From 3c921797bf0e4917f0c5c74b793d3e78b51f3b7e Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Thu, 1 Oct 2026 10:45:31 -0700 Subject: [PATCH 01/54] fix(serialization): statically register native RPC responses --- .../docs/implementation/serialization.md | 12 + .../AnalyzerReleases.Unshipped.md | 1 + .../Diagnostics/DiagnosticRuleId.cs | 1 + .../OrleansSourceGenerator.cs | 11 + src/Orleans.CodeGenerator/Resources.resx | 6 + .../RpcResponseGenerator.cs | 154 ++++++++++ .../SerializerFactoryGenerator.cs | 56 +++- .../SourceGeneratorOptionsParser.cs | 14 + .../Microsoft.Orleans.CodeGenerator.props | 2 + .../Configuration/TypeManifestOptions.cs | 58 +++- .../Invocation/Response.cs | 71 ++++- .../OrleansSourceGeneratorTests.cs | 114 ++++++++ ...eGeneratorTests.TestBasicGrain.verified.cs | 25 +- ...ateMethodSerializersAnnotation.verified.cs | 26 +- ...torTests.TestGrainComplexGrain.verified.cs | 33 ++- ...AnnotatedWithInvokableBaseType.verified.cs | 25 +- ...odAnnotatedWithResponseTimeout.verified.cs | 25 +- ...TestGrainWithDifferentKeyTypes.verified.cs | 33 ++- ...estGrainWithMultipleInterfaces.verified.cs | 25 +- .../Orleans.NativeAotSmoke.csproj | 2 + .../RpcResponses.Contracts.cs | 170 +++++++++++ test/Orleans.NativeAotSmoke/RpcResponses.cs | 9 + .../RpcResponses.smoke.json | 5 + .../RpcResponsesModels.cs | 33 +++ .../Orleans.Serialization.UnitTests.csproj | 2 + .../RpcResponseTests.cs | 275 ++++++++++++++++++ 26 files changed, 1151 insertions(+), 37 deletions(-) create mode 100644 src/Orleans.CodeGenerator/RpcResponseGenerator.cs create mode 100644 test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs create mode 100644 test/Orleans.NativeAotSmoke/RpcResponses.cs create mode 100644 test/Orleans.NativeAotSmoke/RpcResponses.smoke.json create mode 100644 test/Orleans.NativeAotSmoke/RpcResponsesModels.cs create mode 100644 test/Orleans.Serialization.UnitTests/RpcResponseTests.cs diff --git a/docs/site/src/content/docs/implementation/serialization.md b/docs/site/src/content/docs/implementation/serialization.md index 2142d9e8acf..166fa9d61ad 100644 --- a/docs/site/src/content/docs/implementation/serialization.md +++ b/docs/site/src/content/docs/implementation/serialization.md @@ -131,6 +131,18 @@ For a return type marked through ` and `ValueTask` method results, generated metadata supplies a closed response codec and copier graph for NativeAOT execution. The graph uses the concrete result implementations in and . Recursive result dependencies resolve with a construction caller after the response implementation has been allocated. Reference payload codecs and copiers preserve payload cycles and shared references, and the pooled response envelope retains the existing field and raw-message encoding. + +These supplemental registrations are defaults: explicit closed factory registrations take precedence in either configuration order. The automatic provider activates when runtime code generation is unavailable. JIT execution continues to use the existing serializer and copier selection, including application-provided payload implementations. Explicit factory and context registration also works in JIT execution. + +`OrleansValidateRpcResponseFactories` enables compile-time validation of the response graph and defaults to the executable project's `PublishAot` setting. Diagnostic `ORLEANS0116` identifies an unresolved generic result, a custom return adapter requiring an explicit response contract, or a result dependency outside the supported finite graph. Applications with runtime-selected generic results register every permitted closed graph explicitly through and in a , and set `OrleansValidateRpcResponseFactories=false` for the project supplying that contract. A missing native response registration reports the closed response type and registration guidance at lookup. + +The focused native smoke exercises the generated response graph for boolean, integer, and reference results, including recursive factory dependencies and payload identity. Full silo startup and RPC execution additionally require the native support for activation, request serialization, grain references, and runtime metadata. + +Source: [RPC response factory generation](https://github.com/dotnet/orleans/blob/main/src/Orleans.CodeGenerator/RpcResponseGenerator.cs), [closed serializer factory graphs](https://github.com/dotnet/orleans/blob/main/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs), and [native response smoke](https://github.com/dotnet/orleans/blob/main/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs). + ### Request identity and dispatch Generated request names are implementation details. Their wire identity is a compound alias containing: diff --git a/src/Orleans.CodeGenerator/AnalyzerReleases.Unshipped.md b/src/Orleans.CodeGenerator/AnalyzerReleases.Unshipped.md index e8fb9b2577e..c469bfc6a36 100644 --- a/src/Orleans.CodeGenerator/AnalyzerReleases.Unshipped.md +++ b/src/Orleans.CodeGenerator/AnalyzerReleases.Unshipped.md @@ -12,3 +12,4 @@ ORLEANS0112 | Usage | Error | Invalid RPC parameter field identifier ORLEANS0113 | Usage | Warning | CancellationToken parameter is not last ORLEANS0114 | Usage | Error | Invalid serializer context declaration ORLEANS0115 | Usage | Error | Unsupported serializer context dependency +ORLEANS0116 | Usage | Error | RPC response requires a closed serializer factory diff --git a/src/Orleans.CodeGenerator/Diagnostics/DiagnosticRuleId.cs b/src/Orleans.CodeGenerator/Diagnostics/DiagnosticRuleId.cs index 3f191ac79a8..44048aea69a 100644 --- a/src/Orleans.CodeGenerator/Diagnostics/DiagnosticRuleId.cs +++ b/src/Orleans.CodeGenerator/Diagnostics/DiagnosticRuleId.cs @@ -18,4 +18,5 @@ internal static class DiagnosticRuleId public const string CancellationTokenNotLast = "ORLEANS0113"; public const string InvalidSerializerContext = "ORLEANS0114"; public const string UnsupportedSerializerContextType = "ORLEANS0115"; + public const string UnsupportedRpcResponseFactory = "ORLEANS0116"; } diff --git a/src/Orleans.CodeGenerator/OrleansSourceGenerator.cs b/src/Orleans.CodeGenerator/OrleansSourceGenerator.cs index 5f34fd53a27..82394edf7fb 100644 --- a/src/Orleans.CodeGenerator/OrleansSourceGenerator.cs +++ b/src/Orleans.CodeGenerator/OrleansSourceGenerator.cs @@ -221,6 +221,17 @@ public void Initialize(IncrementalGeneratorInitializationContext context) GeneratedSourceOutput.EmitSourceOutputResult(productionContext, input); }); + var responseOutputs = preparedProxyOutputModels + .Combine(compilationProvider) + .Combine(generatorOptions) + .SelectMany(static (input, ct) => RpcResponseGenerator.Generate( + input.Left.Right, input.Left.Left, input.Right, ct)); + + context.RegisterSourceOutput(responseOutputs, static (productionContext, input) => + { + GeneratedSourceOutput.EmitSourceOutputResult(productionContext, input); + }); + context.RegisterSourceOutput(assemblyNameProvider, static (productionContext, assemblyName) => { productionContext.AddSource($"{assemblyName}.orleans.g.cs", SourceText.From(string.Empty, Encoding.UTF8)); diff --git a/src/Orleans.CodeGenerator/Resources.resx b/src/Orleans.CodeGenerator/Resources.resx index fbe58a7cb5d..7e9f55238ac 100644 --- a/src/Orleans.CodeGenerator/Resources.resx +++ b/src/Orleans.CodeGenerator/Resources.resx @@ -144,4 +144,10 @@ Invalid invokable base type mapping + + RPC response requires a closed serializer factory + + + RPC method '{0}' requires response result '{1}': {2}; register the closed Response<TResult> types in a serializer context for this contract + \ No newline at end of file diff --git a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs new file mode 100644 index 00000000000..bf1dddbafa5 --- /dev/null +++ b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs @@ -0,0 +1,154 @@ +using System.Collections.Immutable; +using System.Text; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using Orleans.CodeGenerator.Diagnostics; +using Orleans.CodeGenerator.Model; +using Orleans.CodeGenerator.SyntaxGeneration; + +namespace Orleans.CodeGenerator; + +internal static class RpcResponseGenerator +{ + private static readonly DiagnosticDescriptor UnsupportedResponse = new( + DiagnosticRuleId.UnsupportedRpcResponseFactory, + new LocalizableResourceString("UnsupportedRpcResponseFactoryTitle", Resources.ResourceManager, typeof(Resources)), + new LocalizableResourceString("UnsupportedRpcResponseFactoryMessageFormat", Resources.ResourceManager, typeof(Resources)), + "Usage", + DiagnosticSeverity.Error, + isEnabledByDefault: true); + + internal static ImmutableArray Generate( + Compilation compilation, + ImmutableArray proxies, + SourceGeneratorOptions options, + CancellationToken cancellationToken) + { + if (proxies.IsDefaultOrEmpty) + { + return []; + } + + var services = new GeneratorServices(compilation, SourceGeneratorOptionsParser.CreateCodeGeneratorOptions(options)); + var responseDefinition = compilation.GetTypeByMetadataName("Orleans.Serialization.Invocation.Response`1")!; + var resolver = new TypeSymbolResolver(compilation); + var results = new Dictionary(SymbolEqualityComparer.Default); + var output = ImmutableArray.CreateBuilder(); + foreach (var proxy in proxies) + { + cancellationToken.ThrowIfCancellationRequested(); + if (!resolver.TryResolveProxyInterface(proxy.ProxyInterface, cancellationToken, out var interfaceType)) + { + continue; + } + + foreach (var method in interfaceType.GetMembers().OfType() + .Concat(interfaceType.AllInterfaces.SelectMany(static type => type.GetMembers().OfType())) + .Where(static method => method.MethodKind == MethodKind.Ordinary)) + { + var returnType = method.ReturnType; + if (returnType.SpecialType == SpecialType.System_Void + || SymbolEqualityComparer.Default.Equals(returnType, services.LibraryTypes.Task) + || SymbolEqualityComparer.Default.Equals(returnType, services.LibraryTypes.ValueTask)) + { + continue; + } + + if (returnType is not INamedTypeSymbol named + || !(SymbolEqualityComparer.Default.Equals(named.OriginalDefinition, services.LibraryTypes.Task_1) + || SymbolEqualityComparer.Default.Equals(named.OriginalDefinition, services.LibraryTypes.ValueTask_1))) + { + Report(method, returnType, "the selected return adapter requires an explicit response result contract"); + continue; + } + + var resultType = named.TypeArguments[0].WithNullableAnnotation(NullableAnnotation.None); + if (ContainsTypeParameter(resultType)) + { + Report(method, resultType, "the result contains an unresolved type parameter"); + continue; + } + + if (!results.ContainsKey(resultType)) + { + results.Add(resultType, method); + } + } + } + + var supportedResults = new List(); + foreach (var entry in results.OrderBy(static entry => entry.Key.ToDisplayString(), StringComparer.Ordinal)) + { + var resultType = entry.Key; + var method = entry.Value; + if (SerializerFactoryGenerator.TryCreate(services, [responseDefinition.Construct(resultType)], cancellationToken, out _, out var failure)) + { + supportedResults.Add(resultType); + } + else + { + Report(method, failure.Type, failure.Reason); + } + } + + if (supportedResults.Count == 0) + { + return output.ToImmutable(); + } + + if (!SerializerFactoryGenerator.TryCreate(services, supportedResults.Select(type => responseDefinition.Construct(type)), cancellationToken, out var graph, out var graphFailure, useDefaultFactories: true)) + { + if (options.ValidateRpcResponseFactories) + { + output.Add(SourceOutputResult.FromDiagnostic(Diagnostic.Create( + UnsupportedResponse, Location.None, compilation.AssemblyName, graphFailure.Type.ToDisplayString(), graphFailure.Reason))); + } + + return output.ToImmutable(); + } + + var generatedNamespace = $"{GeneratedCodeUtilities.CodeGeneratorName}.{Identifier.SanitizeIdentifierName(compilation.AssemblyName ?? "Assembly").EscapeIdentifier()}"; + var source = new StringBuilder(); + source.AppendLine("// "); + source.AppendLine("#nullable disable"); + source.AppendLine($"[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof({generatedNamespace}.RpcResponseFactories))]"); + source.AppendLine($"namespace {generatedNamespace}"); + source.AppendLine("{"); + source.AppendLine("internal sealed class RpcResponseFactories : global::Orleans.Serialization.SerializerContext"); + source.AppendLine("{"); + source.AppendLine("protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options)"); + source.AppendLine("{"); + source.AppendLine("#if NET5_0_OR_GREATER"); + source.AppendLine("if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) return;"); + source.AppendLine(graph.ConfigurationStatements); + + source.AppendLine("#endif"); + source.AppendLine("}"); + source.AppendLine("}"); + source.AppendLine("}"); + var unit = CSharpSyntaxTree.ParseText(source.ToString(), + options: new CSharpParseOptions(preprocessorSymbols: ["NET5_0_OR_GREATER"]), + cancellationToken: cancellationToken).GetCompilationUnitRoot(cancellationToken); + var provider = unit.DescendantNodes().OfType().Single(); + unit = unit.ReplaceNode(provider, provider.AddAttributeLists(GeneratedCodeUtilities.GetGeneratedCodeAttributes())); + output.Add(SourceOutputResult.FromSource(new GeneratedSourceEntry( + $"{compilation.AssemblyName}.orleans.rpcresponses.g.cs", unit.NormalizeWhitespace().ToFullString()))); + return output.ToImmutable(); + + void Report(IMethodSymbol method, ITypeSymbol resultType, string reason) + { + if (options.ValidateRpcResponseFactories) + { + output.Add(SourceOutputResult.FromDiagnostic(Diagnostic.Create( + UnsupportedResponse, method.Locations.FirstOrDefault(), method.ToDisplayString(), resultType.ToDisplayString(), reason))); + } + } + } + + private static bool ContainsTypeParameter(ITypeSymbol type) + => type is ITypeParameterSymbol + || type is IArrayTypeSymbol array && ContainsTypeParameter(array.ElementType) + || type is INamedTypeSymbol named && (named.TypeArguments.Any(ContainsTypeParameter) + || named.ContainingType is { } containing && ContainsTypeParameter(containing)); +} diff --git a/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs b/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs index 2325e2b7a11..8d73c1d4310 100644 --- a/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs +++ b/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs @@ -18,6 +18,7 @@ internal sealed class Registration(ITypeSymbol type) public string CopierConstruction { get; set; } = ""; public List Dependencies { get; } = []; public ISerializableTypeDescription? Model { get; set; } + public ITypeSymbol? ResponseResult { get; set; } public INamedTypeSymbol? ReferencedCodec { get; set; } public INamedTypeSymbol? ReferencedCopier { get; set; } public List CanonicalArrays { get; } = []; @@ -36,7 +37,8 @@ internal static bool TryCreate( IEnumerable roots, CancellationToken cancellationToken, [NotNullWhen(true)] out Graph? graph, - [NotNullWhen(false)] out Failure? failure) + [NotNullWhen(false)] out Failure? failure, + bool useDefaultFactories = false) { graph = null; failure = null; @@ -68,6 +70,9 @@ internal static bool TryCreate( var serializerGenerator = new SerializerGenerator(services); var copierGenerator = new CopierGenerator(services); var result = new StringBuilder(); + foreach (var registration in registrations.Values) ResolveResponseImplementations(registration); + var addService = useDefaultFactories ? "AddDefaultSerializerService" : "AddSerializerService"; + var addSerializer = useDefaultFactories ? "AddDefaultSerializer" : "AddSerializer"; var metadataTypes = new HashSet(SymbolEqualityComparer.Default); var auxiliaryServices = new HashSet(StringComparer.Ordinal); @@ -112,37 +117,41 @@ internal static bool TryCreate( { var target = registrations[dependency.WithNullableAnnotation(NullableAnnotation.None)]; var cyclic = Reaches(target, registration.Type, registrations, new(SymbolEqualityComparer.Default)); - codecArguments.Add(cyclic + codecArguments.Add(cyclic && registration.ResponseResult is not null + ? $"caller => {Resolve(target.Codec, "caller")}" + : cyclic ? $"CreateCodecHolder<{Name(dependency)}>(provider)" - : $"provider.GetCodec<{Name(dependency)}>()"); - copierArguments.Add(cyclic + : useDefaultFactories || registration.ResponseResult is not null ? Resolve(target.Codec) : $"provider.GetCodec<{Name(dependency)}>()"); + copierArguments.Add(cyclic && registration.ResponseResult is not null + ? $"caller => {Resolve(target.Copier, "caller")}" + : cyclic ? $"CreateCopierHolder<{Name(dependency)}>(provider)" - : $"provider.GetDeepCopier<{Name(dependency)}>()"); + : useDefaultFactories || registration.ResponseResult is not null ? Resolve(target.Copier) : $"provider.GetDeepCopier<{Name(dependency)}>()"); } registration.CodecConstruction = $"new {registration.Codec}({string.Join(", ", codecArguments)})"; registration.CopierConstruction = $"new {registration.Copier}({string.Join(", ", copierArguments)})"; } - result.Append("options.AddSerializerService<").Append(registration.Codec).Append(">(static provider => ") + result.Append("options.").Append(addService).Append('<').Append(registration.Codec).Append(">(static provider => ") .Append(registration.CodecConstruction).AppendLine(");"); - result.Append("options.AddSerializerService<").Append(registration.Copier).Append(">(static provider => ") + result.Append("options.").Append(addService).Append('<').Append(registration.Copier).Append(">(static provider => ") .Append(registration.CopierConstruction).AppendLine(");"); - result.Append("options.AddSerializer<").Append(typeName).Append(">(static provider => ") + result.Append("options.").Append(addSerializer).Append('<').Append(typeName).Append(">(static provider => ") .Append(Resolve(registration.Codec)).Append(", static provider => ").Append(Resolve(registration.Copier)).AppendLine(");"); if (registration.Model is { IsValueType: true, IsEnumType: false }) { - result.Append("options.AddSerializerService>(static provider => ").Append(Resolve(registration.Codec)).AppendLine(");"); } if (hasBaseCodec) { - result.Append("options.AddSerializerService>(static provider => ").Append(Resolve(registration.Codec)).AppendLine(");"); } if (hasBaseCopier) { - result.Append("options.AddSerializerService>(static provider => ").Append(Resolve(registration.Copier)).AppendLine(");"); } @@ -156,19 +165,19 @@ internal static bool TryCreate( if (arrayRegistration.Codec != canonicalCodec && auxiliaryServices.Add(canonicalCodec)) { var codecDependency = cyclic ? $"CreateCodecHolder<{Name(array.ElementType)}>(provider)" : $"provider.GetCodec<{Name(array.ElementType)}>()"; - result.Append("options.AddSerializerService<").Append(canonicalCodec).Append(">(static provider => new ") + result.Append("options.").Append(addService).Append('<').Append(canonicalCodec).Append(">(static provider => new ") .Append(canonicalCodec).Append('(').Append(codecDependency).AppendLine("));"); } if (arrayRegistration.Copier != canonicalCopier && auxiliaryServices.Add(canonicalCopier)) { var copierDependency = cyclic ? $"CreateCopierHolder<{Name(array.ElementType)}>(provider)" : $"provider.GetDeepCopier<{Name(array.ElementType)}>()"; - result.Append("options.AddSerializerService<").Append(canonicalCopier).Append(">(static provider => new ") + result.Append("options.").Append(addService).Append('<').Append(canonicalCopier).Append(">(static provider => new ") .Append(canonicalCopier).Append('(').Append(copierDependency).AppendLine("));"); } } result.Append("options.AddAllowedType(typeof(").Append(typeName).AppendLine("));"); - if (AppendTypeMetadata(result, registration.Type, services.LibraryTypes, metadataTypes) is { } metadataFailure) + if (!useDefaultFactories && AppendTypeMetadata(result, registration.Type, services.LibraryTypes, metadataTypes) is { } metadataFailure) { failure = metadataFailure; return false; @@ -177,6 +186,15 @@ internal static bool TryCreate( graph = new Graph(registrations, result.ToString()); return true; + + void ResolveResponseImplementations(Registration registration) + { + if (registration.ResponseResult is not { } resultType || registration.Codec.Length > 0) return; + var target = registrations[resultType.WithNullableAnnotation(NullableAnnotation.None)]; + ResolveResponseImplementations(target); + registration.Codec = $"global::Orleans.Serialization.Invocation.PooledResponseCodec<{Name(resultType)}, {target.Codec}>"; + registration.Copier = $"global::Orleans.Serialization.Invocation.PooledResponseCopier<{Name(resultType)}, {target.Copier}>"; + } } private static string? Describe(Registration registration, IGeneratorServices services, Compilation implementationCompilation, CancellationToken cancellationToken) @@ -215,6 +233,12 @@ internal static bool TryCreate( if (named.ContainingType is { IsGenericType: true }) return "use a model declared outside a generic containing type"; var definition = named.OriginalDefinition.ToDisplayString(); + if (definition == "Orleans.Serialization.Invocation.Response") + { + registration.ResponseResult = named.TypeArguments[0]; + registration.Dependencies.Add(named.TypeArguments[0]); + return null; + } var collection = definition switch { "System.Collections.Generic.List" => "List", @@ -524,8 +548,8 @@ private static bool ContainsTypeParameter(ITypeSymbol type) || type is INamedTypeSymbol named && named.TypeArguments.Any(ContainsTypeParameter) || type is IArrayTypeSymbol array && ContainsTypeParameter(array.ElementType); - private static string Resolve(string type) - => $"global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService<{type}>(null!, provider)"; + private static string Resolve(string type, string caller = "null!") + => $"global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService<{type}>({caller}, provider)"; private static string Name(ITypeSymbol type) => type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); diff --git a/src/Orleans.CodeGenerator/SourceGeneratorOptionsParser.cs b/src/Orleans.CodeGenerator/SourceGeneratorOptionsParser.cs index 908a5437fb0..039ae33e985 100644 --- a/src/Orleans.CodeGenerator/SourceGeneratorOptionsParser.cs +++ b/src/Orleans.CodeGenerator/SourceGeneratorOptionsParser.cs @@ -78,6 +78,17 @@ internal static SourceGeneratorOptions ParseOptions(AnalyzerConfigOptions global } } + if (globalOptions.TryGetValue("build_property.orleansvalidaterpcresponsefactories", out var validateResponses) + && bool.TryParse(validateResponses, out var validateResponseFactories)) + { + result.ValidateRpcResponseFactories = validateResponseFactories; + } + else if (globalOptions.TryGetValue("build_property.publishaot", out var publishAot) + && bool.TryParse(publishAot, out var isAot)) + { + result.ValidateRpcResponseFactories = isAot; + } + return result; } @@ -88,6 +99,7 @@ internal struct SourceGeneratorOptions : IEquatable public GenerateFieldIds GenerateFieldIds { get; set; } public bool GenerateCompatibilityInvokers { get; set; } public bool AttachDebugger { get; set; } + public bool ValidateRpcResponseFactories { get; set; } /// /// Enables hot-reload-safe code generation. @@ -101,6 +113,7 @@ public readonly bool Equals(SourceGeneratorOptions other) => GenerateFieldIds == other.GenerateFieldIds && GenerateCompatibilityInvokers == other.GenerateCompatibilityInvokers && AttachDebugger == other.AttachDebugger + && ValidateRpcResponseFactories == other.ValidateRpcResponseFactories && HotReload == other.HotReload && SupportsUnsafeAccessors == other.SupportsUnsafeAccessors && SupportsGenericUnsafeAccessors == other.SupportsGenericUnsafeAccessors @@ -115,6 +128,7 @@ public override readonly int GetHashCode() var hash = (int)GenerateFieldIds; hash = hash * 31 + (GenerateCompatibilityInvokers ? 1 : 0); hash = hash * 31 + (AttachDebugger ? 1 : 0); + hash = hash * 31 + (ValidateRpcResponseFactories ? 1 : 0); hash = hash * 31 + (HotReload switch { true => 1, false => 2, null => 0 }); hash = hash * 31 + (SupportsUnsafeAccessors ? 1 : 0); hash = hash * 31 + (SupportsGenericUnsafeAccessors ? 1 : 0); diff --git a/src/Orleans.CodeGenerator/build/Microsoft.Orleans.CodeGenerator.props b/src/Orleans.CodeGenerator/build/Microsoft.Orleans.CodeGenerator.props index 1761a0dd25d..04a9a345212 100644 --- a/src/Orleans.CodeGenerator/build/Microsoft.Orleans.CodeGenerator.props +++ b/src/Orleans.CodeGenerator/build/Microsoft.Orleans.CodeGenerator.props @@ -7,6 +7,8 @@ + + diff --git a/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs b/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs index e575040170d..f57bfab0c07 100644 --- a/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs +++ b/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs @@ -47,6 +47,7 @@ public sealed class TypeManifestOptions internal Dictionary> CodecFactories { get; } = new(); internal Dictionary> CopierFactories { get; } = new(); internal Dictionary> SerializerServiceFactories { get; } = new(); + private readonly HashSet _defaultSerializerServices = new(); internal HashSet ContextTypes { get; } = new(); /// @@ -55,9 +56,31 @@ public sealed class TypeManifestOptions /// The serialized type. /// The factory for the field codec. /// The factory for the deep copier. + /// Explicit registrations replace defaults. The first explicit registration for each service is used. public void AddSerializer( Func> codecFactory, Func> copierFactory) + => RegisterSerializerFactories(codecFactory, copierFactory, isDefault: false); + + /// + /// Registers default closed serialization factories which yield to explicit registrations. + /// + /// The serialized type. + /// The default field codec factory. + /// The default deep copier factory. + /// + /// The first default registration is used until an explicit + /// registration supplies the implementation, in either registration order. + /// + public void AddDefaultSerializer( + Func> codecFactory, + Func> copierFactory) + => RegisterSerializerFactories(codecFactory, copierFactory, isDefault: true); + + private void RegisterSerializerFactories( + Func> codecFactory, + Func> copierFactory, + bool isDefault) { if (codecFactory is null) throw new ArgumentNullException(nameof(codecFactory)); if (copierFactory is null) throw new ArgumentNullException(nameof(copierFactory)); @@ -65,8 +88,8 @@ public void AddSerializer( Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null!, provider)); CopierFactories.TryAdd(typeof(T), static provider => Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null!, provider)); - SerializerServiceFactories.TryAdd(typeof(IFieldCodec), codecFactory); - SerializerServiceFactories.TryAdd(typeof(IDeepCopier), copierFactory); + AddSerializerServiceFactory(typeof(IFieldCodec), codecFactory, isDefault); + AddSerializerServiceFactory(typeof(IDeepCopier), copierFactory, isDefault); ContextTypes.Add(typeof(T)); } @@ -78,7 +101,7 @@ public void AddSerializer( /// /// The codec provider constructs and caches one instance per service type. Recursive generated /// constructors retain references to in-progress dependencies through the generated-code helper. - /// The first registration for a service type is used. + /// Explicit registrations replace defaults. The first explicit registration for a service type is used. /// During graph construction, dependencies resolve through provider-owned services and these closed /// factories. Supply external dependencies through explicit constructor arguments or factories which /// return captured instances. Ordinary dependency injection resumes after the graph is published. @@ -86,7 +109,34 @@ public void AddSerializer( public void AddSerializerService(Func factory) where TService : class { if (factory is null) throw new ArgumentNullException(nameof(factory)); - SerializerServiceFactories.TryAdd(typeof(TService), factory); + AddSerializerServiceFactory(typeof(TService), factory, isDefault: false); + } + + /// + /// Registers a default closed service factory which yields to an explicit service registration. + /// + /// The closed service type. + /// The default service factory. + /// + /// The first default registration is used until + /// supplies an explicit factory, in either registration order. + /// + public void AddDefaultSerializerService(Func factory) where TService : class + { + if (factory is null) throw new ArgumentNullException(nameof(factory)); + AddSerializerServiceFactory(typeof(TService), factory, isDefault: true); + } + + private void AddSerializerServiceFactory(Type type, Func factory, bool isDefault) + { + if (!isDefault && _defaultSerializerServices.Remove(type)) + { + SerializerServiceFactories[type] = factory; + } + else if (SerializerServiceFactories.TryAdd(type, factory) && isDefault) + { + _defaultSerializerServices.Add(type); + } } /// diff --git a/src/Orleans.Serialization/Invocation/Response.cs b/src/Orleans.Serialization/Invocation/Response.cs index b9fabfcefa7..e7b9cd6f721 100644 --- a/src/Orleans.Serialization/Invocation/Response.cs +++ b/src/Orleans.Serialization/Invocation/Response.cs @@ -230,15 +230,41 @@ public abstract class ResponseCodec } [RegisterSerializer] - internal sealed class PooledResponseCodec : ResponseCodec, IFieldCodec> + internal sealed class PooledResponseCodec : PooledResponseCodec> + { + public PooledResponseCodec(ICodecProvider codecProvider) + : base(caller => OrleansGeneratedCodeHelper.GetService>(caller, codecProvider)) + { + } + } + + /// + /// Serializes pooled invocation responses using a statically specified result codec. + /// + /// The invocation result type. + /// The concrete codec for invocation results. + public class PooledResponseCodec : ResponseCodec, IFieldCodec> + where TResultCodec : class, IFieldCodec { private readonly Type _codecFieldType = typeof(Response); private readonly Type _resultType = typeof(TResult); - private readonly IFieldCodec _codec; + private readonly TResultCodec _codec; - public PooledResponseCodec(ICodecProvider codecProvider) - => _codec = OrleansGeneratedCodeHelper.GetService>(this, codecProvider); + /// + /// Initializes a response codec with its result codec. + /// + /// The codec for invocation results. + public PooledResponseCodec(TResultCodec codec) + => _codec = codec ?? throw new ArgumentNullException(nameof(codec)); + + /// + /// Initializes a response codec using a caller-aware factory for a recursive result codec graph. + /// + /// The concrete result codec factory, receiving this response codec as its construction caller. + public PooledResponseCodec(Func codecFactory) + => _codec = (codecFactory ?? throw new ArgumentNullException(nameof(codecFactory)))(this); + /// public void WriteField(ref Writer writer, uint fieldIdDelta, [System.Diagnostics.CodeAnalysis.AllowNull] Type expectedType, [System.Diagnostics.CodeAnalysis.AllowNull] Response value) where TBufferWriter : IBufferWriter { if (value is null) @@ -254,6 +280,7 @@ public void WriteField(ref Writer writer, uint fie writer.WriteEndObject(); } + /// [return: System.Diagnostics.CodeAnalysis.MaybeNull] public Response ReadValue(ref Reader reader, Field field) { @@ -273,6 +300,7 @@ public Response ReadValue(ref Reader reader, Field fiel return result; } + /// public override void WriteRaw(ref Writer writer, object value) { writer.WriteStartObject(0, null!, _resultType); @@ -282,6 +310,7 @@ public override void WriteRaw(ref Writer writer, o writer.WriteEndObject(); } + /// public override object ReadRaw(ref Reader reader, scoped ref Field field) { field.EnsureWireTypeTagDelimited(); @@ -298,13 +327,39 @@ public override object ReadRaw(ref Reader reader, scoped ref Fie } [RegisterCopier] - internal sealed class PooledResponseCopier : IDeepCopier> + internal sealed class PooledResponseCopier : PooledResponseCopier> { - private readonly IDeepCopier _copier; - public PooledResponseCopier(ICodecProvider codecProvider) - => _copier = OrleansGeneratedCodeHelper.GetService>(this, codecProvider); + : base(caller => OrleansGeneratedCodeHelper.GetService>(caller, codecProvider)) + { + } + } + + /// + /// Copies pooled invocation responses using a statically specified result copier. + /// + /// The invocation result type. + /// The concrete copier for invocation results. + public class PooledResponseCopier : IDeepCopier> + where TResultCopier : class, IDeepCopier + { + private readonly TResultCopier _copier; + + /// + /// Initializes a response copier with its result copier. + /// + /// The copier for invocation results. + public PooledResponseCopier(TResultCopier copier) + => _copier = copier ?? throw new ArgumentNullException(nameof(copier)); + /// + /// Initializes a response copier using a caller-aware factory for a recursive result copier graph. + /// + /// The concrete result copier factory, receiving this response copier as its construction caller. + public PooledResponseCopier(Func copierFactory) + => _copier = (copierFactory ?? throw new ArgumentNullException(nameof(copierFactory)))(this); + + /// [return: System.Diagnostics.CodeAnalysis.NotNullIfNotNull(nameof(input))] public Response? DeepCopy(Response? input, CopyContext context) { diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index 2825aa60a1c..d22d0176d72 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -2241,6 +2241,120 @@ public sealed record PrimaryCtorRecord( Assert.Equal(1, CountOccurrences(serializerText, "if (id == 2U)")); } + [Fact] + public async Task RpcResponseFactoriesGenerateConcreteClosedGraph() + { + var compilation = await CreateCompilation(""" + using Orleans; + using System.Threading.Tasks; + namespace TestProject; + public interface IResponses : IGrainWithIntegerKey + { + Task Boolean(); + ValueTask Integer(); + Task Reference(); + Task Repeated(); + } + [GenerateSerializer, Alias("rpc.payload")] + public sealed class Payload + { + [Id(0)] public int Value { get; set; } + [Id(1)] public Payload Next { get; set; } + [Id(2)] public Orleans.Serialization.Invocation.Response Envelope { get; set; } + } + """); + var result = RunSourceGenerator(compilation, new Dictionary { ["build_property.publishaot"] = "true" }); + Assert.Empty(result.Diagnostics); + var source = Assert.Single(result.GeneratedSources, static source => source.HintName.EndsWith(".orleans.rpcresponses.g.cs", StringComparison.Ordinal)).SourceText.ToString(); + Assert.Contains("new global::Orleans.Serialization.Invocation.PooledResponseCodec", source); + Assert.Contains("new global::Orleans.Serialization.Invocation.PooledResponseCopier>", source); + Assert.Contains("PooledResponseCodec", source); + Assert.Contains("new global::OrleansCodeGen.TestProject.Codec_Payload(provider)", source); + Assert.Contains("caller => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(caller, provider)", source); + Assert.Contains("caller => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(caller, provider)", source); + Assert.Equal(1, CountOccurrences(source, "options.AddDefaultSerializer>")); + Assert.Contains("RuntimeFeature.IsDynamicCodeSupported", source); + Assert.DoesNotContain("GetService).Assembly.Location)) + .AddSyntaxTrees(result.GeneratedSources.Select(static source => CSharpSyntaxTree.ParseText(source.SourceText, + options: new CSharpParseOptions().WithPreprocessorSymbols("NET5_0_OR_GREATER"), path: source.HintName))); + Assert.Empty(outputCompilation.GetDiagnostics(TestContext.Current.CancellationToken).Where(static diagnostic => diagnostic.Severity == DiagnosticSeverity.Error)); + } + + [Theory] + [InlineData("Task Get();")] + [InlineData("Task> Get();")] + [InlineData("Task Get();")] + public async Task RpcResponseFactoriesDiagnoseUnresolvedNativeResults(string method) + { + var compilation = await CreateCompilation($$""" + using Orleans; + using System.Threading.Tasks; + namespace TestProject; + public interface IResponses : IGrainWithIntegerKey { {{method}} } + """); + var result = RunSourceGenerator(compilation, new Dictionary { ["build_property.publishaot"] = "true" }); + var diagnostic = Assert.Single(result.Diagnostics); + Assert.Equal("ORLEANS0116", diagnostic.Id); + Assert.Equal(DiagnosticSeverity.Error, diagnostic.Severity); + Assert.Contains("serializer context", diagnostic.GetMessage()); + Assert.NotEqual(Location.None, diagnostic.Location); + } + + [Fact] + public async Task RpcResponseFactoriesPreserveGenericJitGenerationAndExplicitValidationOverride() + { + var compilation = await CreateCompilation(""" + using Orleans; + using System.Threading.Tasks; + namespace TestProject; + public interface IResponses : IGrainWithIntegerKey + { + Task Generic(); + Task Concrete(); + } + """); + var jit = RunSourceGenerator(compilation); + var overridden = RunSourceGenerator(compilation, new Dictionary + { + ["build_property.publishaot"] = "true", + ["build_property.orleansvalidaterpcresponsefactories"] = "false", + }); + Assert.Empty(jit.Diagnostics); + Assert.Empty(overridden.Diagnostics); + Assert.Contains("Response", ConcatenateGeneratedSources(jit)); + Assert.DoesNotContain("Response", ConcatenateGeneratedSources(jit)); + Assert.Equal(ConcatenateGeneratedSources(jit), ConcatenateGeneratedSources(overridden)); + } + + [Fact] + public async Task RpcResponseFactoriesResolveInheritedClosedGenericResultsAndCompletionMethods() + { + var compilation = await CreateCompilation(""" + using Orleans; + using System.Threading.Tasks; + namespace TestProject; + public interface IParent : IGrainWithIntegerKey { Task Get(); } + public interface IChild : IParent + { + Task Done(); + ValueTask DoneValueTask(); + void OneWay(); + } + """); + var result = RunSourceGenerator(compilation); + Assert.Empty(result.Diagnostics); + var source = Assert.Single(result.GeneratedSources, static source => source.HintName.EndsWith(".orleans.rpcresponses.g.cs", StringComparison.Ordinal)).SourceText.ToString(); + Assert.Contains("Response", source); + Assert.DoesNotContain("Response", source); + } + private static GeneratorRunResult RunSourceGenerator( CSharpCompilation compilation, IReadOnlyDictionary? globalOptions = null) diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.verified.cs index 2ecfdceb351..31a4dd1596a 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.verified.cs @@ -1,4 +1,7 @@ -#pragma warning disable +// +#nullable disable +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] +#pragma warning disable [assembly: global::Orleans.ApplicationPartAttribute("TestProject")] [assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] [assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] @@ -244,6 +247,26 @@ internal sealed class Activator_BasicGrain : global::Orleans.Serialization.Activ public global::TestProject.BasicGrain Create() => new global::TestProject.BasicGrain(); } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class RpcResponseFactories : global::Orleans.Serialization.SerializerContext + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) + { +#if NET5_0_OR_GREATER + if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) + return; + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(string)); +#endif + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase { diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.verified.cs index e66a9bd5660..82444f74097 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.verified.cs @@ -1,4 +1,7 @@ -#pragma warning disable +// +#nullable disable +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] +#pragma warning disable [assembly: global::Orleans.ApplicationPartAttribute("TestProject")] [assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] [assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] @@ -152,8 +155,25 @@ public OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404 DeepCopy(Orlean namespace OrleansCodeGen.TestProject { - using global::Orleans.Serialization.Codecs; - using global::Orleans.Serialization.GeneratedCodeHelpers; + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class RpcResponseFactories : global::Orleans.Serialization.SerializerContext + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) + { +#if NET5_0_OR_GREATER + if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) + return; + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(string)); +#endif + } + } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.verified.cs index 7059a896a4d..0a4ee576fb5 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.verified.cs @@ -1,4 +1,7 @@ -#pragma warning disable +// +#nullable disable +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] +#pragma warning disable [assembly: global::Orleans.ApplicationPartAttribute("TestProject")] [assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] [assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] @@ -437,6 +440,34 @@ internal sealed class Activator_ComplexGrain : global::Orleans.Serialization.Act public global::TestProject.ComplexGrain Create() => new global::TestProject.ComplexGrain(); } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class RpcResponseFactories : global::Orleans.Serialization.SerializerContext + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) + { +#if NET5_0_OR_GREATER + if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) + return; + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Codec_ComplexData()); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Copier_ComplexData()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); + options.AddAllowedType(typeof(global::TestProject.ComplexData)); + options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.Int32Codec()); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(int)); + options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(string)); +#endif + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase { diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.verified.cs index 9fbdbedad6d..bc446b73dc2 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.verified.cs @@ -1,4 +1,7 @@ -#pragma warning disable +// +#nullable disable +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] +#pragma warning disable [assembly: global::Orleans.ApplicationPartAttribute("TestProject")] [assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] [assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] @@ -249,6 +252,26 @@ internal sealed class Activator_HelloGrain : global::Orleans.Serialization.Activ public global::TestProject.HelloGrain Create() => new global::TestProject.HelloGrain(); } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class RpcResponseFactories : global::Orleans.Serialization.SerializerContext + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) + { +#if NET5_0_OR_GREATER + if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) + return; + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(string)); +#endif + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase { diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.verified.cs index f1ab9fe7972..6dd28d9e70e 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.verified.cs @@ -1,4 +1,7 @@ -#pragma warning disable +// +#nullable disable +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] +#pragma warning disable [assembly: global::Orleans.ApplicationPartAttribute("TestProject")] [assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] [assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] @@ -151,6 +154,26 @@ public OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference } } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class RpcResponseFactories : global::Orleans.Serialization.SerializerContext + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) + { +#if NET5_0_OR_GREATER + if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) + return; + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(string)); +#endif + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase { diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.verified.cs index 45badca42ce..3884f72c9fb 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.verified.cs @@ -1,4 +1,7 @@ -#pragma warning disable +// +#nullable disable +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] +#pragma warning disable [assembly: global::Orleans.ApplicationPartAttribute("TestProject")] [assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] [assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] @@ -762,6 +765,34 @@ internal sealed class Activator_GrainWithIntegerCompoundKey : global::Orleans.Se public global::TestProject.GrainWithIntegerCompoundKey Create() => new global::TestProject.GrainWithIntegerCompoundKey(); } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class RpcResponseFactories : global::Orleans.Serialization.SerializerContext + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) + { +#if NET5_0_OR_GREATER + if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) + return; + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.GuidCodec()); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::System.Guid)); + options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(string)); +#endif + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase { diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.verified.cs index ec26e138f3b..00fb1ee63e1 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.verified.cs @@ -1,4 +1,7 @@ -#pragma warning disable +// +#nullable disable +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] +#pragma warning disable [assembly: global::Orleans.ApplicationPartAttribute("TestProject")] [assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] [assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] @@ -288,6 +291,26 @@ public OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809 Deep } } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class RpcResponseFactories : global::Orleans.Serialization.SerializerContext + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) + { +#if NET5_0_OR_GREATER + if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) + return; + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(string)); +#endif + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase { diff --git a/test/Orleans.NativeAotSmoke/Orleans.NativeAotSmoke.csproj b/test/Orleans.NativeAotSmoke/Orleans.NativeAotSmoke.csproj index bf00e725a81..b3201cffe01 100644 --- a/test/Orleans.NativeAotSmoke/Orleans.NativeAotSmoke.csproj +++ b/test/Orleans.NativeAotSmoke/Orleans.NativeAotSmoke.csproj @@ -24,6 +24,8 @@ Condition="'$(NativeAotSmokeScenario)' == 'DependencyInjection' or '$(NativeAotSmokeScenario)' == 'GrainReferences' or '$(NativeAotSmokeScenario)' == 'Silo' or '$(NativeAotSmokeScenario)' == 'GrainActivation'" /> + diff --git a/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs b/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs new file mode 100644 index 00000000000..e966e6a25e8 --- /dev/null +++ b/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs @@ -0,0 +1,170 @@ +#nullable enable +using System; +using System.Buffers; +using Microsoft.Extensions.DependencyInjection; +using Orleans.Serialization; +using Orleans.Serialization.Buffers; +using Orleans.Serialization.Cloning; +using Orleans.Serialization.Codecs; +using Orleans.Serialization.Invocation; +using Orleans.Serialization.Serializers; +using Orleans.Serialization.Session; + +namespace Orleans.NativeAotSmoke; + +public static class RpcResponseContracts +{ + public static void PrimitiveResponses() + { + using var services = CreateServices(); + Check(false); + Check(true); + Check(0); + Check(42); + Check(-17); + + void Check(T value) + { + using var response = Response.FromResult(value); + using var copy = Copy(services, response); + Ensure(!ReferenceEquals(response, copy), "Response copies have distinct pooled envelopes."); + Ensure(Equals(value, copy.GetResult()), "The response copier preserves primitive results."); + using var roundTrip = RoundTrip(services, response); + Ensure(Equals(value, roundTrip.GetResult()), "The response codec preserves primitive results."); + Ensure(services.GetRequiredService().GetCodec(response.GetType()) is ResponseCodec, + "Response dispatch retains the concrete raw response codec."); + } + } + + public static void ReferenceResponsePreservesCycles() + { + using var services = CreateServices(); + var payload = new RpcResponsePayload { Value = 42 }; + var shared = new RpcResponsePayload { Value = 17, Left = payload }; + payload.Left = shared; + payload.Right = shared; + using var response = Response.FromResult(payload); + using var copy = Copy(services, response); + Verify(copy.GetResult()); + using var roundTrip = RoundTrip(services, response); + Verify(roundTrip.GetResult()); + + void Verify(RpcResponsePayload? result) + { + Ensure(result is not null, "Reference response payloads retain their root."); + Ensure(!ReferenceEquals(payload, result), "Mutable response payloads are isolated."); + Ensure(result.Value == 42 && result.Left.Value == 17, "Payload fields retain their values."); + Ensure(ReferenceEquals(result.Left, result.Right), "Repeated payload references retain identity."); + Ensure(ReferenceEquals(result, result.Left.Left), "Payload cycles point to the copied root."); + } + } + + public static void NullResponsePayload() + { + using var services = CreateServices(); + using var response = Response.FromResult(null!); + using var copy = Copy(services, response); + using var roundTrip = RoundTrip(services, response); + Ensure(copy.GetResult() is null && roundTrip.GetResult() is null, + "Empty reference response payloads retain null."); + } + + public static void RawResponses() + { + using var services = CreateServices(); + Check(true); + Check(42); + Check(null!); + + void Check(T value) + { + using var response = Response.FromResult(value); + var codec = (ResponseCodec)services.GetRequiredService().GetCodec(response.GetType()); + var buffer = new ArrayBufferWriter(); + var sessions = services.GetRequiredService(); + using (var session = sessions.GetSession()) + { + var writer = Writer.Create(buffer, session); + codec.WriteRaw(ref writer, response); + writer.Commit(); + } + + using var readerSession = sessions.GetSession(); + var reader = Reader.Create(buffer.WrittenMemory, readerSession); + var field = reader.ReadFieldHeader(); + Ensure(field.FieldType == typeof(T), "Raw message responses encode the result type."); + using var result = (Response)codec.ReadRaw(ref reader, ref field); + Ensure(Equals(value, result.GetResult()), "Raw message responses retain result values."); + } + } + +#if NATIVE_AOT_SMOKE + public static void MissingNativeResponseRegistration() + { + using var services = CreateServices(); + var provider = services.GetRequiredService(); + Check(() => provider.GetCodec(typeof(Response))); + Check(() => provider.GetDeepCopier(typeof(Response))); + + static void Check(Action lookup) + { + try + { + lookup(); + } + catch (NotSupportedException exception) + { + Ensure(exception.Message.Contains(typeof(Response).ToString(), StringComparison.Ordinal) + && exception.Message.Contains("serializer context", StringComparison.Ordinal), + "Missing response registrations identify the closed response and registration contract."); + return; + } + + throw new InvalidOperationException("A missing native response registration must fail at lookup."); + } + } +#endif + + private static ServiceProvider CreateServices() + { +#if NATIVE_AOT_SMOKE + return new ServiceCollection().AddSerializerContext(new global::OrleansCodeGen.OrleansNativeAotSmoke.RpcResponseFactories()).BuildServiceProvider(); +#else + return new ServiceCollection().AddSerializer(builder => builder.AddAssembly(typeof(IRpcResponses).Assembly)).BuildServiceProvider(); +#endif + } + + private static Response Copy(ServiceProvider services, Response response) + { + var provider = services.GetRequiredService(); + var pool = services.GetRequiredService(); +#if NATIVE_AOT_SMOKE + using var context = pool.GetContext(); + return (Response)provider.GetDeepCopier(response.GetType()).DeepCopy(response, context)!; +#else + return new DeepCopier(provider.GetDeepCopier(), pool).Copy(response); +#endif + } + + private static Response RoundTrip(ServiceProvider services, Response response) + { + var codec = services.GetRequiredService().GetCodec(response.GetType()); + var sessions = services.GetRequiredService(); + var buffer = new ArrayBufferWriter(); + using (var session = sessions.GetSession()) + { + var writer = Writer.Create(buffer, session); + codec.WriteField(ref writer, 0, response.GetType(), response); + writer.Commit(); + } + + using var readerSession = sessions.GetSession(); + var reader = Reader.Create(buffer.WrittenMemory, readerSession); + return (Response)codec.ReadValue(ref reader, reader.ReadFieldHeader())!; + } + + private static void Ensure([System.Diagnostics.CodeAnalysis.DoesNotReturnIf(false)] bool condition, string message) + { + if (!condition) throw new InvalidOperationException(message); + } +} diff --git a/test/Orleans.NativeAotSmoke/RpcResponses.cs b/test/Orleans.NativeAotSmoke/RpcResponses.cs new file mode 100644 index 00000000000..f3ef40399f2 --- /dev/null +++ b/test/Orleans.NativeAotSmoke/RpcResponses.cs @@ -0,0 +1,9 @@ +using System; +using Orleans.NativeAotSmoke; + +RpcResponseContracts.PrimitiveResponses(); +RpcResponseContracts.ReferenceResponsePreservesCycles(); +RpcResponseContracts.NullResponsePayload(); +RpcResponseContracts.RawResponses(); +RpcResponseContracts.MissingNativeResponseRegistration(); +Console.WriteLine("Native RPC response factories passed: bool, int, reference payloads, cycles, null, and raw message encoding."); diff --git a/test/Orleans.NativeAotSmoke/RpcResponses.smoke.json b/test/Orleans.NativeAotSmoke/RpcResponses.smoke.json new file mode 100644 index 00000000000..6c9b83bb1b8 --- /dev/null +++ b/test/Orleans.NativeAotSmoke/RpcResponses.smoke.json @@ -0,0 +1,5 @@ +{ + "scenario": "RpcResponses", + "diagnostics": "strict", + "rejectDiagnostics": [] +} diff --git a/test/Orleans.NativeAotSmoke/RpcResponsesModels.cs b/test/Orleans.NativeAotSmoke/RpcResponsesModels.cs new file mode 100644 index 00000000000..f0510b51bf9 --- /dev/null +++ b/test/Orleans.NativeAotSmoke/RpcResponsesModels.cs @@ -0,0 +1,33 @@ +using System.Threading.Tasks; +using Orleans; +using Orleans.Serialization.Invocation; + +namespace Orleans.NativeAotSmoke; + +public interface IRpcResponses : IGrainWithIntegerKey +{ + [Id(0)] + Task Boolean(); + + [Id(1)] + ValueTask Integer(); + + [Id(2)] + Task Payload(); +} + +[GenerateSerializer] +public sealed class RpcResponsePayload +{ + [Id(0)] + public int Value { get; set; } + + [Id(1)] + public RpcResponsePayload Left { get; set; } = null!; + + [Id(2)] + public RpcResponsePayload Right { get; set; } = null!; + + [Id(3)] + public Response Envelope { get; set; } = null!; +} diff --git a/test/Orleans.Serialization.UnitTests/Orleans.Serialization.UnitTests.csproj b/test/Orleans.Serialization.UnitTests/Orleans.Serialization.UnitTests.csproj index 16942d7f27c..e2fe0466882 100644 --- a/test/Orleans.Serialization.UnitTests/Orleans.Serialization.UnitTests.csproj +++ b/test/Orleans.Serialization.UnitTests/Orleans.Serialization.UnitTests.csproj @@ -38,6 +38,8 @@ + + _services.Dispose(); + + [Fact] + public void ConcreteResponseCodecsPreserveLegacyWireFormat() + { + Check(false, new BoolCodec()); + Check(true, new BoolCodec()); + Check(0, new Int32Codec()); + Check(42, new Int32Codec()); + Check(-17, new Int32Codec()); + Check(null!, new StringCodec()); + + void Check(T value, TCodec resultCodec) where TCodec : class, IFieldCodec + { + using var response = Response.FromResult(value); + var concrete = new PooledResponseCodec(resultCodec); + var legacy = new PooledResponseCodec(_services.GetRequiredService()); + var expected = Write(legacy, (Response)response); + var actual = Write(concrete, (Response)response); + Assert.Equal(expected, actual); + + using var session = _services.GetRequiredService().GetSession(); + var reader = Reader.Create(actual, session); + using var roundTrip = concrete.ReadValue(ref reader, reader.ReadFieldHeader()); + Assert.NotNull(roundTrip); + Assert.Equal(value, roundTrip.TypedResult); + } + } + + [Fact] + public void ConcreteResponseCodecPreservesRawMessageEncoding() + { + var codec = new PooledResponseCodec(new Int32Codec()); + using var response = Response.FromResult(42); + var buffer = new ArrayBufferWriter(); + var sessions = _services.GetRequiredService(); + using (var session = sessions.GetSession()) + { + var writer = Writer.Create(buffer, session); + codec.WriteRaw(ref writer, response); + writer.Commit(); + } + + using var readerSession = sessions.GetSession(); + var reader = Reader.Create(buffer.WrittenMemory, readerSession); + var header = reader.ReadFieldHeader(); + Assert.Equal(typeof(int), header.FieldType); + using var result = (Response)codec.ReadRaw(ref reader, ref header); + Assert.Equal(42, result.TypedResult); + } + + [Fact] + public void ConcreteResponseCopiersPreserveNullAndPooledEnvelopeSemantics() + { + var copier = new PooledResponseCopier>(new ShallowCopier()); + using var context = _services.GetRequiredService().GetContext(); + Assert.Null(copier.DeepCopy(null, context)); + using var response = (Response)Response.FromResult(42); + var copy = copier.DeepCopy(response, context); + Assert.NotSame(response, copy); + Assert.Equal(42, copy.TypedResult); + copy.Dispose(); + Assert.Equal(0, copy.TypedResult); + Assert.Equal(42, response.TypedResult); + } + + [Fact] + public void ConcreteResponseFactoriesValidateResultDependencies() + { + Assert.Equal("codec", Assert.Throws(() => new PooledResponseCodec((Int32Codec)null!)).ParamName); + Assert.Equal("copier", Assert.Throws(() => new PooledResponseCopier>((ShallowCopier)null!)).ParamName); + } + + [Fact] + public void GeneratedResponseFactoriesCopyAndSerializePrimitiveResults() + => NativeAotSmoke.RpcResponseContracts.PrimitiveResponses(); + + [Fact] + public void GeneratedResponseFactoriesPreserveReferencePayloadCycles() + => NativeAotSmoke.RpcResponseContracts.ReferenceResponsePreservesCycles(); + + [Fact] + public void GeneratedResponseFactoriesPreserveNullPayloads() + => NativeAotSmoke.RpcResponseContracts.NullResponsePayload(); + + [Fact] + public void GeneratedResponseFactoriesPreserveRawMessageResponses() + => NativeAotSmoke.RpcResponseContracts.RawResponses(); + + [Fact] + public void AutomaticResponseFactoriesPreserveCustomJitPayloadCopier() + { + using var services = new ServiceCollection() + .AddSerializer(builder => builder.Configure(options => options.AddCopier(typeof(CustomPayloadCopier)))) + .BuildServiceProvider(); + var payload = new NativeAotSmoke.RpcResponsePayload { Value = 42 }; + using var response = Response.FromResult(payload); + using var copy = services.GetRequiredService().Copy(response); + Assert.NotSame(response, copy); + Assert.Same(payload, copy.GetResult()); + Assert.IsType>( + services.GetRequiredService().GetDeepCopier(response.GetType())); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public void DefaultFactoryRegistrationsYieldToExplicitFactories(bool explicitFirst) + { + var codec = new Int32Codec(); + var copier = new ShallowCopier(); + var service = new FactoryService(); + using var services = new ServiceCollection() + .AddSerializer(builder => builder.Configure(options => + { + if (explicitFirst) RegisterExplicit(options); + options.AddDefaultSerializer(static _ => new Int32Codec(), static _ => new ShallowCopier()); + options.AddDefaultSerializerService(static _ => new FactoryService()); + options.AddDefaultSerializer(static _ => throw new InvalidOperationException("duplicate default codec"), static _ => throw new InvalidOperationException("duplicate default copier")); + options.AddDefaultSerializerService(static _ => throw new InvalidOperationException("duplicate default service")); + if (!explicitFirst) RegisterExplicit(options); + })) + .BuildServiceProvider(); + var provider = services.GetRequiredService(); + Assert.Same(codec, provider.GetCodec()); + Assert.Same(copier, provider.GetDeepCopier()); + Assert.Same(service, OrleansGeneratedCodeHelper.GetService(null!, provider)); + + void RegisterExplicit(TypeManifestOptions options) + { + options.AddSerializer(_ => codec, _ => copier); + options.AddSerializerService(_ => service); + } + } + + [Fact] + public void DuplicateDefaultFactoryRegistrationsUseFirstImplementation() + { + var codec = new Int32Codec(); + var copier = new ShallowCopier(); + var service = new FactoryService(); + using var services = new ServiceCollection().AddSerializer(builder => + { + builder.Configure(options => + { + options.AddDefaultSerializer(_ => codec, _ => copier); + options.AddDefaultSerializerService(_ => service); + }); + builder.Configure(options => + { + options.AddDefaultSerializer(static _ => throw new InvalidOperationException("second manifest codec"), + static _ => throw new InvalidOperationException("second manifest copier")); + options.AddDefaultSerializerService(static _ => throw new InvalidOperationException("second manifest service")); + }); + }).BuildServiceProvider(); + var provider = services.GetRequiredService(); + Assert.Same(codec, provider.GetCodec()); + Assert.Same(copier, provider.GetDeepCopier()); + Assert.Same(service, OrleansGeneratedCodeHelper.GetService(null!, provider)); + } + + [Theory] + [InlineData("Boolean")] + [InlineData("Integer")] + [InlineData("Payload")] + public async Task GeneratedInvokablesReturnClosedResponses(string methodName) + { + var target = new RpcResponseTarget(); + using var invokable = CreateInvokable(methodName); + invokable.SetTarget(new TargetHolder(target)); + using var response = await invokable.Invoke(); + using var copy = new DeepCopier(_services.GetRequiredService().GetDeepCopier(), + _services.GetRequiredService()).Copy(response); + if (methodName == "Boolean") + { + Assert.IsType>(response); + Assert.True(copy.GetResult()); + } + else if (methodName == "Integer") + { + Assert.IsType>(response); + Assert.Equal(42, copy.GetResult()); + } + else + { + Assert.IsType>(response); + var result = copy.GetResult(); + Assert.NotNull(result); + Assert.NotSame(target.Result, result); + Assert.Equal(17, result.Value); + } + } + + [Fact] + public async Task GeneratedInvokablesPreserveExceptionResponses() + { + using var invokable = CreateInvokable("Boolean"); + invokable.SetTarget(new TargetHolder(new RpcResponseTarget { Fail = true })); + using var response = await invokable.Invoke(); + Assert.IsType(response); + Assert.Equal("response failure", Assert.IsType(response.Exception).Message); + Assert.Throws(() => response.GetResult()); + using var copied = _services.GetRequiredService().Copy(response); + Assert.Same(response, copied); + } + + private static IInvokable CreateInvokable(string methodName) + { + var invokables = typeof(NativeAotSmoke.IRpcResponses).Assembly.GetTypes() + .Where(static type => !type.IsAbstract && typeof(IInvokable).IsAssignableFrom(type) + && type.Name.StartsWith("Invokable_IRpcResponses_", StringComparison.Ordinal)) + .Select(static type => (IInvokable)Activator.CreateInstance(type)!); + var result = invokables.Single(invokable => invokable.GetMethodName() == methodName); + return result; + } + + private sealed class TargetHolder(object target) : ITargetHolder + { + public object GetTarget() => target; + public object? GetComponent(Type componentType) => componentType.IsInstanceOfType(target) ? target : null; + } + + private sealed class RpcResponseTarget : NativeAotSmoke.IRpcResponses + { + public bool Fail { get; init; } + public NativeAotSmoke.RpcResponsePayload Result { get; } = new() { Value = 17 }; + public Task Boolean() => Fail ? throw new InvalidOperationException("response failure") : Task.FromResult(true); + public ValueTask Integer() => ValueTask.FromResult(42); + public Task Payload() => Task.FromResult(Result); + } + + public sealed class FactoryService + { + } + + public sealed class CustomPayloadCopier : IDeepCopier + { + [return: System.Diagnostics.CodeAnalysis.NotNullIfNotNull(nameof(input))] + public NativeAotSmoke.RpcResponsePayload? DeepCopy(NativeAotSmoke.RpcResponsePayload? input, CopyContext context) => input; + } + + private byte[] Write(IFieldCodec codec, T value) + { + var buffer = new ArrayBufferWriter(); + using var session = _services.GetRequiredService().GetSession(); + var writer = Writer.Create(buffer, session); + codec.WriteField(ref writer, 0, typeof(T), value); + writer.Commit(); + return buffer.WrittenSpan.ToArray(); + } +} From da8b3b05a804fd57feb94a91882a86f300093db9 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Thu, 1 Oct 2026 11:43:29 -0700 Subject: [PATCH 02/54] fix(codegen): register polymorphic native response dispatch --- .../docs/implementation/serialization.md | 2 ++ .../RpcResponseGenerator.cs | 21 ++++++++++++++- .../OrleansSourceGeneratorTests.cs | 3 +++ ...eGeneratorTests.TestBasicGrain.verified.cs | 27 +++++++++++++++++++ ...ateMethodSerializersAnnotation.verified.cs | 27 +++++++++++++++++++ ...torTests.TestGrainComplexGrain.verified.cs | 27 +++++++++++++++++++ ...AnnotatedWithInvokableBaseType.verified.cs | 27 +++++++++++++++++++ ...odAnnotatedWithResponseTimeout.verified.cs | 27 +++++++++++++++++++ ...TestGrainWithDifferentKeyTypes.verified.cs | 27 +++++++++++++++++++ ...estGrainWithMultipleInterfaces.verified.cs | 27 +++++++++++++++++++ .../RpcResponses.Contracts.cs | 23 +++++++++++----- test/Orleans.NativeAotSmoke/RpcResponses.cs | 3 ++- .../RpcResponseTests.cs | 9 +++++++ 13 files changed, 241 insertions(+), 9 deletions(-) diff --git a/docs/site/src/content/docs/implementation/serialization.md b/docs/site/src/content/docs/implementation/serialization.md index 166fa9d61ad..34e710d6619 100644 --- a/docs/site/src/content/docs/implementation/serialization.md +++ b/docs/site/src/content/docs/implementation/serialization.md @@ -135,6 +135,8 @@ Arguments and result values use normal Orleans.Serialization codecs and copiers. For concrete `Task` and `ValueTask` method results, generated metadata supplies a closed response codec and copier graph for NativeAOT execution. The graph uses the concrete result implementations in and . Recursive result dependencies resolve with a construction caller after the response implementation has been allocated. Reference payload codecs and copiers preserve payload cycles and shared references, and the pooled response envelope retains the existing field and raw-message encoding. +The graph also registers polymorphic codec and copier dispatch for the non-generic boundary used by the runtime client. That dispatch selects the closed implementation for the actual response type and preserves the identity of immutable completed and exception responses. The native smoke uses with `Response`, matching the runtime's response-copy boundary. + These supplemental registrations are defaults: explicit closed factory registrations take precedence in either configuration order. The automatic provider activates when runtime code generation is unavailable. JIT execution continues to use the existing serializer and copier selection, including application-provided payload implementations. Explicit factory and context registration also works in JIT execution. `OrleansValidateRpcResponseFactories` enables compile-time validation of the response graph and defaults to the executable project's `PublishAot` setting. Diagnostic `ORLEANS0116` identifies an unresolved generic result, a custom return adapter requiring an explicit response contract, or a result dependency outside the supported finite graph. Applications with runtime-selected generic results register every permitted closed graph explicitly through and in a , and set `OrleansValidateRpcResponseFactories=false` for the project supplying that contract. A missing native response registration reports the closed response type and registration guidance at lookup. diff --git a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs index bf1dddbafa5..3c77d5f0d7c 100644 --- a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs +++ b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs @@ -122,15 +122,34 @@ internal static ImmutableArray Generate( source.AppendLine("#if NET5_0_OR_GREATER"); source.AppendLine("if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) return;"); source.AppendLine(graph.ConfigurationStatements); + source.AppendLine("options.AddDefaultSerializerService(static provider => new ResponseFieldCodec());"); + source.AppendLine("options.AddDefaultSerializerService(static provider => new ResponseFieldCopier());"); + source.AppendLine("options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null!, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null!, provider));"); source.AppendLine("#endif"); source.AppendLine("}"); + source.AppendLine("private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer"); + source.AppendLine("{"); + source.AppendLine("public ResponseFieldCodec() { }"); + source.AppendLine("}"); + source.AppendLine("private sealed class ResponseFieldCopier : global::Orleans.Serialization.Cloning.IDeepCopier"); + source.AppendLine("{"); + source.AppendLine("public ResponseFieldCopier() { }"); + source.AppendLine("[return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull(\"input\")]"); + source.AppendLine("public global::Orleans.Serialization.Invocation.Response DeepCopy(global::Orleans.Serialization.Invocation.Response input, global::Orleans.Serialization.Cloning.CopyContext context)"); + source.AppendLine("{"); + source.AppendLine("if (context is null) throw new global::System.ArgumentNullException(nameof(context));"); + source.AppendLine("if (input is global::Orleans.Serialization.Invocation.CompletedResponse or global::Orleans.Serialization.Invocation.ExceptionResponse) return input;"); + source.AppendLine("return (global::Orleans.Serialization.Invocation.Response)global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context);"); + source.AppendLine("}"); + source.AppendLine("}"); source.AppendLine("}"); source.AppendLine("}"); var unit = CSharpSyntaxTree.ParseText(source.ToString(), options: new CSharpParseOptions(preprocessorSymbols: ["NET5_0_OR_GREATER"]), cancellationToken: cancellationToken).GetCompilationUnitRoot(cancellationToken); - var provider = unit.DescendantNodes().OfType().Single(); + var provider = unit.DescendantNodes().OfType() + .Single(static declaration => declaration.Identifier.ValueText == "RpcResponseFactories"); unit = unit.ReplaceNode(provider, provider.AddAttributeLists(GeneratedCodeUtilities.GetGeneratedCodeAttributes())); output.Add(SourceOutputResult.FromSource(new GeneratedSourceEntry( $"{compilation.AssemblyName}.orleans.rpcresponses.g.cs", unit.NormalizeWhitespace().ToFullString()))); diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index d22d0176d72..cadc65c492d 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -2280,6 +2280,9 @@ public sealed class Payload Assert.DoesNotContain("MakeGenericType", source); Assert.DoesNotContain("WellKnownTypeAliases", source); Assert.Contains("WellKnownTypeAliases.Add(\"rpc.payload\"", ConcatenateGeneratedSources(result)); + Assert.Contains("options.AddDefaultSerializer", source); + Assert.Contains("AbstractTypeSerializer", source); + Assert.Contains("global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context)", source); var outputCompilation = compilation.AddReferences(MetadataReference.CreateFromFile(typeof(Microsoft.Extensions.Options.IConfigureOptions<>).Assembly.Location)) .AddSyntaxTrees(result.GeneratedSources.Select(static source => CSharpSyntaxTree.ParseText(source.SourceText, options: new CSharpParseOptions().WithPreprocessorSymbols("NET5_0_OR_GREATER"), path: source.HintName))); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.verified.cs index 31a4dd1596a..18943c92124 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.verified.cs @@ -263,8 +263,35 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(string)); + options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); + options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); #endif } + + private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer + { + public ResponseFieldCodec() + { + } + } + + private sealed class ResponseFieldCopier : global::Orleans.Serialization.Cloning.IDeepCopier + { + public ResponseFieldCopier() + { + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public global::Orleans.Serialization.Invocation.Response DeepCopy(global::Orleans.Serialization.Invocation.Response input, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context is null) + throw new global::System.ArgumentNullException(nameof(context)); + if (input is global::Orleans.Serialization.Invocation.CompletedResponse or global::Orleans.Serialization.Invocation.ExceptionResponse) + return input; + return (global::Orleans.Serialization.Invocation.Response)global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context); + } + } } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.verified.cs index 82444f74097..306d5be2f2b 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.verified.cs @@ -171,8 +171,35 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(string)); + options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); + options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); #endif } + + private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer + { + public ResponseFieldCodec() + { + } + } + + private sealed class ResponseFieldCopier : global::Orleans.Serialization.Cloning.IDeepCopier + { + public ResponseFieldCopier() + { + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public global::Orleans.Serialization.Invocation.Response DeepCopy(global::Orleans.Serialization.Invocation.Response input, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context is null) + throw new global::System.ArgumentNullException(nameof(context)); + if (input is global::Orleans.Serialization.Invocation.CompletedResponse or global::Orleans.Serialization.Invocation.ExceptionResponse) + return input; + return (global::Orleans.Serialization.Invocation.Response)global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context); + } + } } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.verified.cs index 0a4ee576fb5..2b6ac662f44 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.verified.cs @@ -464,8 +464,35 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(string)); + options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); + options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); #endif } + + private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer + { + public ResponseFieldCodec() + { + } + } + + private sealed class ResponseFieldCopier : global::Orleans.Serialization.Cloning.IDeepCopier + { + public ResponseFieldCopier() + { + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public global::Orleans.Serialization.Invocation.Response DeepCopy(global::Orleans.Serialization.Invocation.Response input, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context is null) + throw new global::System.ArgumentNullException(nameof(context)); + if (input is global::Orleans.Serialization.Invocation.CompletedResponse or global::Orleans.Serialization.Invocation.ExceptionResponse) + return input; + return (global::Orleans.Serialization.Invocation.Response)global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context); + } + } } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.verified.cs index bc446b73dc2..93a6b5cb7cf 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.verified.cs @@ -268,8 +268,35 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(string)); + options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); + options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); #endif } + + private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer + { + public ResponseFieldCodec() + { + } + } + + private sealed class ResponseFieldCopier : global::Orleans.Serialization.Cloning.IDeepCopier + { + public ResponseFieldCopier() + { + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public global::Orleans.Serialization.Invocation.Response DeepCopy(global::Orleans.Serialization.Invocation.Response input, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context is null) + throw new global::System.ArgumentNullException(nameof(context)); + if (input is global::Orleans.Serialization.Invocation.CompletedResponse or global::Orleans.Serialization.Invocation.ExceptionResponse) + return input; + return (global::Orleans.Serialization.Invocation.Response)global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context); + } + } } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.verified.cs index 6dd28d9e70e..e82aa9ee8f8 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.verified.cs @@ -170,8 +170,35 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(string)); + options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); + options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); #endif } + + private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer + { + public ResponseFieldCodec() + { + } + } + + private sealed class ResponseFieldCopier : global::Orleans.Serialization.Cloning.IDeepCopier + { + public ResponseFieldCopier() + { + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public global::Orleans.Serialization.Invocation.Response DeepCopy(global::Orleans.Serialization.Invocation.Response input, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context is null) + throw new global::System.ArgumentNullException(nameof(context)); + if (input is global::Orleans.Serialization.Invocation.CompletedResponse or global::Orleans.Serialization.Invocation.ExceptionResponse) + return input; + return (global::Orleans.Serialization.Invocation.Response)global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context); + } + } } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.verified.cs index 3884f72c9fb..ac6c5520765 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.verified.cs @@ -789,8 +789,35 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(string)); + options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); + options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); #endif } + + private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer + { + public ResponseFieldCodec() + { + } + } + + private sealed class ResponseFieldCopier : global::Orleans.Serialization.Cloning.IDeepCopier + { + public ResponseFieldCopier() + { + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public global::Orleans.Serialization.Invocation.Response DeepCopy(global::Orleans.Serialization.Invocation.Response input, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context is null) + throw new global::System.ArgumentNullException(nameof(context)); + if (input is global::Orleans.Serialization.Invocation.CompletedResponse or global::Orleans.Serialization.Invocation.ExceptionResponse) + return input; + return (global::Orleans.Serialization.Invocation.Response)global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context); + } + } } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.verified.cs index 00fb1ee63e1..8deff7a33af 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.verified.cs @@ -307,8 +307,35 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(string)); + options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); + options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); #endif } + + private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer + { + public ResponseFieldCodec() + { + } + } + + private sealed class ResponseFieldCopier : global::Orleans.Serialization.Cloning.IDeepCopier + { + public ResponseFieldCopier() + { + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public global::Orleans.Serialization.Invocation.Response DeepCopy(global::Orleans.Serialization.Invocation.Response input, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context is null) + throw new global::System.ArgumentNullException(nameof(context)); + if (input is global::Orleans.Serialization.Invocation.CompletedResponse or global::Orleans.Serialization.Invocation.ExceptionResponse) + return input; + return (global::Orleans.Serialization.Invocation.Response)global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context); + } + } } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] diff --git a/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs b/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs index e966e6a25e8..8c3dc3146ef 100644 --- a/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs +++ b/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs @@ -69,6 +69,20 @@ public static void NullResponsePayload() "Empty reference response payloads retain null."); } + public static void CompletedAndExceptionResponses() + { + using var services = CreateServices(); + var cause = new InvalidOperationException("response failure"); + var mutableData = new RpcResponsePayload { Value = 17 }; + cause.Data["payload"] = mutableData; + using var exception = Response.FromException(cause); + using var copied = Copy(services, exception); + Ensure(ReferenceEquals(exception, copied), "Immutable exception responses retain their identity."); + Ensure(copied.Exception is { } copiedCause && ReferenceEquals(cause, copiedCause) && ReferenceEquals(mutableData, copiedCause.Data["payload"]), + "Immutable exception envelope copying retains the existing exception and Data references."); + Ensure(ReferenceEquals(Response.Completed, Copy(services, Response.Completed)), "Completed responses retain their singleton identity."); + } + public static void RawResponses() { using var services = CreateServices(); @@ -138,23 +152,18 @@ private static Response Copy(ServiceProvider services, Response response) { var provider = services.GetRequiredService(); var pool = services.GetRequiredService(); -#if NATIVE_AOT_SMOKE - using var context = pool.GetContext(); - return (Response)provider.GetDeepCopier(response.GetType()).DeepCopy(response, context)!; -#else return new DeepCopier(provider.GetDeepCopier(), pool).Copy(response); -#endif } private static Response RoundTrip(ServiceProvider services, Response response) { - var codec = services.GetRequiredService().GetCodec(response.GetType()); + var codec = services.GetRequiredService().GetCodec(); var sessions = services.GetRequiredService(); var buffer = new ArrayBufferWriter(); using (var session = sessions.GetSession()) { var writer = Writer.Create(buffer, session); - codec.WriteField(ref writer, 0, response.GetType(), response); + codec.WriteField(ref writer, 0, typeof(Response), response); writer.Commit(); } diff --git a/test/Orleans.NativeAotSmoke/RpcResponses.cs b/test/Orleans.NativeAotSmoke/RpcResponses.cs index f3ef40399f2..741b0309f32 100644 --- a/test/Orleans.NativeAotSmoke/RpcResponses.cs +++ b/test/Orleans.NativeAotSmoke/RpcResponses.cs @@ -4,6 +4,7 @@ RpcResponseContracts.PrimitiveResponses(); RpcResponseContracts.ReferenceResponsePreservesCycles(); RpcResponseContracts.NullResponsePayload(); +RpcResponseContracts.CompletedAndExceptionResponses(); RpcResponseContracts.RawResponses(); RpcResponseContracts.MissingNativeResponseRegistration(); -Console.WriteLine("Native RPC response factories passed: bool, int, reference payloads, cycles, null, and raw message encoding."); +Console.WriteLine("Native Response dispatch passed: DeepCopier, bool, int, reference cycles, null, completion/exception identity, and raw message encoding."); diff --git a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs index ba2666783c9..31c3e883448 100644 --- a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs +++ b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs @@ -111,6 +111,15 @@ public void GeneratedResponseFactoriesPreserveNullPayloads() public void GeneratedResponseFactoriesPreserveRawMessageResponses() => NativeAotSmoke.RpcResponseContracts.RawResponses(); + [Fact] + public void GeneratedResponseFactoriesPreserveCompletionAndExceptionIdentity() + { + var provider = _services.GetRequiredService(); + Assert.IsType>(provider.GetDeepCopier()); + Assert.IsType>(provider.GetDeepCopier()); + NativeAotSmoke.RpcResponseContracts.CompletedAndExceptionResponses(); + } + [Fact] public void AutomaticResponseFactoriesPreserveCustomJitPayloadCopier() { From 85fd6fccc38e1d7ca349cf67b94115f685fd1314 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Thu, 1 Oct 2026 11:59:17 -0700 Subject: [PATCH 03/54] fix(codegen): require explicit dictionary response comparer contracts --- .../docs/implementation/serialization.md | 2 ++ .../RpcResponseGenerator.cs | 11 +++++++++- .../OrleansSourceGeneratorTests.cs | 22 +++++++++++++++++++ .../RpcResponseTests.cs | 18 +++++++++++++++ 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/docs/site/src/content/docs/implementation/serialization.md b/docs/site/src/content/docs/implementation/serialization.md index 34e710d6619..d93e421dec0 100644 --- a/docs/site/src/content/docs/implementation/serialization.md +++ b/docs/site/src/content/docs/implementation/serialization.md @@ -141,6 +141,8 @@ These supplemental registrations are defaults: explicit closed factory registrat `OrleansValidateRpcResponseFactories` enables compile-time validation of the response graph and defaults to the executable project's `PublishAot` setting. Diagnostic `ORLEANS0116` identifies an unresolved generic result, a custom return adapter requiring an explicit response contract, or a result dependency outside the supported finite graph. Applications with runtime-selected generic results register every permitted closed graph explicitly through and in a , and set `OrleansValidateRpcResponseFactories=false` for the project supplying that contract. A missing native response registration reports the closed response type and registration guidance at lookup. +Dictionary results and dictionary members require an explicit closed registration which preserves the application's comparer contract. A dictionary's comparer is selected per value, so the method's declared result type alone supplies the key/value shape while the registration supplies comparer serialization and copying. + The focused native smoke exercises the generated response graph for boolean, integer, and reference results, including recursive factory dependencies and payload identity. Full silo startup and RPC execution additionally require the native support for activation, request serialization, grain references, and runtime metadata. Source: [RPC response factory generation](https://github.com/dotnet/orleans/blob/main/src/Orleans.CodeGenerator/RpcResponseGenerator.cs), [closed serializer factory graphs](https://github.com/dotnet/orleans/blob/main/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs), and [native response smoke](https://github.com/dotnet/orleans/blob/main/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs). diff --git a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs index 3c77d5f0d7c..6479a0f0b2e 100644 --- a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs +++ b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs @@ -78,12 +78,21 @@ internal static ImmutableArray Generate( } var supportedResults = new List(); + var dictionaryDefinition = compilation.GetTypeByMetadataName("System.Collections.Generic.Dictionary`2"); foreach (var entry in results.OrderBy(static entry => entry.Key.ToDisplayString(), StringComparer.Ordinal)) { var resultType = entry.Key; var method = entry.Value; - if (SerializerFactoryGenerator.TryCreate(services, [responseDefinition.Construct(resultType)], cancellationToken, out _, out var failure)) + if (SerializerFactoryGenerator.TryCreate(services, [responseDefinition.Construct(resultType)], cancellationToken, out var candidate, out var failure)) { + var dictionary = candidate.Registrations.Keys.OfType() + .FirstOrDefault(type => SymbolEqualityComparer.Default.Equals(type.OriginalDefinition, dictionaryDefinition)); + if (dictionary is not null) + { + Report(method, dictionary, "dictionary comparers are selected per value and require an explicit closed registration preserving the comparer contract"); + continue; + } + supportedResults.Add(resultType); } else diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index cadc65c492d..d787540812a 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -2309,6 +2309,28 @@ public interface IResponses : IGrainWithIntegerKey { {{method}} } Assert.NotEqual(Location.None, diagnostic.Location); } + [Theory] + [InlineData("System.Collections.Generic.Dictionary")] + [InlineData("System.Collections.Generic.List>")] + public async Task RpcResponseFactoriesRequireExplicitDictionaryComparerContract(string resultType) + { + var compilation = await CreateCompilation($$""" + using Orleans; + using System.Threading.Tasks; + namespace TestProject; + public interface IResponses : IGrainWithIntegerKey { Task<{{resultType}}> Get(); } + """); + var native = RunSourceGenerator(compilation, new Dictionary { ["build_property.publishaot"] = "true" }); + var diagnostic = Assert.Single(native.Diagnostics); + Assert.Equal("ORLEANS0116", diagnostic.Id); + Assert.Contains("comparer contract", diagnostic.GetMessage()); + Assert.Contains("Dictionary", diagnostic.GetMessage()); + Assert.DoesNotContain(native.GeneratedSources, static source => source.HintName.EndsWith(".orleans.rpcresponses.g.cs", StringComparison.Ordinal)); + var jit = RunSourceGenerator(compilation); + Assert.Empty(jit.Diagnostics); + Assert.Contains(jit.GeneratedSources, static source => source.HintName.Contains(".orleans.proxy.", StringComparison.Ordinal)); + } + [Fact] public async Task RpcResponseFactoriesPreserveGenericJitGenerationAndExplicitValidationOverride() { diff --git a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs index 31c3e883448..cf0a59a6e0c 100644 --- a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs +++ b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs @@ -1,5 +1,6 @@ using System; using System.Buffers; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; @@ -135,6 +136,23 @@ public void AutomaticResponseFactoriesPreserveCustomJitPayloadCopier() services.GetRequiredService().GetDeepCopier(response.GetType())); } + [Fact] + public void LegacyJitDictionaryResponsesPreserveCustomComparers() + { + var dictionary = new Dictionary(StringComparer.OrdinalIgnoreCase) { ["entry"] = 42 }; + using var response = (Response>)Response.FromResult(dictionary); + using var copy = _services.GetRequiredService().Copy(response); + Assert.NotSame(dictionary, copy.TypedResult); + Assert.Same(StringComparer.OrdinalIgnoreCase, copy.TypedResult!.Comparer); + Assert.Equal(42, copy.TypedResult["ENTRY"]); + var serializer = _services.GetRequiredService(); + using var result = serializer.Deserialize>>(serializer.SerializeToArray(response)); + Assert.NotNull(result); + Assert.NotSame(dictionary, result.TypedResult); + Assert.Same(StringComparer.OrdinalIgnoreCase, result.TypedResult!.Comparer); + Assert.Equal(42, result.TypedResult["ENTRY"]); + } + [Theory] [InlineData(false)] [InlineData(true)] From 8281c819c8f4d4366d751aa77163acab162abf84 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Thu, 1 Oct 2026 12:48:30 -0700 Subject: [PATCH 04/54] fix(codegen): root generated response models in metadata mode --- .../docs/implementation/serialization.md | 2 + .../RpcResponseGenerator.cs | 30 ++++++- .../SerializerFactoryGenerator.cs | 80 +++++++++++++++++++ .../OrleansSourceGeneratorTests.cs | 32 ++++++++ 4 files changed, 141 insertions(+), 3 deletions(-) diff --git a/docs/site/src/content/docs/implementation/serialization.md b/docs/site/src/content/docs/implementation/serialization.md index d93e421dec0..9c73670c3cf 100644 --- a/docs/site/src/content/docs/implementation/serialization.md +++ b/docs/site/src/content/docs/implementation/serialization.md @@ -139,6 +139,8 @@ The graph also registers polymorphic codec and copier dispatch for the non-gener These supplemental registrations are defaults: explicit closed factory registrations take precedence in either configuration order. The automatic provider activates when runtime code generation is unavailable. JIT execution continues to use the existing serializer and copier selection, including application-provided payload implementations. Explicit factory and context registration also works in JIT execution. +Ordinary metadata mode also supplies static response factories for non-generic generated result models. These factories construct the model's canonical generated codec and copier using their generated constructor signatures; nested model dependencies retain the existing metadata-service resolution. Explicit context mode uses the complete finite dependency graph and validates each declared member shape. + `OrleansValidateRpcResponseFactories` enables compile-time validation of the response graph and defaults to the executable project's `PublishAot` setting. Diagnostic `ORLEANS0116` identifies an unresolved generic result, a custom return adapter requiring an explicit response contract, or a result dependency outside the supported finite graph. Applications with runtime-selected generic results register every permitted closed graph explicitly through and in a , and set `OrleansValidateRpcResponseFactories=false` for the project supplying that contract. A missing native response registration reports the closed response type and registration guidance at lookup. Dictionary results and dictionary members require an explicit closed registration which preserves the application's comparer contract. A dictionary's comparer is selected per value, so the method's declared result type alone supplies the key/value shape while the registration supplies comparer serialization and copying. diff --git a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs index 6479a0f0b2e..1679d9a11bb 100644 --- a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs +++ b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs @@ -78,6 +78,7 @@ internal static ImmutableArray Generate( } var supportedResults = new List(); + var metadataModelRoots = new List(); var dictionaryDefinition = compilation.GetTypeByMetadataName("System.Collections.Generic.Dictionary`2"); foreach (var entry in results.OrderBy(static entry => entry.Key.ToDisplayString(), StringComparer.Ordinal)) { @@ -97,16 +98,24 @@ internal static ImmutableArray Generate( } else { + if (!options.ValidateRpcResponseFactories && resultType is INamedTypeSymbol named + && SerializerFactoryGenerator.CreateRpcModelRoot(services, named, cancellationToken) is { } metadataRoot) + { + metadataModelRoots.Add(metadataRoot); + continue; + } + Report(method, failure.Type, failure.Reason); } } - if (supportedResults.Count == 0) + if (supportedResults.Count == 0 && metadataModelRoots.Count == 0) { return output.ToImmutable(); } - if (!SerializerFactoryGenerator.TryCreate(services, supportedResults.Select(type => responseDefinition.Construct(type)), cancellationToken, out var graph, out var graphFailure, useDefaultFactories: true)) + SerializerFactoryGenerator.Graph? graph = null; + if (supportedResults.Count > 0 && !SerializerFactoryGenerator.TryCreate(services, supportedResults.Select(type => responseDefinition.Construct(type)), cancellationToken, out graph, out var graphFailure, useDefaultFactories: true)) { if (options.ValidateRpcResponseFactories) { @@ -130,7 +139,22 @@ internal static ImmutableArray Generate( source.AppendLine("{"); source.AppendLine("#if NET5_0_OR_GREATER"); source.AppendLine("if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) return;"); - source.AppendLine(graph.ConfigurationStatements); + if (graph is not null) + { + source.AppendLine(graph.ConfigurationStatements); + } + + if (metadataModelRoots.Count > 0) + { + source.AppendLine("if (!options.RequireExplicitTypeRegistration)"); + source.AppendLine("{"); + foreach (var metadataRoot in metadataModelRoots) + { + source.AppendLine(metadataRoot.ConfigurationStatements); + } + + source.AppendLine("}"); + } source.AppendLine("options.AddDefaultSerializerService(static provider => new ResponseFieldCodec());"); source.AppendLine("options.AddDefaultSerializerService(static provider => new ResponseFieldCopier());"); source.AppendLine("options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null!, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null!, provider));"); diff --git a/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs b/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs index 8d73c1d4310..0002a7dbb50 100644 --- a/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs +++ b/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs @@ -32,6 +32,65 @@ internal sealed class Graph(IReadOnlyDictionary regis internal sealed record Failure(ITypeSymbol Type, string Reason); + internal static Graph? CreateRpcModelRoot( + IGeneratorServices services, + INamedTypeSymbol type, + CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + if (type.IsGenericType || type.IsAbstract || type.TypeKind == TypeKind.Interface + || !type.HasAttribute(services.LibraryTypes.GenerateSerializerAttribute)) + { + return null; + } + + var registration = new Registration(type); + if (SymbolEqualityComparer.Default.Equals(type.ContainingAssembly, services.Compilation.Assembly)) + { + var model = SerializableSourceOutputGenerator.CreateSerializableTypeDescription(services, type); + if (model is null) return null; + DescribeGeneratedModel(registration, type, model); + ConstructGeneratedModel(registration, services); + } + else + { + var generatedNamespace = SerializerGenerator.GetGeneratedNamespaceName(type); + var codecType = services.Compilation.GetTypeByMetadataName($"{generatedNamespace}.{SerializerGenerator.GetSimpleClassName(type.Name)}"); + if (codecType is null) return null; + registration.Codec = Name(codecType); + registration.CodecConstruction = ConstructReferenced(registration.Codec, codecType); + if (services.LibraryTypes.IsShallowCopyable(type)) + { + registration.Copier = $"global::Orleans.Serialization.Cloning.ShallowCopier<{Name(type)}>"; + registration.CopierConstruction = $"new {registration.Copier}()"; + } + else + { + var copierType = services.Compilation.GetTypeByMetadataName($"{generatedNamespace}.{CopierGenerator.GetSimpleClassName(type.Name)}"); + if (copierType is null) return null; + registration.Copier = Name(copierType); + registration.CopierConstruction = ConstructReferenced(registration.Copier, copierType); + } + } + + var responseType = services.Compilation.GetTypeByMetadataName("Orleans.Serialization.Invocation.Response`1")!.Construct(type); + var codec = $"global::Orleans.Serialization.Invocation.PooledResponseCodec<{Name(type)}, {registration.Codec}>"; + var copier = $"global::Orleans.Serialization.Invocation.PooledResponseCopier<{Name(type)}, {registration.Copier}>"; + var result = new StringBuilder(); + result.Append("options.AddDefaultSerializerService<").Append(registration.Codec).Append(">(static provider => ") + .Append(registration.CodecConstruction).AppendLine(");"); + result.Append("options.AddDefaultSerializerService<").Append(registration.Copier).Append(">(static provider => ") + .Append(registration.CopierConstruction).AppendLine(");"); + result.Append("options.AddDefaultSerializerService<").Append(codec).Append(">(static provider => new ") + .Append(codec).Append("(caller => ").Append(Resolve(registration.Codec, "caller")).AppendLine("));"); + result.Append("options.AddDefaultSerializerService<").Append(copier).Append(">(static provider => new ") + .Append(copier).Append("(caller => ").Append(Resolve(registration.Copier, "caller")).AppendLine("));"); + result.Append("options.AddDefaultSerializer<").Append(Name(responseType)).Append(">(static provider => ") + .Append(Resolve(codec)).Append(", static provider => ").Append(Resolve(copier)).AppendLine(");"); + result.Append("options.AddAllowedType(typeof(").Append(Name(responseType)).AppendLine("));"); + return new Graph(new Dictionary(SymbolEqualityComparer.Default) { [type] = registration }, result.ToString()); + } + internal static bool TryCreate( IGeneratorServices services, IEnumerable roots, @@ -422,6 +481,27 @@ void ResolveResponseImplementations(Registration registration) } } + private static void DescribeGeneratedModel(Registration registration, INamedTypeSymbol named, ISerializableTypeDescription model) + { + var argumentsSuffix = named.IsGenericType ? $"<{string.Join(", ", named.TypeArguments.Select(Name))}>" : ""; + var generatedNamespace = SerializerGenerator.GetGeneratedNamespaceName(named); + registration.Codec = $"global::{generatedNamespace}.{SerializerGenerator.GetSimpleClassName(named.Name)}{argumentsSuffix}"; + registration.Copier = model.IsShallowCopyable + ? $"global::Orleans.Serialization.Cloning.ShallowCopier<{Name(named)}>" + : $"global::{generatedNamespace}.{CopierGenerator.GetSimpleClassName(named.Name)}{argumentsSuffix}"; + registration.Model = model; + } + + private static void ConstructGeneratedModel(Registration registration, IGeneratorServices services) + { + var codecDeclaration = new SerializerGenerator(services).Generate(registration.Model!); + var copierDeclaration = new CopierGenerator(services).GenerateCopier(registration.Model!, new()); + registration.CodecConstruction = ConstructGenerated(registration.Codec, codecDeclaration); + registration.CopierConstruction = copierDeclaration is null + ? $"new {registration.Copier}()" + : ConstructGenerated(registration.Copier, copierDeclaration); + } + private static string ConstructReferenced(string name, INamedTypeSymbol implementation) { var constructor = implementation.InstanceConstructors.Single(ctor => ctor.DeclaredAccessibility == Accessibility.Public); diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index d787540812a..cc79769dd78 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -2331,6 +2331,38 @@ public interface IResponses : IGrainWithIntegerKey { Task<{{resultType}}> Get(); Assert.Contains(jit.GeneratedSources, static source => source.HintName.Contains(".orleans.proxy.", StringComparison.Ordinal)); } + [Fact] + public async Task RpcResponseFactoriesRootCanonicalModelsInMetadataMode() + { + var compilation = await CreateCompilation(""" + using Orleans; + using System.Collections.Generic; + using System.Threading.Tasks; + namespace TestProject; + public interface IResponses : IGrainWithIntegerKey { Task Get(); } + [GenerateSerializer] + public sealed class Payload + { + [Id(0)] public IReadOnlyList> Members { get; private set; } + public Payload(IReadOnlyList> members) => Members = members; + } + """); + var result = RunSourceGenerator(compilation); + Assert.Empty(result.Diagnostics); + var source = Assert.Single(result.GeneratedSources, static source => source.HintName.EndsWith(".orleans.rpcresponses.g.cs", StringComparison.Ordinal)).SourceText.ToString(); + Assert.Contains("if (!options.RequireExplicitTypeRegistration)", source); + Assert.Contains("new global::OrleansCodeGen.TestProject.Codec_Payload(", source); + Assert.Contains("new global::OrleansCodeGen.TestProject.Copier_Payload(", source); + Assert.Contains("PooledResponseCodec", source); + Assert.DoesNotContain("MakeGenericType", source); + var output = compilation.AddReferences(MetadataReference.CreateFromFile(typeof(Microsoft.Extensions.Options.IConfigureOptions<>).Assembly.Location)) + .AddSyntaxTrees(result.GeneratedSources.Select(static item => CSharpSyntaxTree.ParseText(item.SourceText, + options: new CSharpParseOptions().WithPreprocessorSymbols("NET5_0_OR_GREATER"), path: item.HintName))); + Assert.Empty(output.GetDiagnostics(TestContext.Current.CancellationToken).Where(static diagnostic => diagnostic.Severity == DiagnosticSeverity.Error)); + var strict = RunSourceGenerator(compilation, new Dictionary { ["build_property.publishaot"] = "true" }); + Assert.Contains(strict.Diagnostics, static diagnostic => diagnostic.Id == "ORLEANS0116"); + } + [Fact] public async Task RpcResponseFactoriesPreserveGenericJitGenerationAndExplicitValidationOverride() { From 9628e8e026075133309b45fd6cea55dd8fa63ae1 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Thu, 1 Oct 2026 13:20:29 -0700 Subject: [PATCH 05/54] fix(codegen): define finite native response transport contracts --- .../docs/implementation/serialization.md | 4 +++ .../RpcResponseGenerator.cs | 10 +++++++ .../OrleansSourceGeneratorTests.cs | 2 ++ ...eGeneratorTests.TestBasicGrain.verified.cs | 14 ++++++++++ ...ateMethodSerializersAnnotation.verified.cs | 14 ++++++++++ ...torTests.TestGrainComplexGrain.verified.cs | 14 ++++++++++ ...AnnotatedWithInvokableBaseType.verified.cs | 14 ++++++++++ ...odAnnotatedWithResponseTimeout.verified.cs | 14 ++++++++++ ...TestGrainWithDifferentKeyTypes.verified.cs | 14 ++++++++++ ...estGrainWithMultipleInterfaces.verified.cs | 14 ++++++++++ .../RpcResponses.Contracts.cs | 26 +++++++++++++++++++ test/Orleans.NativeAotSmoke/RpcResponses.cs | 2 ++ .../RpcResponseTests.cs | 19 ++++++++++++++ 13 files changed, 161 insertions(+) diff --git a/docs/site/src/content/docs/implementation/serialization.md b/docs/site/src/content/docs/implementation/serialization.md index 9c73670c3cf..8ffbc854ff8 100644 --- a/docs/site/src/content/docs/implementation/serialization.md +++ b/docs/site/src/content/docs/implementation/serialization.md @@ -137,6 +137,10 @@ For concrete `Task` and `ValueTask` method results, generated The graph also registers polymorphic codec and copier dispatch for the non-generic boundary used by the runtime client. That dispatch selects the closed implementation for the actual response type and preserves the identity of immutable completed and exception responses. The native smoke uses with `Response`, matching the runtime's response-copy boundary. +Completed response transport uses the existing generated codec and its canonical singleton activator, restoring after a round-trip. + +The finite strict response graph supplies successful typed results and completed-response transport, plus immutable exception-envelope copying. Exception transport in an explicit context requires an codec and the declared exception and `Data` value type graph. Lookup reports that registration contract when it is missing. Ordinary metadata mode retains the existing exception codecs and their serialization-constructor support. + These supplemental registrations are defaults: explicit closed factory registrations take precedence in either configuration order. The automatic provider activates when runtime code generation is unavailable. JIT execution continues to use the existing serializer and copier selection, including application-provided payload implementations. Explicit factory and context registration also works in JIT execution. Ordinary metadata mode also supplies static response factories for non-generic generated result models. These factories construct the model's canonical generated codec and copier using their generated constructor signatures; nested model dependencies retain the existing metadata-service resolution. Explicit context mode uses the complete finite dependency graph and validates each declared member shape. diff --git a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs index 1679d9a11bb..35f03eeb341 100644 --- a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs +++ b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs @@ -158,9 +158,19 @@ internal static ImmutableArray Generate( source.AppendLine("options.AddDefaultSerializerService(static provider => new ResponseFieldCodec());"); source.AppendLine("options.AddDefaultSerializerService(static provider => new ResponseFieldCopier());"); source.AppendLine("options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null!, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null!, provider));"); + source.AppendLine("options.AddDefaultSerializerService(static provider => new CompletedResponseActivator());"); + source.AppendLine("options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null!, provider)));"); + source.AppendLine("options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier());"); + source.AppendLine("options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null!, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null!, provider));"); + source.AppendLine("options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse));"); source.AppendLine("#endif"); source.AppendLine("}"); + source.AppendLine("private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator"); + source.AppendLine("{"); + source.AppendLine("public CompletedResponseActivator() { }"); + source.AppendLine("public global::Orleans.Serialization.Invocation.CompletedResponse Create() => global::Orleans.Serialization.Invocation.CompletedResponse.Instance;"); + source.AppendLine("}"); source.AppendLine("private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer"); source.AppendLine("{"); source.AppendLine("public ResponseFieldCodec() { }"); diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index cc79769dd78..ac6e567b047 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -2283,6 +2283,8 @@ public sealed class Payload Assert.Contains("options.AddDefaultSerializer", source); Assert.Contains("AbstractTypeSerializer", source); Assert.Contains("global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context)", source); + Assert.Contains("new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(", source); + Assert.Contains("Create() => global::Orleans.Serialization.Invocation.CompletedResponse.Instance", source); var outputCompilation = compilation.AddReferences(MetadataReference.CreateFromFile(typeof(Microsoft.Extensions.Options.IConfigureOptions<>).Assembly.Location)) .AddSyntaxTrees(result.GeneratedSources.Select(static source => CSharpSyntaxTree.ParseText(source.SourceText, options: new CSharpParseOptions().WithPreprocessorSymbols("NET5_0_OR_GREATER"), path: source.HintName))); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.verified.cs index 18943c92124..aa1bf3fdc7c 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.verified.cs @@ -266,9 +266,23 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); + options.AddDefaultSerializerService(static provider => new CompletedResponseActivator()); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); #endif } + private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator + { + public CompletedResponseActivator() + { + } + + public global::Orleans.Serialization.Invocation.CompletedResponse Create() => global::Orleans.Serialization.Invocation.CompletedResponse.Instance; + } + private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer { public ResponseFieldCodec() diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.verified.cs index 306d5be2f2b..6bf6c45e852 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.verified.cs @@ -174,9 +174,23 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); + options.AddDefaultSerializerService(static provider => new CompletedResponseActivator()); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); #endif } + private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator + { + public CompletedResponseActivator() + { + } + + public global::Orleans.Serialization.Invocation.CompletedResponse Create() => global::Orleans.Serialization.Invocation.CompletedResponse.Instance; + } + private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer { public ResponseFieldCodec() diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.verified.cs index 2b6ac662f44..b721d5ac06b 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.verified.cs @@ -467,9 +467,23 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); + options.AddDefaultSerializerService(static provider => new CompletedResponseActivator()); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); #endif } + private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator + { + public CompletedResponseActivator() + { + } + + public global::Orleans.Serialization.Invocation.CompletedResponse Create() => global::Orleans.Serialization.Invocation.CompletedResponse.Instance; + } + private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer { public ResponseFieldCodec() diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.verified.cs index 93a6b5cb7cf..dd42b6d4396 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.verified.cs @@ -271,9 +271,23 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); + options.AddDefaultSerializerService(static provider => new CompletedResponseActivator()); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); #endif } + private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator + { + public CompletedResponseActivator() + { + } + + public global::Orleans.Serialization.Invocation.CompletedResponse Create() => global::Orleans.Serialization.Invocation.CompletedResponse.Instance; + } + private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer { public ResponseFieldCodec() diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.verified.cs index e82aa9ee8f8..4766710ef07 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.verified.cs @@ -173,9 +173,23 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); + options.AddDefaultSerializerService(static provider => new CompletedResponseActivator()); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); #endif } + private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator + { + public CompletedResponseActivator() + { + } + + public global::Orleans.Serialization.Invocation.CompletedResponse Create() => global::Orleans.Serialization.Invocation.CompletedResponse.Instance; + } + private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer { public ResponseFieldCodec() diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.verified.cs index ac6c5520765..bd14a9a01cb 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.verified.cs @@ -792,9 +792,23 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); + options.AddDefaultSerializerService(static provider => new CompletedResponseActivator()); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); #endif } + private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator + { + public CompletedResponseActivator() + { + } + + public global::Orleans.Serialization.Invocation.CompletedResponse Create() => global::Orleans.Serialization.Invocation.CompletedResponse.Instance; + } + private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer { public ResponseFieldCodec() diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.verified.cs index 8deff7a33af..c2bdee693fa 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.verified.cs @@ -310,9 +310,23 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); + options.AddDefaultSerializerService(static provider => new CompletedResponseActivator()); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); #endif } + private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator + { + public CompletedResponseActivator() + { + } + + public global::Orleans.Serialization.Invocation.CompletedResponse Create() => global::Orleans.Serialization.Invocation.CompletedResponse.Instance; + } + private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer { public ResponseFieldCodec() diff --git a/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs b/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs index 8c3dc3146ef..016c8db3750 100644 --- a/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs +++ b/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs @@ -83,6 +83,13 @@ public static void CompletedAndExceptionResponses() Ensure(ReferenceEquals(Response.Completed, Copy(services, Response.Completed)), "Completed responses retain their singleton identity."); } + public static void CompletedResponseRoundTrip() + { + using var services = CreateServices(); + using var result = RoundTrip(services, Response.Completed); + Ensure(ReferenceEquals(Response.Completed, result), "Completed response transport restores the canonical singleton."); + } + public static void RawResponses() { using var services = CreateServices(); @@ -113,6 +120,25 @@ void Check(T value) } #if NATIVE_AOT_SMOKE + public static void ExceptionTransportRequiresDeclaredGraph() + { + using var services = CreateServices(); + using var exception = Response.FromException(new InvalidOperationException("response failure")); + try + { + using var result = RoundTrip(services, exception); + } + catch (NotSupportedException error) + { + Ensure(error.Message.Contains("ExceptionResponse", StringComparison.Ordinal) + && error.Message.Contains("exception and Data value types", StringComparison.Ordinal), + "Strict exception transport identifies its explicit codec graph contract."); + return; + } + + throw new InvalidOperationException("Strict exception transport requires its declared dependency graph."); + } + public static void MissingNativeResponseRegistration() { using var services = CreateServices(); diff --git a/test/Orleans.NativeAotSmoke/RpcResponses.cs b/test/Orleans.NativeAotSmoke/RpcResponses.cs index 741b0309f32..2c3c36065ff 100644 --- a/test/Orleans.NativeAotSmoke/RpcResponses.cs +++ b/test/Orleans.NativeAotSmoke/RpcResponses.cs @@ -5,6 +5,8 @@ RpcResponseContracts.ReferenceResponsePreservesCycles(); RpcResponseContracts.NullResponsePayload(); RpcResponseContracts.CompletedAndExceptionResponses(); +RpcResponseContracts.CompletedResponseRoundTrip(); +RpcResponseContracts.ExceptionTransportRequiresDeclaredGraph(); RpcResponseContracts.RawResponses(); RpcResponseContracts.MissingNativeResponseRegistration(); Console.WriteLine("Native Response dispatch passed: DeepCopier, bool, int, reference cycles, null, completion/exception identity, and raw message encoding."); diff --git a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs index cf0a59a6e0c..74cebaf854c 100644 --- a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs +++ b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs @@ -121,6 +121,25 @@ public void GeneratedResponseFactoriesPreserveCompletionAndExceptionIdentity() NativeAotSmoke.RpcResponseContracts.CompletedAndExceptionResponses(); } + [Fact] + public void GeneratedCompletedResponsesPreserveTransportIdentity() + => NativeAotSmoke.RpcResponseContracts.CompletedResponseRoundTrip(); + + [Fact] + public void ExplicitExceptionTransportRequiresDeclaredDependencyGraph() + { + using var services = new ServiceCollection().AddSerializerContext(new EmptyContext()).BuildServiceProvider(); + var error = Assert.Throws(() => services.GetRequiredService().GetCodec()); + Assert.Contains("ExceptionResponse", error.Message); + Assert.Contains("exception and Data value types", error.Message); + Assert.Contains("serializer context", error.Message); + } + + private sealed class EmptyContext : SerializerContext + { + protected override void ConfigureInner(TypeManifestOptions options) { } + } + [Fact] public void AutomaticResponseFactoriesPreserveCustomJitPayloadCopier() { From 2cb20a7e65b5f0ef8a66a15a7094da1a82d81621 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Thu, 1 Oct 2026 13:46:21 -0700 Subject: [PATCH 06/54] fix(codegen): emit factories for completion-only RPC contracts --- .../docs/implementation/serialization.md | 2 +- .../RpcResponseGenerator.cs | 12 ++++-- .../OrleansSourceGeneratorTests.cs | 37 +++++++++++++++++++ 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/docs/site/src/content/docs/implementation/serialization.md b/docs/site/src/content/docs/implementation/serialization.md index 8ffbc854ff8..387091d0bf8 100644 --- a/docs/site/src/content/docs/implementation/serialization.md +++ b/docs/site/src/content/docs/implementation/serialization.md @@ -137,7 +137,7 @@ For concrete `Task` and `ValueTask` method results, generated The graph also registers polymorphic codec and copier dispatch for the non-generic boundary used by the runtime client. That dispatch selects the closed implementation for the actual response type and preserves the identity of immutable completed and exception responses. The native smoke uses with `Response`, matching the runtime's response-copy boundary. -Completed response transport uses the existing generated codec and its canonical singleton activator, restoring after a round-trip. +Completed response transport uses the existing generated codec and its canonical singleton activator, restoring after a round-trip. Interfaces containing only non-generic `Task` or `ValueTask` methods also generate this shared response/completion graph. The finite strict response graph supplies successful typed results and completed-response transport, plus immutable exception-envelope copying. Exception transport in an explicit context requires an codec and the declared exception and `Data` value type graph. Lookup reports that registration contract when it is missing. Ordinary metadata mode retains the existing exception codecs and their serialization-constructor support. diff --git a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs index 35f03eeb341..dc427666504 100644 --- a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs +++ b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs @@ -34,6 +34,7 @@ internal static ImmutableArray Generate( var responseDefinition = compilation.GetTypeByMetadataName("Orleans.Serialization.Invocation.Response`1")!; var resolver = new TypeSymbolResolver(compilation); var results = new Dictionary(SymbolEqualityComparer.Default); + var hasCompletionMethods = false; var output = ImmutableArray.CreateBuilder(); foreach (var proxy in proxies) { @@ -48,10 +49,15 @@ internal static ImmutableArray Generate( .Where(static method => method.MethodKind == MethodKind.Ordinary)) { var returnType = method.ReturnType; - if (returnType.SpecialType == SpecialType.System_Void - || SymbolEqualityComparer.Default.Equals(returnType, services.LibraryTypes.Task) + if (returnType.SpecialType == SpecialType.System_Void) + { + continue; + } + + if (SymbolEqualityComparer.Default.Equals(returnType, services.LibraryTypes.Task) || SymbolEqualityComparer.Default.Equals(returnType, services.LibraryTypes.ValueTask)) { + hasCompletionMethods = true; continue; } @@ -109,7 +115,7 @@ internal static ImmutableArray Generate( } } - if (supportedResults.Count == 0 && metadataModelRoots.Count == 0) + if (supportedResults.Count == 0 && metadataModelRoots.Count == 0 && !hasCompletionMethods) { return output.ToImmutable(); } diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index ac6e567b047..0e9ffe7de31 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -2365,6 +2365,43 @@ public sealed class Payload Assert.Contains(strict.Diagnostics, static diagnostic => diagnostic.Id == "ORLEANS0116"); } + [Theory] + [InlineData("Task")] + [InlineData("ValueTask")] + public async Task RpcResponseFactoriesGenerateCompletionOnlyContracts(string returnType) + { + var compilation = await CreateCompilation($$""" + using Orleans; + using System.Threading.Tasks; + namespace TestProject; + public interface ICompletion : IGrainWithIntegerKey { {{returnType}} Done(); } + """); + var result = RunSourceGenerator(compilation, new Dictionary { ["build_property.publishaot"] = "true" }); + Assert.Empty(result.Diagnostics); + var source = Assert.Single(result.GeneratedSources, static item => item.HintName.EndsWith(".orleans.rpcresponses.g.cs", StringComparison.Ordinal)).SourceText.ToString(); + Assert.Contains("options.AddDefaultSerializer", source); + Assert.Contains("options.AddDefaultSerializer", source); + Assert.Contains("Codec_CompletedResponse", source); + Assert.DoesNotContain("PooledResponseCodec<", source); + var output = compilation.AddReferences(MetadataReference.CreateFromFile(typeof(Microsoft.Extensions.Options.IConfigureOptions<>).Assembly.Location)) + .AddSyntaxTrees(result.GeneratedSources.Select(static item => CSharpSyntaxTree.ParseText(item.SourceText, + options: new CSharpParseOptions().WithPreprocessorSymbols("NET5_0_OR_GREATER"), path: item.HintName))); + Assert.Empty(output.GetDiagnostics(TestContext.Current.CancellationToken).Where(static diagnostic => diagnostic.Severity == DiagnosticSeverity.Error)); + } + + [Fact] + public async Task RpcResponseFactoriesLeaveOneWayContractsWithoutResponses() + { + var compilation = await CreateCompilation(""" + using Orleans; + namespace TestProject; + public interface IOneWay : IGrainWithIntegerKey { void Send(); } + """); + var result = RunSourceGenerator(compilation, new Dictionary { ["build_property.publishaot"] = "true" }); + Assert.Empty(result.Diagnostics); + Assert.DoesNotContain(result.GeneratedSources, static item => item.HintName.EndsWith(".orleans.rpcresponses.g.cs", StringComparison.Ordinal)); + } + [Fact] public async Task RpcResponseFactoriesPreserveGenericJitGenerationAndExplicitValidationOverride() { From 67683c02500e1ac3fa9c8c55d1d57d604abc6582 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Thu, 1 Oct 2026 16:47:09 -0700 Subject: [PATCH 07/54] fix(serialization): preserve referenced factory contracts and alias prefixes --- .../TypeSystem/CompoundTypeAliasTree.cs | 2 +- .../OrleansSourceGeneratorTests.cs | 40 +++++++++++++++++++ .../RpcResponseTests.cs | 11 +++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/Orleans.Serialization/TypeSystem/CompoundTypeAliasTree.cs b/src/Orleans.Serialization/TypeSystem/CompoundTypeAliasTree.cs index c1c370feac4..13650d7f3ba 100644 --- a/src/Orleans.Serialization/TypeSystem/CompoundTypeAliasTree.cs +++ b/src/Orleans.Serialization/TypeSystem/CompoundTypeAliasTree.cs @@ -116,7 +116,7 @@ private CompoundTypeAliasTree AddInternal(object key, Type? value) return existing; } - existing.Value = value; + existing.Value = value ?? existing.Value; return existing; } else diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index 0e9ffe7de31..1b39b31fda8 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -2402,6 +2402,46 @@ public interface IOneWay : IGrainWithIntegerKey { void Send(); } Assert.DoesNotContain(result.GeneratedSources, static item => item.HintName.EndsWith(".orleans.rpcresponses.g.cs", StringComparison.Ordinal)); } + [Fact] + public async Task RpcResponseFactoriesUseReferencedHotReloadConstructorContracts() + { + var library = await CreateCompilation(""" + using Orleans; + namespace ReferencedResults; + [GenerateSerializer] + public sealed class Payload { [Id(0)] public int Value { get; set; } } + """, "ReferencedResults"); + var generated = RunSourceGenerator(library, new Dictionary { ["build_property.orleanshotreload"] = "true" }); + Assert.Empty(generated.Diagnostics); + library = library.AddReferences(MetadataReference.CreateFromFile(typeof(Microsoft.Extensions.Options.IConfigureOptions<>).Assembly.Location)) + .AddSyntaxTrees(generated.GeneratedSources.Select(static item => CSharpSyntaxTree.ParseText(item.SourceText, path: item.HintName))); + using var image = new System.IO.MemoryStream(); + var emit = library.Emit(image, cancellationToken: TestContext.Current.CancellationToken); + Assert.True(emit.Success, string.Join(Environment.NewLine, emit.Diagnostics)); + + var consumer = (await CreateCompilation("namespace Consumer { }", "Consumer")) + .AddReferences(MetadataReference.CreateFromImage(image.ToArray())) + .AddReferences(MetadataReference.CreateFromFile(typeof(Microsoft.Extensions.Options.IConfigureOptions<>).Assembly.Location)); + var payload = consumer.GetTypeByMetadataName("ReferencedResults.Payload"); + Assert.NotNull(payload); + var services = new GeneratorServices(consumer, new CodeGeneratorOptions { HotReloadSafe = false }); + Assert.True(SerializerFactoryGenerator.TryCreate(services, [payload], TestContext.Current.CancellationToken, out var graph, out var failure), failure?.Reason); + Assert.NotNull(graph); + Assert.Contains("new global::OrleansCodeGen.ReferencedResults.Codec_Payload(provider)", graph.ConfigurationStatements); + + var contextSource = $$""" + public sealed class ConsumerContext : Orleans.Serialization.SerializerContext + { + protected override void ConfigureInner(Orleans.Serialization.Configuration.TypeManifestOptions options) + { + {{graph.ConfigurationStatements}} + } + } + """; + var output = consumer.AddSyntaxTrees(CSharpSyntaxTree.ParseText(contextSource, cancellationToken: TestContext.Current.CancellationToken)); + Assert.Empty(output.GetDiagnostics(TestContext.Current.CancellationToken).Where(static item => item.Severity == DiagnosticSeverity.Error)); + } + [Fact] public async Task RpcResponseFactoriesPreserveGenericJitGenerationAndExplicitValidationOverride() { diff --git a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs index 74cebaf854c..a461338e1e1 100644 --- a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs +++ b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs @@ -140,6 +140,17 @@ private sealed class EmptyContext : SerializerContext protected override void ConfigureInner(TypeManifestOptions options) { } } + [Fact] + public void CompoundAliasPrefixSurvivesChildRegistration() + { + var tree = Orleans.Serialization.TypeSystem.CompoundTypeAliasTree.Create(); + var prefix = tree.Add("rpc.prefix", typeof(int)); + var child = tree.Add("rpc.prefix").Add("child", typeof(string)); + Assert.Same(prefix, tree.Add("rpc.prefix")); + Assert.Equal(typeof(int), prefix.Value); + Assert.Equal(typeof(string), child.Value); + } + [Fact] public void AutomaticResponseFactoriesPreserveCustomJitPayloadCopier() { From 2c97b7750023a9fdcd664dcab84182595ec78570 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Thu, 1 Oct 2026 16:51:35 -0700 Subject: [PATCH 08/54] fix(codegen): generate response factories for instance RPC methods --- .../RpcResponseGenerator.cs | 4 +- .../OrleansSourceGeneratorTests.cs | 43 +++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs index dc427666504..22cb111cc9e 100644 --- a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs +++ b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs @@ -44,8 +44,8 @@ internal static ImmutableArray Generate( continue; } - foreach (var method in interfaceType.GetMembers().OfType() - .Concat(interfaceType.AllInterfaces.SelectMany(static type => type.GetMembers().OfType())) + foreach (var method in interfaceType.GetDeclaredInstanceMembers() + .Concat(interfaceType.AllInterfaces.SelectMany(static type => type.GetDeclaredInstanceMembers())) .Where(static method => method.MethodKind == MethodKind.Ordinary)) { var returnType = method.ReturnType; diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index 1b39b31fda8..9718c3a334c 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -2442,6 +2442,49 @@ protected override void ConfigureInner(Orleans.Serialization.Configuration.TypeM Assert.Empty(output.GetDiagnostics(TestContext.Current.CancellationToken).Where(static item => item.Severity == DiagnosticSeverity.Error)); } + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task RpcResponseFactoriesIgnoreStaticInterfaceHelpers(bool hasInstanceMethod) + { + var instanceMethod = hasInstanceMethod ? "Task Invoke();" : ""; + var compilation = await CreateCompilation($$""" + using Orleans; + using System.Threading.Tasks; + namespace TestProject; + public interface IHelpers : IGrainWithIntegerKey + { + static Task SupportedHelper() => Task.FromResult("local"); + static Task UnsupportedHelper() => Task.FromResult(new object()); + static Task GenericHelper(T value) => Task.FromResult(value); + static Task CompletionHelper() => Task.CompletedTask; + } + public interface IContract : IHelpers + { + static ValueTask LocalHelper() => ValueTask.FromResult(true); + {{instanceMethod}} + } + """); + var result = RunSourceGenerator(compilation, new Dictionary { ["build_property.publishaot"] = "true" }); + Assert.Empty(result.Diagnostics); + var factories = result.GeneratedSources.Where(static item => item.HintName.EndsWith(".orleans.rpcresponses.g.cs", StringComparison.Ordinal)).ToArray(); + if (!hasInstanceMethod) + { + Assert.Empty(factories); + return; + } + + var source = Assert.Single(factories).SourceText.ToString(); + Assert.Contains("Response", source); + Assert.DoesNotContain("Response", source); + Assert.DoesNotContain("Response", source); + Assert.DoesNotContain("Response", source); + var output = compilation.AddReferences(MetadataReference.CreateFromFile(typeof(Microsoft.Extensions.Options.IConfigureOptions<>).Assembly.Location)) + .AddSyntaxTrees(result.GeneratedSources.Select(static item => CSharpSyntaxTree.ParseText(item.SourceText, + options: new CSharpParseOptions().WithPreprocessorSymbols("NET5_0_OR_GREATER"), path: item.HintName))); + Assert.Empty(output.GetDiagnostics(TestContext.Current.CancellationToken).Where(static item => item.Severity == DiagnosticSeverity.Error)); + } + [Fact] public async Task RpcResponseFactoriesPreserveGenericJitGenerationAndExplicitValidationOverride() { From 16b18d21d37065cd91754c548f8d9d94406e65ba Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Fri, 2 Oct 2026 00:49:01 -0700 Subject: [PATCH 09/54] fix(serialization): preserve complete alias metadata and legacy traversal --- .../TypeSystem/CompoundTypeAliasTree.cs | 2 +- .../OrleansSourceGeneratorTests.cs | 79 +++++++++++++++++++ .../RpcResponseTests.cs | 54 ++++++++++++- 3 files changed, 131 insertions(+), 4 deletions(-) diff --git a/src/Orleans.Serialization/TypeSystem/CompoundTypeAliasTree.cs b/src/Orleans.Serialization/TypeSystem/CompoundTypeAliasTree.cs index 13650d7f3ba..c1c370feac4 100644 --- a/src/Orleans.Serialization/TypeSystem/CompoundTypeAliasTree.cs +++ b/src/Orleans.Serialization/TypeSystem/CompoundTypeAliasTree.cs @@ -116,7 +116,7 @@ private CompoundTypeAliasTree AddInternal(object key, Type? value) return existing; } - existing.Value = value ?? existing.Value; + existing.Value = value; return existing; } else diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index 9718c3a334c..1fcd264ccee 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -2485,6 +2485,85 @@ public interface IContract : IHelpers Assert.Empty(output.GetDiagnostics(TestContext.Current.CancellationToken).Where(static item => item.Severity == DiagnosticSeverity.Error)); } + [Fact] + public async Task RpcResponseFactoriesPreserveAllAliasesAndMetadataOnlyComponents() + { + var compilation = await CreateCompilation(""" + using Orleans; + using System.Threading.Tasks; + namespace TestProject; + [CompoundTypeAlias("rpc.marker")] + public sealed class Marker { } + [GenerateSerializer, CompoundTypeAlias("rpc.multiple", "2"), CompoundTypeAlias("rpc.multiple", "1")] + public sealed class Payload { [Id(0)] public int Value { get; set; } } + [GenerateSerializer, CompoundTypeAlias(typeof(Marker), "payload")] + public sealed class NestedPayload { [Id(0)] public int Value { get; set; } } + public interface IAliases : IGrainWithIntegerKey + { + Task Multiple(); + Task Nested(); + } + """); + var generated = RunSourceGenerator(compilation, new Dictionary { ["build_property.publishaot"] = "true" }); + Assert.Empty(generated.Diagnostics); + var metadata = Assert.Single(generated.GeneratedSources, static item => item.HintName.EndsWith(".orleans.metadata.g.cs", StringComparison.Ordinal)).SourceText.ToString(); + Assert.Contains("GetOrAdd(\"rpc.multiple\")", metadata); + Assert.Contains(".Add(\"1\", typeof(global::TestProject.Payload))", metadata); + Assert.Contains(".Add(\"2\", typeof(global::TestProject.Payload))", metadata); + + var services = new GeneratorServices(compilation, new CodeGeneratorOptions()); + var multiple = compilation.GetTypeByMetadataName("TestProject.Payload"); + var nested = compilation.GetTypeByMetadataName("TestProject.NestedPayload"); + Assert.NotNull(multiple); + Assert.NotNull(nested); + Assert.True(SerializerFactoryGenerator.TryCreate(services, [multiple, nested], TestContext.Current.CancellationToken, out var graph, out var failure), failure?.Reason); + Assert.NotNull(graph); + Assert.Contains("GetOrAdd(\"rpc.multiple\").Add(\"2\", typeof(global::TestProject.Payload))", graph.ConfigurationStatements); + Assert.Contains("GetOrAdd(\"rpc.multiple\").Add(\"1\", typeof(global::TestProject.Payload))", graph.ConfigurationStatements); + Assert.Contains("options.CompoundTypeAliases.Add(\"rpc.marker\", typeof(global::TestProject.Marker))", graph.ConfigurationStatements); + Assert.Contains("options.CompoundTypeAliases.GetOrAdd(typeof(global::TestProject.Marker)).Add(\"payload\"", graph.ConfigurationStatements); + Assert.DoesNotContain(graph.Registrations.Keys, static type => type.Name == "Marker"); + Assert.Equal(1, CountOccurrences(graph.ConfigurationStatements, "options.CompoundTypeAliases.Add(\"rpc.marker\"")); + + var contextSource = $$""" + public sealed class AliasContext : Orleans.Serialization.SerializerContext + { + protected override void ConfigureInner(Orleans.Serialization.Configuration.TypeManifestOptions options) + { + {{graph.ConfigurationStatements}} + } + } + """; + var output = compilation.AddReferences(MetadataReference.CreateFromFile(typeof(Microsoft.Extensions.Options.IConfigureOptions<>).Assembly.Location)) + .AddSyntaxTrees(generated.GeneratedSources.Select(static item => CSharpSyntaxTree.ParseText(item.SourceText, + options: new CSharpParseOptions().WithPreprocessorSymbols("NET5_0_OR_GREATER"), path: item.HintName))) + .AddSyntaxTrees(CSharpSyntaxTree.ParseText(contextSource, cancellationToken: TestContext.Current.CancellationToken)); + Assert.Empty(output.GetDiagnostics(TestContext.Current.CancellationToken).Where(static item => item.Severity == DiagnosticSeverity.Error)); + } + + [Fact] + public async Task RpcResponseFactoriesVisitRecursiveAliasMetadataOnce() + { + var compilation = await CreateCompilation(""" + using Orleans; + namespace TestProject; + [CompoundTypeAlias(typeof(SecondMarker), "first")] + public sealed class FirstMarker { } + [CompoundTypeAlias(typeof(FirstMarker), "second")] + public sealed class SecondMarker { } + [GenerateSerializer, CompoundTypeAlias(typeof(FirstMarker), "payload")] + public sealed class Payload { [Id(0)] public int Value { get; set; } } + """); + var payload = compilation.GetTypeByMetadataName("TestProject.Payload"); + Assert.NotNull(payload); + Assert.True(SerializerFactoryGenerator.TryCreate(new GeneratorServices(compilation, new CodeGeneratorOptions()), + [payload], TestContext.Current.CancellationToken, out var graph, out var failure), failure?.Reason); + Assert.NotNull(graph); + Assert.Equal(1, CountOccurrences(graph.ConfigurationStatements, ".Add(\"first\", typeof(global::TestProject.FirstMarker))")); + Assert.Equal(1, CountOccurrences(graph.ConfigurationStatements, ".Add(\"second\", typeof(global::TestProject.SecondMarker))")); + Assert.DoesNotContain(graph.Registrations.Keys, static type => type.Name.EndsWith("Marker", StringComparison.Ordinal)); + } + [Fact] public async Task RpcResponseFactoriesPreserveGenericJitGenerationAndExplicitValidationOverride() { diff --git a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs index a461338e1e1..8f1082d4020 100644 --- a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs +++ b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs @@ -141,14 +141,45 @@ protected override void ConfigureInner(TypeManifestOptions options) { } } [Fact] - public void CompoundAliasPrefixSurvivesChildRegistration() + public void CompoundAliasTraversalPreservesPrefixesAndAddClearsThem() { var tree = Orleans.Serialization.TypeSystem.CompoundTypeAliasTree.Create(); var prefix = tree.Add("rpc.prefix", typeof(int)); - var child = tree.Add("rpc.prefix").Add("child", typeof(string)); - Assert.Same(prefix, tree.Add("rpc.prefix")); + var child = tree.GetOrAdd("rpc.prefix").Add("child", typeof(string)); + Assert.Same(prefix, tree.GetOrAdd("rpc.prefix")); Assert.Equal(typeof(int), prefix.Value); Assert.Equal(typeof(string), child.Value); + tree.Add("rpc.prefix"); + Assert.Null(prefix.Value); + tree.Add("rpc.prefix", typeof(long)); + Assert.Equal(typeof(long), tree.GetOrAdd("rpc.prefix").Value); + + var typePrefix = tree.Add(typeof(RpcResponseTests), typeof(int)); + Assert.Same(typePrefix, tree.GetOrAdd(typeof(RpcResponseTests))); + Assert.Equal(typeof(int), typePrefix.Value); + tree.Add(typeof(RpcResponseTests)); + Assert.Null(typePrefix.Value); + tree.Add(typeof(RpcResponseTests), typeof(long)); + Assert.Equal(typeof(long), tree.GetOrAdd(typeof(RpcResponseTests)).Value); + } + + [Fact] + public void CompoundResponseAliasesResolveAndRoundTrip() + { + var converter = _services.GetRequiredService(); + Assert.Equal(typeof(RpcMultipleAliasPayload), converter.Parse("(\"rpc.response.multiple\",\"2\")")); + Assert.Equal(typeof(RpcMultipleAliasPayload), converter.Parse("(\"rpc.response.multiple\",\"1\")")); + var serializer = _services.GetRequiredService(); + var multiple = new List { new() { Value = 79 } }; + var result = serializer.Deserialize>(serializer.SerializeToArray(multiple)); + Assert.NotNull(result); + Assert.Single(result); + Assert.Equal(79, result[0].Value); + var nested = new List { new() { Value = 89 } }; + var nestedResult = serializer.Deserialize>(serializer.SerializeToArray(nested)); + Assert.NotNull(nestedResult); + Assert.Single(nestedResult); + Assert.Equal(89, nestedResult[0].Value); } [Fact] @@ -166,6 +197,23 @@ public void AutomaticResponseFactoriesPreserveCustomJitPayloadCopier() services.GetRequiredService().GetDeepCopier(response.GetType())); } + [GenerateSerializer, CompoundTypeAlias("rpc.response.multiple", "2"), CompoundTypeAlias("rpc.response.multiple", "1")] + public sealed class RpcMultipleAliasPayload + { + [Id(0)] + public int Value { get; set; } + } + + [CompoundTypeAlias("rpc.response.marker")] + public sealed class RpcAliasMarker { } + + [GenerateSerializer, CompoundTypeAlias(typeof(RpcAliasMarker), "payload")] + public sealed class RpcNestedAliasPayload + { + [Id(0)] + public int Value { get; set; } + } + [Fact] public void LegacyJitDictionaryResponsesPreserveCustomComparers() { From da69737ce6b49e9595f2aedaef37c679aa2c0106 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Fri, 2 Oct 2026 01:47:00 -0700 Subject: [PATCH 10/54] fix(codegen): close canonical response model construction dependencies --- .../docs/implementation/serialization.md | 2 +- .../SerializableSourceOutputGenerator.cs | 9 +- .../SerializerFactoryGenerator.cs | 111 +++++++++++- .../OrleansGeneratedCodeHelper.cs | 22 +++ .../Orleans.Serialization.cs | 6 + .../OrleansSourceGeneratorTests.cs | 159 ++++++++++++++++++ 6 files changed, 302 insertions(+), 7 deletions(-) diff --git a/docs/site/src/content/docs/implementation/serialization.md b/docs/site/src/content/docs/implementation/serialization.md index 387091d0bf8..0caf5b47759 100644 --- a/docs/site/src/content/docs/implementation/serialization.md +++ b/docs/site/src/content/docs/implementation/serialization.md @@ -143,7 +143,7 @@ The finite strict response graph supplies successful typed results and completed These supplemental registrations are defaults: explicit closed factory registrations take precedence in either configuration order. The automatic provider activates when runtime code generation is unavailable. JIT execution continues to use the existing serializer and copier selection, including application-provided payload implementations. Explicit factory and context registration also works in JIT execution. -Ordinary metadata mode also supplies static response factories for non-generic generated result models. These factories construct the model's canonical generated codec and copier using their generated constructor signatures; nested model dependencies retain the existing metadata-service resolution. Explicit context mode uses the complete finite dependency graph and validates each declared member shape. +Ordinary metadata mode also supplies static response factories for non-generic generated result models. These factories construct the model's canonical generated codec and copier using their generated constructor signatures. Construction dependencies include the selected activator and declared codec/copier service contracts; source-known finite dependencies use closed factories, while interface contracts use ordinary metadata dispatch. This keeps construction within the provider's publication boundary and preserves canonical service identity and rollback. Default activation uses the existing reference- or value-type activator implementation, and custom activation retains its declared contract. Explicit context mode uses the complete finite dependency graph and validates each declared member shape. `OrleansValidateRpcResponseFactories` enables compile-time validation of the response graph and defaults to the executable project's `PublishAot` setting. Diagnostic `ORLEANS0116` identifies an unresolved generic result, a custom return adapter requiring an explicit response contract, or a result dependency outside the supported finite graph. Applications with runtime-selected generic results register every permitted closed graph explicitly through and in a , and set `OrleansValidateRpcResponseFactories=false` for the project supplying that contract. A missing native response registration reports the closed response type and registration guidance at lookup. diff --git a/src/Orleans.CodeGenerator/SerializableSourceOutputGenerator.cs b/src/Orleans.CodeGenerator/SerializableSourceOutputGenerator.cs index 5aeff5283ec..0782c68dd06 100644 --- a/src/Orleans.CodeGenerator/SerializableSourceOutputGenerator.cs +++ b/src/Orleans.CodeGenerator/SerializableSourceOutputGenerator.cs @@ -245,10 +245,10 @@ internal static SourceOutputResult CreateSerializableSourceOutput( typeDescription.GeneratedNamespace)); } - internal static ISerializableTypeDescription? CreateSerializableTypeDescription(IGeneratorServices services, INamedTypeSymbol symbol) - => CreateSerializableTypeDescription(services.Compilation, services.LibraryTypes, services.Options, symbol); + internal static ISerializableTypeDescription? CreateSerializableTypeDescription(IGeneratorServices services, INamedTypeSymbol symbol, bool inspectReferenceMetadata = false) + => CreateSerializableTypeDescription(services.Compilation, services.LibraryTypes, services.Options, symbol, inspectReferenceMetadata); - internal static ISerializableTypeDescription? CreateSerializableTypeDescription(Compilation compilation, LibraryTypes libraryTypes, CodeGeneratorOptions options, INamedTypeSymbol symbol) + internal static ISerializableTypeDescription? CreateSerializableTypeDescription(Compilation compilation, LibraryTypes libraryTypes, CodeGeneratorOptions options, INamedTypeSymbol symbol, bool inspectReferenceMetadata = false) { if (FSharpUtilities.IsUnionCase(libraryTypes, symbol, out var sumType) && sumType.HasAttribute(libraryTypes.GenerateSerializerAttribute)) @@ -266,7 +266,7 @@ internal static SourceOutputResult CreateSerializableSourceOutput( return null; } - if (HasReferenceAssemblyAttribute(symbol.ContainingAssembly)) + if (!inspectReferenceMetadata && HasReferenceAssemblyAttribute(symbol.ContainingAssembly)) { throw new OrleansGeneratorDiagnosticAnalysisException(ReferenceAssemblyWithGenerateSerializerDiagnostic.CreateDiagnostic(symbol)); } @@ -469,4 +469,3 @@ internal static bool IsCurrentCompilationAssembly(TypeMetadataIdentity metadataI } } - diff --git a/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs b/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs index 0002a7dbb50..77c17d2092c 100644 --- a/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs +++ b/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs @@ -36,21 +36,37 @@ internal sealed record Failure(ITypeSymbol Type, string Reason); IGeneratorServices services, INamedTypeSymbol type, CancellationToken cancellationToken) + => CreateRpcModelRoot(services, type, cancellationToken, new HashSet(SymbolEqualityComparer.Default), includeResponse: true); + + private static Graph? CreateRpcModelRoot( + IGeneratorServices services, + INamedTypeSymbol type, + CancellationToken cancellationToken, + HashSet constructionTypes, + bool includeResponse) { cancellationToken.ThrowIfCancellationRequested(); - if (type.IsGenericType || type.IsAbstract || type.TypeKind == TypeKind.Interface + if (!constructionTypes.Add(type) || type.IsGenericType || type.IsAbstract || type.TypeKind == TypeKind.Interface || !type.HasAttribute(services.LibraryTypes.GenerateSerializerAttribute)) { return null; } var registration = new Registration(type); + var constructionModel = SerializableSourceOutputGenerator.CreateSerializableTypeDescription(services, type, inspectReferenceMetadata: true); + if (constructionModel is null) + { + return null; + } + + var requiresActivator = false; if (SymbolEqualityComparer.Default.Equals(type.ContainingAssembly, services.Compilation.Assembly)) { var model = SerializableSourceOutputGenerator.CreateSerializableTypeDescription(services, type); if (model is null) return null; DescribeGeneratedModel(registration, type, model); ConstructGeneratedModel(registration, services); + requiresActivator = model.UseActivator; } else { @@ -59,6 +75,7 @@ internal sealed record Failure(ITypeSymbol Type, string Reason); if (codecType is null) return null; registration.Codec = Name(codecType); registration.CodecConstruction = ConstructReferenced(registration.Codec, codecType); + requiresActivator = HasActivatorDependency(codecType); if (services.LibraryTypes.IsShallowCopyable(type)) { registration.Copier = $"global::Orleans.Serialization.Cloning.ShallowCopier<{Name(type)}>"; @@ -70,6 +87,7 @@ internal sealed record Failure(ITypeSymbol Type, string Reason); if (copierType is null) return null; registration.Copier = Name(copierType); registration.CopierConstruction = ConstructReferenced(registration.Copier, copierType); + requiresActivator |= HasActivatorDependency(copierType); } } @@ -77,10 +95,41 @@ internal sealed record Failure(ITypeSymbol Type, string Reason); var codec = $"global::Orleans.Serialization.Invocation.PooledResponseCodec<{Name(type)}, {registration.Codec}>"; var copier = $"global::Orleans.Serialization.Invocation.PooledResponseCopier<{Name(type)}, {registration.Copier}>"; var result = new StringBuilder(); + foreach (var memberType in constructionModel.Members + .Where(static member => member.IsSerializable || member.IsCopyable) + .Select(static member => member.Type) + .Distinct(SymbolEqualityComparer.Default)) + { + AppendConstructionDependency(memberType); + } + + if (requiresActivator && constructionModel.HasActivatorConstructor + && SymbolEqualityComparer.Default.Equals(type.ContainingAssembly, services.Compilation.Assembly)) + { + var activatorName = $"global::{constructionModel.GeneratedNamespace}.{ActivatorGenerator.GetSimpleClassName(constructionModel)}"; + var activator = new ActivatorGenerator(services).GenerateActivator(constructionModel); + result.Append("options.AddDefaultSerializerService>(static provider => ") + .Append(ConstructGenerated(activatorName, activator)).AppendLine(");"); + } + else if (requiresActivator && !type.HasAttribute(services.LibraryTypes.UseActivatorAttribute) + && !constructionModel.HasActivatorConstructor) + { + var factory = type.IsValueType ? "CreateDefaultValueTypeActivator" : "CreateDefaultReferenceTypeActivator"; + result.Append("options.AddDefaultSerializerService>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.") + .Append(factory).Append('<').Append(Name(type)).AppendLine(">());"); + } + result.Append("options.AddDefaultSerializerService<").Append(registration.Codec).Append(">(static provider => ") .Append(registration.CodecConstruction).AppendLine(");"); result.Append("options.AddDefaultSerializerService<").Append(registration.Copier).Append(">(static provider => ") .Append(registration.CopierConstruction).AppendLine(");"); + if (!includeResponse) + { + return new Graph(new Dictionary(SymbolEqualityComparer.Default) { [type] = registration }, result.ToString()); + } + result.Append("options.AddDefaultSerializerService<").Append(codec).Append(">(static provider => new ") .Append(codec).Append("(caller => ").Append(Resolve(registration.Codec, "caller")).AppendLine("));"); result.Append("options.AddDefaultSerializerService<").Append(copier).Append(">(static provider => new ") @@ -89,6 +138,66 @@ internal sealed record Failure(ITypeSymbol Type, string Reason); .Append(Resolve(codec)).Append(", static provider => ").Append(Resolve(copier)).AppendLine(");"); result.Append("options.AddAllowedType(typeof(").Append(Name(responseType)).AppendLine("));"); return new Graph(new Dictionary(SymbolEqualityComparer.Default) { [type] = registration }, result.ToString()); + + bool HasActivatorDependency(INamedTypeSymbol implementation) + => implementation.InstanceConstructors.SelectMany(static constructor => constructor.Parameters) + .Any(parameter => parameter.Type is INamedTypeSymbol dependency + && SymbolEqualityComparer.Default.Equals(dependency.OriginalDefinition, services.LibraryTypes.IActivator_1) + && SymbolEqualityComparer.Default.Equals(dependency.TypeArguments[0], type)); + + void AppendConstructionDependency(ITypeSymbol dependency) + { + dependency = dependency.WithNullableAnnotation(NullableAnnotation.None); + if (constructionTypes.Contains(dependency)) return; + if (TryCreate(services, [dependency], cancellationToken, out var finite, out _, useDefaultFactories: true) + && !finite.Registrations.Keys.OfType().Any(named => + SymbolEqualityComparer.Default.Equals(named.OriginalDefinition, services.Compilation.GetTypeByMetadataName("System.Collections.Generic.Dictionary`2")))) + { + foreach (var registered in finite.Registrations.Keys) constructionTypes.Add(registered); + result.AppendLine(finite.ConfigurationStatements); + return; + } + + if (dependency is INamedTypeSymbol modelType && modelType.HasAttribute(services.LibraryTypes.GenerateSerializerAttribute) + && CreateRpcModelRoot(services, modelType, cancellationToken, constructionTypes, includeResponse: false) is { } modelGraph) + { + result.AppendLine(modelGraph.ConfigurationStatements); + } + else + { + constructionTypes.Add(dependency); + } + + var name = Name(dependency); + // Metadata bridges add service contracts, while type dispatch stays with ordinary metadata. + result.Append("options.AddDefaultSerializerService>(static provider => provider.GetCodec<").Append(name).AppendLine(">());"); + result.Append("options.AddDefaultSerializerService>(static provider => provider.GetDeepCopier<").Append(name).AppendLine(">());"); + if (dependency is INamedTypeSymbol named) + { + foreach (var argument in named.TypeArguments) AppendConstructionDependency(argument); + if (services.LibraryTypes.WellKnownCodecs.FindByUnderlyingType(named.OriginalDefinition) is { } knownCodec + && knownCodec.CodecType.IsGenericType) + { + var codec = knownCodec.CodecType.Construct([.. named.TypeArguments]); + foreach (var parameter in codec.InstanceConstructors.SelectMany(static constructor => constructor.Parameters)) + { + if (parameter.Type is INamedTypeSymbol service + && (SymbolEqualityComparer.Default.Equals(service.OriginalDefinition, services.LibraryTypes.FieldCodec_1) + || SymbolEqualityComparer.Default.Equals(service.OriginalDefinition, services.LibraryTypes.DeepCopier_1))) + { + AppendConstructionDependency(service.TypeArguments[0]); + } + } + } + } + else if (dependency is IArrayTypeSymbol array) + { + AppendConstructionDependency(array.ElementType); + } + } + } internal static bool TryCreate( diff --git a/src/Orleans.Serialization/GeneratedCodeHelpers/OrleansGeneratedCodeHelper.cs b/src/Orleans.Serialization/GeneratedCodeHelpers/OrleansGeneratedCodeHelper.cs index 53c00627dc0..421f1570255 100644 --- a/src/Orleans.Serialization/GeneratedCodeHelpers/OrleansGeneratedCodeHelper.cs +++ b/src/Orleans.Serialization/GeneratedCodeHelpers/OrleansGeneratedCodeHelper.cs @@ -21,6 +21,28 @@ namespace Orleans.Serialization.GeneratedCodeHelpers /// public static class OrleansGeneratedCodeHelper { + /// + /// Creates the default activator for a statically specified reference type. + /// + /// The reference type to activate. + /// The default reference-type activator. + public static IActivator CreateDefaultReferenceTypeActivator< +#if NET5_0_OR_GREATER + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] +#endif + T>() where T : class => new DefaultReferenceTypeActivator(); + + /// + /// Creates the default activator for a statically specified value type. + /// + /// The value type to activate. + /// The default value-type activator. + public static IActivator CreateDefaultValueTypeActivator< +#if NET5_0_OR_GREATER + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] +#endif + T>() where T : struct => new DefaultValueTypeActivator(); + private static readonly ThreadLocal ResolutionState = new ThreadLocal(() => new RecursiveServiceResolutionState()); internal static void EnterServiceResolution(ICodecProvider provider, CodecProvider.ConstructionScope scope) diff --git a/src/api/Orleans.Serialization/Orleans.Serialization.cs b/src/api/Orleans.Serialization/Orleans.Serialization.cs index 8a97d49dcc8..3c9837841ef 100644 --- a/src/api/Orleans.Serialization/Orleans.Serialization.cs +++ b/src/api/Orleans.Serialization/Orleans.Serialization.cs @@ -3485,6 +3485,12 @@ public static void ConsumeEndBaseOrEndObject(this ref Buffers.Reader(this ref Buffers.Reader reader) { } + public static Activators.IActivator CreateDefaultReferenceTypeActivator() + where T : class { throw null; } + + public static Activators.IActivator CreateDefaultValueTypeActivator() + where T : struct { throw null; } + public static TField DeserializeUnexpectedType(this ref Buffers.Reader reader, scoped ref WireProtocol.Field field) where TField : class { throw null; } diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index 1fcd264ccee..af48487c5ee 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -2356,6 +2356,8 @@ public sealed class Payload Assert.Contains("new global::OrleansCodeGen.TestProject.Codec_Payload(", source); Assert.Contains("new global::OrleansCodeGen.TestProject.Copier_Payload(", source); Assert.Contains("PooledResponseCodec", source); + Assert.Contains("AddDefaultSerializerService>", source); + Assert.Contains("OrleansGeneratedCodeHelper.CreateDefaultReferenceTypeActivator()", source); Assert.DoesNotContain("MakeGenericType", source); var output = compilation.AddReferences(MetadataReference.CreateFromFile(typeof(Microsoft.Extensions.Options.IConfigureOptions<>).Assembly.Location)) .AddSyntaxTrees(result.GeneratedSources.Select(static item => CSharpSyntaxTree.ParseText(item.SourceText, @@ -2365,6 +2367,163 @@ public sealed class Payload Assert.Contains(strict.Diagnostics, static diagnostic => diagnostic.Id == "ORLEANS0116"); } + [Fact] + public async Task RpcResponseFactoriesConstructPartialModelRootsWithinPendingGraphs() + { + var compilation = await CreateCompilation(""" + using Orleans; + namespace TestProject; + [GenerateSerializer] + public sealed class Payload + { + [Id(0)] public int Value { get; private set; } + [Id(1)] public System.Collections.Generic.IReadOnlyList> Members { get; private set; } + public Payload(int value) { Value = value; Members = new[] { System.Tuple.Create(new Item { Value = value }, "entry") }; } + } + [GenerateSerializer] + public sealed class Item { [Id(0)] public int Value { get; set; } } + """, $"RootActivatorProof{Guid.NewGuid():N}"); + var payload = compilation.GetTypeByMetadataName("TestProject.Payload"); + Assert.NotNull(payload); + var graph = SerializerFactoryGenerator.CreateRpcModelRoot(new GeneratorServices(compilation, new CodeGeneratorOptions()), + payload, TestContext.Current.CancellationToken); + Assert.NotNull(graph); + Assert.Contains("provider.GetCodec statement.Contains("CreateDefaultReferenceTypeActivator", StringComparison.Ordinal))); + var modelRegistrations = string.Join(Environment.NewLine, statements.Where(static statement => !statement.Contains("CreateDefaultReferenceTypeActivator", StringComparison.Ordinal))); + var exerciseSource = $$""" + using System; + using Microsoft.Extensions.DependencyInjection; + using Orleans.Serialization; + using Orleans.Serialization.Configuration; + using Orleans.Serialization.Invocation; + using Orleans.Serialization.Serializers; + public sealed class RootContext : TypeManifestProviderBase + { + private readonly bool includeActivator; + private int attempts; + public RootContext(bool includeActivator) { this.includeActivator = includeActivator; } + protected override void ConfigureInner(TypeManifestOptions options) + { + if (includeActivator) + { + {{activationRegistration}} + } + {{modelRegistrations}} + options.AddSerializerService(provider => + { + var probe = new ConstructionProbe( + provider.GetCodec>(), + provider.GetDeepCopier>(), + provider.GetActivator()); + if (++attempts == 1) + { + ConstructionProbe.Failed = probe; + throw new InvalidOperationException("injected root failure"); + } + return probe; + }); + } + } + public sealed class ConstructionProbe + { + public static ConstructionProbe Failed; + public Orleans.Serialization.Codecs.IFieldCodec> Codec { get; } + public Orleans.Serialization.Cloning.IDeepCopier> Copier { get; } + public Orleans.Serialization.Activators.IActivator Activator { get; } + public ConstructionProbe( + Orleans.Serialization.Codecs.IFieldCodec> codec, + Orleans.Serialization.Cloning.IDeepCopier> copier, + Orleans.Serialization.Activators.IActivator activator) + { Codec = codec; Copier = copier; Activator = activator; } + } + public static class RootProof + { + public static bool Run(bool includeActivator) + { + using var services = new ServiceCollection().AddSerializer(builder => builder.Configure(new RootContext(includeActivator))).BuildServiceProvider(); + var provider = services.GetRequiredService(); + var committed = provider.GetCodec(); + try + { + Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + throw new InvalidOperationException("expected injected root failure"); + } + catch (InvalidOperationException error) when (error.Message == "injected root failure") { } + var rebuilt = Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + using var original = Response.FromResult(new TestProject.Payload(47)); + using var copied = services.GetRequiredService().Copy(original); + var value = copied.GetResult(); + var codec = provider.GetCodec>(); + using var sessions = services.GetRequiredService().GetSession(); + var output = new System.Buffers.ArrayBufferWriter(); + var writer = Orleans.Serialization.Buffers.Writer.Create(output, sessions); + codec.WriteField(ref writer, 0, typeof(Response), (Response)original); + writer.Commit(); + var activator = provider.GetActivator(); + return value.Value == 47 && !ReferenceEquals(original.Result, value) + && value.Members[0].Item1.Value == 47 && value.Members[0].Item2 == "entry" + && !ReferenceEquals(((TestProject.Payload)original.Result).Members, value.Members) + && !ReferenceEquals(((TestProject.Payload)original.Result).Members[0].Item1, value.Members[0].Item1) + && ReferenceEquals(activator, provider.GetActivator()) + && ReferenceEquals(rebuilt.Activator, activator) && ReferenceEquals(rebuilt.Codec, codec) + && !ReferenceEquals(ConstructionProbe.Failed.Activator, activator) + && !ReferenceEquals(ConstructionProbe.Failed.Copier, rebuilt.Copier) + && ReferenceEquals(committed, provider.GetCodec()) + && activator.Create().Value == 0 && output.WrittenCount > 0; + } + } + """; + var output = compilation.AddReferences( + MetadataReference.CreateFromFile(typeof(Microsoft.Extensions.Options.IConfigureOptions<>).Assembly.Location), + MetadataReference.CreateFromFile(typeof(ServiceProvider).Assembly.Location)) + .AddSyntaxTrees(generated.GeneratedSources.Select(static source => CSharpSyntaxTree.ParseText(source.SourceText, path: source.HintName))) + .AddSyntaxTrees(CSharpSyntaxTree.ParseText(exerciseSource, cancellationToken: TestContext.Current.CancellationToken)); + using var image = new System.IO.MemoryStream(); + var emit = output.Emit(image, cancellationToken: TestContext.Current.CancellationToken); + Assert.True(emit.Success, string.Join(Environment.NewLine, emit.Diagnostics)); + var assembly = System.Reflection.Assembly.Load(image.ToArray()); + var run = assembly.GetType("RootProof")!.GetMethod("Run")!; + var rejected = Assert.Throws(() => run.Invoke(null, [false])); + var error = Assert.IsType(rejected.InnerException); + Assert.Contains("IActivator", error.Message); + Assert.Contains("graph is unpublished", error.Message); + Assert.Equal(true, run.Invoke(null, [true])); + } + + [Theory] + [InlineData("[UseActivator]", "public Payload(int value) => Value = value;")] + [InlineData("", "[GeneratedActivatorConstructor] public Payload(int value) => Value = value;")] + public async Task RpcResponseFactoriesPreserveCustomActivatorSelection(string attribute, string constructor) + { + var compilation = await CreateCompilation($$""" + using Orleans; + namespace TestProject; + [GenerateSerializer] + {{attribute}} + public sealed class Payload + { + [Id(0)] public int Value { get; private set; } + {{constructor}} + } + """); + var payload = compilation.GetTypeByMetadataName("TestProject.Payload"); + Assert.NotNull(payload); + var graph = SerializerFactoryGenerator.CreateRpcModelRoot(new GeneratorServices(compilation, new CodeGeneratorOptions()), + payload, TestContext.Current.CancellationToken); + Assert.NotNull(graph); + Assert.DoesNotContain("CreateDefaultReferenceTypeActivator", graph.ConfigurationStatements); + Assert.DoesNotContain("CreateDefaultValueTypeActivator", graph.ConfigurationStatements); + if (constructor.Contains("GeneratedActivatorConstructor", StringComparison.Ordinal)) + { + Assert.Contains("new global::OrleansCodeGen.TestProject.Activator_Payload(", graph.ConfigurationStatements); + } + } + [Theory] [InlineData("Task")] [InlineData("ValueTask")] From 5c2766d506b81e344b77323229962145c9b98bf9 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Fri, 2 Oct 2026 02:00:31 -0700 Subject: [PATCH 11/54] fix(codegen): reject incomplete custom activator construction roots --- .../SerializerFactoryGenerator.cs | 7 +++ .../OrleansGeneratedCodeHelper.cs | 4 +- .../OrleansSourceGeneratorTests.cs | 43 +++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs b/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs index 77c17d2092c..c9eb883fa55 100644 --- a/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs +++ b/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs @@ -91,6 +91,13 @@ internal sealed record Failure(ITypeSymbol Type, string Reason); } } + if (requiresActivator + && (type.HasAttribute(services.LibraryTypes.UseActivatorAttribute) && !constructionModel.HasActivatorConstructor + || constructionModel.HasActivatorConstructor && !SymbolEqualityComparer.Default.Equals(type.ContainingAssembly, services.Compilation.Assembly))) + { + return null; + } + var responseType = services.Compilation.GetTypeByMetadataName("Orleans.Serialization.Invocation.Response`1")!.Construct(type); var codec = $"global::Orleans.Serialization.Invocation.PooledResponseCodec<{Name(type)}, {registration.Codec}>"; var copier = $"global::Orleans.Serialization.Invocation.PooledResponseCopier<{Name(type)}, {registration.Copier}>"; diff --git a/src/Orleans.Serialization/GeneratedCodeHelpers/OrleansGeneratedCodeHelper.cs b/src/Orleans.Serialization/GeneratedCodeHelpers/OrleansGeneratedCodeHelper.cs index 421f1570255..162e01d1b88 100644 --- a/src/Orleans.Serialization/GeneratedCodeHelpers/OrleansGeneratedCodeHelper.cs +++ b/src/Orleans.Serialization/GeneratedCodeHelpers/OrleansGeneratedCodeHelper.cs @@ -30,7 +30,7 @@ public static IActivator CreateDefaultReferenceTypeActivator< #if NET5_0_OR_GREATER [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] #endif - T>() where T : class => new DefaultReferenceTypeActivator(); + T>() where T : class => new DefaultReferenceTypeActivator(); /// /// Creates the default activator for a statically specified value type. @@ -41,7 +41,7 @@ public static IActivator CreateDefaultValueTypeActivator< #if NET5_0_OR_GREATER [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] #endif - T>() where T : struct => new DefaultValueTypeActivator(); + T>() where T : struct => new DefaultValueTypeActivator(); private static readonly ThreadLocal ResolutionState = new ThreadLocal(() => new RecursiveServiceResolutionState()); diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index af48487c5ee..adcc13c4a74 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -2515,6 +2515,12 @@ public sealed class Payload Assert.NotNull(payload); var graph = SerializerFactoryGenerator.CreateRpcModelRoot(new GeneratorServices(compilation, new CodeGeneratorOptions()), payload, TestContext.Current.CancellationToken); + if (attribute.Contains("UseActivator", StringComparison.Ordinal)) + { + Assert.Null(graph); + return; + } + Assert.NotNull(graph); Assert.DoesNotContain("CreateDefaultReferenceTypeActivator", graph.ConfigurationStatements); Assert.DoesNotContain("CreateDefaultValueTypeActivator", graph.ConfigurationStatements); @@ -2524,6 +2530,43 @@ public sealed class Payload } } + [Fact] + public async Task RpcResponseFactoriesRejectInaccessibleReferencedGeneratedActivators() + { + var library = await CreateCompilation(""" + using Orleans; + namespace ReferencedActivation; + [GenerateSerializer] + public sealed class Payload + { + [Id(0)] public int Value { get; private set; } + [GeneratedActivatorConstructor] + public Payload(int value) => Value = value; + } + """, "ReferencedActivation"); + var generated = RunSourceGenerator(library); + Assert.Empty(generated.Diagnostics); + library = library.AddReferences(MetadataReference.CreateFromFile(typeof(Microsoft.Extensions.Options.IConfigureOptions<>).Assembly.Location)) + .AddSyntaxTrees(generated.GeneratedSources.Select(static source => CSharpSyntaxTree.ParseText(source.SourceText, path: source.HintName))); + using var image = new System.IO.MemoryStream(); + var emitted = library.Emit(image, cancellationToken: TestContext.Current.CancellationToken); + Assert.True(emitted.Success, string.Join(Environment.NewLine, emitted.Diagnostics)); + var consumer = (await CreateCompilation(""" + using Orleans; + using System.Threading.Tasks; + public interface IContract : IGrainWithIntegerKey + { + Task Get(); + } + """, "ActivationConsumer")).AddReferences(MetadataReference.CreateFromImage(image.ToArray())); + var type = consumer.GetTypeByMetadataName("ReferencedActivation.Payload"); + Assert.NotNull(type); + Assert.Null(SerializerFactoryGenerator.CreateRpcModelRoot(new GeneratorServices(consumer, new CodeGeneratorOptions()), + type, TestContext.Current.CancellationToken)); + var strict = RunSourceGenerator(consumer, new Dictionary { ["build_property.publishaot"] = "true" }); + Assert.Contains(strict.Diagnostics, static diagnostic => diagnostic.Id == "ORLEANS0116"); + } + [Theory] [InlineData("Task")] [InlineData("ValueTask")] From 59379b2aaae644bdcfe998d397bc3cad36784a81 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Fri, 2 Oct 2026 03:37:46 -0700 Subject: [PATCH 12/54] fix(codegen): close canonical value and array serializer services --- .../OrleansSourceGeneratorTests.cs | 155 ++++++++++++++++++ .../RpcResponses.Contracts.cs | 32 ++++ test/Orleans.NativeAotSmoke/RpcResponses.cs | 1 + .../RpcResponsesModels.cs | 20 +++ .../RpcResponseTests.cs | 6 + 5 files changed, 214 insertions(+) diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index adcc13c4a74..d740fa33dd9 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -2766,6 +2766,161 @@ public sealed class Payload { [Id(0)] public int Value { get; set; } } Assert.DoesNotContain(graph.Registrations.Keys, static type => type.Name.EndsWith("Marker", StringComparison.Ordinal)); } + [Theory] + [InlineData("TestProject.GeneratedValue", false)] + [InlineData("TestProject.Box", true)] + [InlineData("TestProject.Box", true)] + public async Task RpcResponseFactoriesCloseCanonicalFullGraphServices(string rootName, bool arrayCase) + { + var compilation = await CreateCompilation(""" + using Orleans; + namespace TestProject; + [GenerateSerializer] + public struct GeneratedValue { [Id(0)] public T Value { get; set; } } + [GenerateSerializer] + public sealed class Box { [Id(0)] public T[] Value { get; set; } } + """, $"FullGraphProof{Guid.NewGuid():N}"); + var definition = compilation.GetTypeByMetadataName(arrayCase ? "TestProject.Box`1" : "TestProject.GeneratedValue`1"); + Assert.NotNull(definition); + var element = compilation.GetSpecialType(rootName.Contains("byte", StringComparison.Ordinal) ? SpecialType.System_Byte : SpecialType.System_Int32); + var type = definition.Construct(element); + Assert.True(SerializerFactoryGenerator.TryCreate(new GeneratorServices(compilation, new CodeGeneratorOptions()), + [type], TestContext.Current.CancellationToken, out var graph, out var failure), failure?.Reason); + Assert.NotNull(graph); + var generated = RunSourceGenerator(compilation); + Assert.Empty(generated.Diagnostics); + var exercise = arrayCase ? $$""" + var provider = services.GetRequiredService(); + var serializer = new Serializer<{{rootName}}>(provider.GetCodec<{{rootName}}>(), sessions); + var copier = new DeepCopier<{{rootName}}>(provider.GetDeepCopier<{{rootName}}>(), services.GetRequiredService()); + var original = new {{rootName}} { Value = new[] { ({{(rootName.Contains("byte", StringComparison.Ordinal) ? "byte" : "int")}})7, ({{(rootName.Contains("byte", StringComparison.Ordinal) ? "byte" : "int")}})9 } }; + var copy = copier.Copy(original); + var wire = serializer.SerializeToArray(original); + using var legacy = new ServiceCollection().AddSerializer(builder => builder.AddAssembly(typeof({{rootName}}).Assembly)).BuildServiceProvider(); + var legacySerializer = new Serializer<{{rootName}}>( + legacy.GetRequiredService().GetCodec<{{rootName}}>(), + legacy.GetRequiredService()); + var legacyWire = legacySerializer.SerializeToArray(original); + var result = serializer.Deserialize(wire); + copy.Value[0] = 3; + return original.Value[0] == 7 && result.Value[0] == 7 && result.Value[1] == 9 + && !ReferenceEquals(original, copy) && !ReferenceEquals(original.Value, copy.Value) + && System.MemoryExtensions.SequenceEqual(wire, legacyWire) + && (!typeof({{rootName}}).GenericTypeArguments[0].Equals(typeof(byte)) + || provider.GetCodec() is Orleans.Serialization.Codecs.ByteArrayCodec + && provider.GetDeepCopier() is Orleans.Serialization.Codecs.ByteArrayCopier); + """ : """ + var provider = services.GetRequiredService(); + var serializer = new ValueSerializer>(provider, sessions); + var original = new TestProject.GeneratedValue { Value = 47 }; + var output = new System.Buffers.ArrayBufferWriter(); + serializer.Serialize(ref original, output); + var result = new TestProject.GeneratedValue(); + serializer.Deserialize(output.WrittenMemory, ref result); + return result.Value == 47 && ReferenceEquals( + provider.GetValueSerializer>(), + provider.GetCodec>()); + """; + var contextSource = $$""" + using System; + using Microsoft.Extensions.DependencyInjection; + using Orleans.Serialization; + using Orleans.Serialization.Configuration; + using Orleans.Serialization.Serializers; + using Orleans.Serialization.Session; + public sealed class ClosedContext : SerializerContext + { + protected override void ConfigureInner(TypeManifestOptions options) + { + {{graph.ConfigurationStatements}} + } + } + public static class FullGraphProof + { + public static bool Run() + { + using var services = new ServiceCollection().AddSerializerContext(new ClosedContext()).BuildServiceProvider(); + var sessions = services.GetRequiredService(); + {{exercise}} + } + } + """; + var outputCompilation = compilation.AddReferences( + MetadataReference.CreateFromFile(typeof(Microsoft.Extensions.Options.IConfigureOptions<>).Assembly.Location), + MetadataReference.CreateFromFile(typeof(ServiceProvider).Assembly.Location)) + .AddSyntaxTrees(generated.GeneratedSources.Select(static item => CSharpSyntaxTree.ParseText(item.SourceText, path: item.HintName))) + .AddSyntaxTrees(CSharpSyntaxTree.ParseText(contextSource, cancellationToken: TestContext.Current.CancellationToken)); + using var image = new System.IO.MemoryStream(); + var emit = outputCompilation.Emit(image, cancellationToken: TestContext.Current.CancellationToken); + Assert.True(emit.Success, string.Join(Environment.NewLine, emit.Diagnostics)); + var assembly = System.Reflection.Assembly.Load(image.ToArray()); + Assert.Equal(true, assembly.GetType("FullGraphProof")!.GetMethod("Run")!.Invoke(null, null)); + } + + [Fact] + public async Task RpcResponseFactoriesPreserveGenericArrayGraphCycles() + { + var compilation = await CreateCompilation(""" + using Orleans; + namespace TestProject; + [GenerateSerializer] + public sealed class Box { [Id(0)] public T[] Value { get; set; } } + [GenerateSerializer] + public sealed class Node { [Id(0)] public Box Children { get; set; } } + """, $"ArrayCycleProof{Guid.NewGuid():N}"); + var node = compilation.GetTypeByMetadataName("TestProject.Node"); + Assert.NotNull(node); + Assert.True(SerializerFactoryGenerator.TryCreate(new GeneratorServices(compilation, new CodeGeneratorOptions()), + [node], TestContext.Current.CancellationToken, out var graph, out var failure), failure?.Reason); + Assert.NotNull(graph); + var generated = RunSourceGenerator(compilation); + Assert.Empty(generated.Diagnostics); + var exercise = $$""" + using System; + using Microsoft.Extensions.DependencyInjection; + using Orleans.Serialization; + using Orleans.Serialization.Configuration; + using Orleans.Serialization.Serializers; + public sealed class CycleContext : SerializerContext + { + protected override void ConfigureInner(TypeManifestOptions options) + { + {{graph.ConfigurationStatements}} + } + } + public static class ArrayCycleProof + { + public static bool Run() + { + using var services = new ServiceCollection().AddSerializerContext(new CycleContext()).BuildServiceProvider(); + var provider = services.GetRequiredService(); + var serializer = new Serializer(provider.GetCodec(), + services.GetRequiredService()); + var copier = new DeepCopier(provider.GetDeepCopier(), + services.GetRequiredService()); + var original = new TestProject.Node(); + original.Children = new TestProject.Box { Value = new[] { original, original } }; + var copy = copier.Copy(original); + var result = serializer.Deserialize(serializer.SerializeToArray(original)); + return !ReferenceEquals(original, copy) && ReferenceEquals(copy, copy.Children.Value[0]) + && ReferenceEquals(copy.Children.Value[0], copy.Children.Value[1]) + && ReferenceEquals(result, result.Children.Value[0]) + && ReferenceEquals(result.Children.Value[0], result.Children.Value[1]); + } + } + """; + var output = compilation.AddReferences( + MetadataReference.CreateFromFile(typeof(Microsoft.Extensions.Options.IConfigureOptions<>).Assembly.Location), + MetadataReference.CreateFromFile(typeof(ServiceProvider).Assembly.Location)) + .AddSyntaxTrees(generated.GeneratedSources.Select(static source => CSharpSyntaxTree.ParseText(source.SourceText, path: source.HintName))) + .AddSyntaxTrees(CSharpSyntaxTree.ParseText(exercise, cancellationToken: TestContext.Current.CancellationToken)); + using var image = new System.IO.MemoryStream(); + var emit = output.Emit(image, cancellationToken: TestContext.Current.CancellationToken); + Assert.True(emit.Success, string.Join(Environment.NewLine, emit.Diagnostics)); + var assembly = System.Reflection.Assembly.Load(image.ToArray()); + Assert.Equal(true, assembly.GetType("ArrayCycleProof")!.GetMethod("Run")!.Invoke(null, null)); + } + [Fact] public async Task RpcResponseFactoriesPreserveGenericJitGenerationAndExplicitValidationOverride() { diff --git a/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs b/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs index 016c8db3750..8b587d4b37d 100644 --- a/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs +++ b/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs @@ -14,6 +14,38 @@ namespace Orleans.NativeAotSmoke; public static class RpcResponseContracts { + public static void CanonicalValueAndArrayServices() + { + using var services = CreateServices(); + var provider = services.GetRequiredService(); + var sessions = services.GetRequiredService(); + var valueSerializer = new ValueSerializer>(provider, sessions); + var original = new RpcGeneratedValue { Value = 47 }; + var output = new ArrayBufferWriter(); + valueSerializer.Serialize(ref original, output); + var value = new RpcGeneratedValue(); + valueSerializer.Deserialize(output.WrittenMemory, ref value); + Ensure(value.Value == 47, "The public value serializer uses the generated struct codec."); +#if NATIVE_AOT_SMOKE + Ensure(ReferenceEquals(provider.GetValueSerializer>(), provider.GetCodec>()), + "Value and field serializer services share the same generated codec instance."); +#endif + + var box = new RpcResponseBox { Value = [7, 9] }; + using var response = Response.FromResult(box); + using var copied = Copy(services, response); + using var roundTrip = RoundTrip(services, response); + var copy = copied.GetResult>(); + var result = roundTrip.GetResult>(); + Ensure(copy is not null && result is not null && result.Value.Length == 2 && result.Value[0] == 7 && result.Value[1] == 9, + "Closed generic array codecs preserve the response payload."); + Ensure(!ReferenceEquals(box, copy) && !ReferenceEquals(box.Value, copy.Value), "Canonical generic array copying isolates the result."); + copy.Value[0] = 3; + Ensure(box.Value[0] == 7, "Mutating the copied generic byte array leaves the original unchanged."); + Ensure(provider.GetCodec() is ByteArrayCodec && provider.GetDeepCopier() is ByteArrayCopier, + "Auxiliary generic array services preserve optimized direct byte-array dispatch."); + } + public static void PrimitiveResponses() { using var services = CreateServices(); diff --git a/test/Orleans.NativeAotSmoke/RpcResponses.cs b/test/Orleans.NativeAotSmoke/RpcResponses.cs index 2c3c36065ff..97389e4e3dd 100644 --- a/test/Orleans.NativeAotSmoke/RpcResponses.cs +++ b/test/Orleans.NativeAotSmoke/RpcResponses.cs @@ -2,6 +2,7 @@ using Orleans.NativeAotSmoke; RpcResponseContracts.PrimitiveResponses(); +RpcResponseContracts.CanonicalValueAndArrayServices(); RpcResponseContracts.ReferenceResponsePreservesCycles(); RpcResponseContracts.NullResponsePayload(); RpcResponseContracts.CompletedAndExceptionResponses(); diff --git a/test/Orleans.NativeAotSmoke/RpcResponsesModels.cs b/test/Orleans.NativeAotSmoke/RpcResponsesModels.cs index f0510b51bf9..8b1c3584846 100644 --- a/test/Orleans.NativeAotSmoke/RpcResponsesModels.cs +++ b/test/Orleans.NativeAotSmoke/RpcResponsesModels.cs @@ -14,6 +14,26 @@ public interface IRpcResponses : IGrainWithIntegerKey [Id(2)] Task Payload(); + + [Id(3)] + Task> Value(); + + [Id(4)] + Task> Bytes(); +} + +[GenerateSerializer] +public struct RpcGeneratedValue +{ + [Id(0)] + public T Value { get; set; } +} + +[GenerateSerializer] +public sealed class RpcResponseBox +{ + [Id(0)] + public T[] Value { get; set; } = null!; } [GenerateSerializer] diff --git a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs index 8f1082d4020..8cb438fcc6d 100644 --- a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs +++ b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs @@ -125,6 +125,10 @@ public void GeneratedResponseFactoriesPreserveCompletionAndExceptionIdentity() public void GeneratedCompletedResponsesPreserveTransportIdentity() => NativeAotSmoke.RpcResponseContracts.CompletedResponseRoundTrip(); + [Fact] + public void GeneratedValueAndArrayServicesRoundTripAndCopy() + => NativeAotSmoke.RpcResponseContracts.CanonicalValueAndArrayServices(); + [Fact] public void ExplicitExceptionTransportRequiresDeclaredDependencyGraph() { @@ -356,6 +360,8 @@ private sealed class RpcResponseTarget : NativeAotSmoke.IRpcResponses public Task Boolean() => Fail ? throw new InvalidOperationException("response failure") : Task.FromResult(true); public ValueTask Integer() => ValueTask.FromResult(42); public Task Payload() => Task.FromResult(Result); + public Task> Value() => Task.FromResult(new NativeAotSmoke.RpcGeneratedValue { Value = 47 }); + public Task> Bytes() => Task.FromResult(new NativeAotSmoke.RpcResponseBox { Value = [7, 9] }); } public sealed class FactoryService From 69eed41dbc30626e5f53a943687adebeaf3d442d Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Fri, 2 Oct 2026 05:21:42 -0700 Subject: [PATCH 13/54] fix(codegen): close canonical tuple and RPC argument construction services --- .../docs/implementation/serialization.md | 2 + .../RpcResponseGenerator.cs | 85 ++++++++- .../SerializerFactoryGenerator.cs | 173 +++++++++++++----- .../OrleansSourceGeneratorTests.cs | 163 +++++++++++++++++ .../RpcResponses.Contracts.cs | 20 ++ test/Orleans.NativeAotSmoke/RpcResponses.cs | 1 + .../RpcResponsesModels.cs | 33 ++++ .../RpcResponseTests.cs | 4 + 8 files changed, 425 insertions(+), 56 deletions(-) diff --git a/docs/site/src/content/docs/implementation/serialization.md b/docs/site/src/content/docs/implementation/serialization.md index 0caf5b47759..f12dafa46cd 100644 --- a/docs/site/src/content/docs/implementation/serialization.md +++ b/docs/site/src/content/docs/implementation/serialization.md @@ -145,6 +145,8 @@ These supplemental registrations are defaults: explicit closed factory registrat Ordinary metadata mode also supplies static response factories for non-generic generated result models. These factories construct the model's canonical generated codec and copier using their generated constructor signatures. Construction dependencies include the selected activator and declared codec/copier service contracts; source-known finite dependencies use closed factories, while interface contracts use ordinary metadata dispatch. This keeps construction within the provider's publication boundary and preserves canonical service identity and rollback. Default activation uses the existing reference- or value-type activator implementation, and custom activation retains its declared contract. Explicit context mode uses the complete finite dependency graph and validates each declared member shape. +The same collector closes source-known argument construction dependencies selected by generated proxy constructors. Tuple arguments and tuple members use the existing closed `TupleCodec` and `TupleCopier` implementations with their declared element services. Parameter-only one-way contracts register the required construction services while completion and result contracts also register their response graphs. Static interface helpers contribute no RPC construction roots. + `OrleansValidateRpcResponseFactories` enables compile-time validation of the response graph and defaults to the executable project's `PublishAot` setting. Diagnostic `ORLEANS0116` identifies an unresolved generic result, a custom return adapter requiring an explicit response contract, or a result dependency outside the supported finite graph. Applications with runtime-selected generic results register every permitted closed graph explicitly through and in a , and set `OrleansValidateRpcResponseFactories=false` for the project supplying that contract. A missing native response registration reports the closed response type and registration guidance at lookup. Dictionary results and dictionary members require an explicit closed registration which preserves the application's comparer contract. A dictionary's comparer is selected per value, so the method's declared result type alone supplies the key/value shape while the registration supplies comparer serialization and copying. diff --git a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs index 22cb111cc9e..8465211acf4 100644 --- a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs +++ b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs @@ -33,7 +33,12 @@ internal static ImmutableArray Generate( var services = new GeneratorServices(compilation, SourceGeneratorOptionsParser.CreateCodeGeneratorOptions(options)); var responseDefinition = compilation.GetTypeByMetadataName("Orleans.Serialization.Invocation.Response`1")!; var resolver = new TypeSymbolResolver(compilation); + var proxyContext = new ProxyGenerationContext(compilation, SourceGeneratorOptionsParser.CreateCodeGeneratorOptions(options)); + ProxySourceOutputGenerator.PopulateProxyInterfaces(proxyContext, resolver, + proxies.Select(static proxy => proxy.ProxyInterface).ToImmutableArray(), cancellationToken); + var binding = compilation.GetSemanticModel(compilation.SyntaxTrees.First()); var results = new Dictionary(SymbolEqualityComparer.Default); + var arguments = new Dictionary(SymbolEqualityComparer.Default); var hasCompletionMethods = false; var output = ImmutableArray.CreateBuilder(); foreach (var proxy in proxies) @@ -44,10 +49,39 @@ internal static ImmutableArray Generate( continue; } + var description = ProxySourceOutputGenerator.GetProxyInterfaceDescription(proxyContext, resolver, proxy.ProxyInterface, cancellationToken); + var (proxyClass, _) = new ProxyGenerator(proxyContext, new CopierGenerator(proxyContext)).Generate(description); + foreach (var request in proxyClass.Members.OfType() + .SelectMany(static constructor => constructor.DescendantNodes().OfType()) + .Where(static invocation => invocation.Expression is MemberAccessExpressionSyntax { Name: GenericNameSyntax { Identifier.ValueText: "GetService" } }) + .Select(static invocation => ((GenericNameSyntax)((MemberAccessExpressionSyntax)invocation.Expression).Name).TypeArgumentList.Arguments.Single())) + { + if (binding.GetSpeculativeTypeInfo(0, request, SpeculativeBindingOption.BindAsTypeOrNamespace).Type is INamedTypeSymbol service + && service.AllInterfaces.Concat([service]).FirstOrDefault(type => + SymbolEqualityComparer.Default.Equals(type.OriginalDefinition, services.LibraryTypes.DeepCopier_1)) is { } copier + && !ContainsTypeParameter(copier.TypeArguments[0]) && !arguments.ContainsKey(copier.TypeArguments[0])) + { + arguments.Add(copier.TypeArguments[0], description.Methods[0].Method); + } + } + foreach (var method in interfaceType.GetDeclaredInstanceMembers() .Concat(interfaceType.AllInterfaces.SelectMany(static type => type.GetDeclaredInstanceMembers())) .Where(static method => method.MethodKind == MethodKind.Ordinary)) { + if (method.TypeParameters.Length == 0) + { + foreach (var parameter in method.Parameters) + { + var parameterType = parameter.Type.WithNullableAnnotation(NullableAnnotation.None); + if (!ContainsTypeParameter(parameterType) && !services.LibraryTypes.IsShallowCopyable(parameterType) + && !arguments.ContainsKey(parameterType)) + { + arguments.Add(parameterType, method); + } + } + } + var returnType = method.ReturnType; if (returnType.SpecialType == SpecialType.System_Void) { @@ -84,7 +118,9 @@ internal static ImmutableArray Generate( } var supportedResults = new List(); + var coveredConstructionTypes = new HashSet(SymbolEqualityComparer.Default); var metadataModelRoots = new List(); + var argumentRoots = new List(); var dictionaryDefinition = compilation.GetTypeByMetadataName("System.Collections.Generic.Dictionary`2"); foreach (var entry in results.OrderBy(static entry => entry.Key.ToDisplayString(), StringComparer.Ordinal)) { @@ -101,6 +137,7 @@ internal static ImmutableArray Generate( } supportedResults.Add(resultType); + foreach (var known in candidate.Registrations.Keys) coveredConstructionTypes.Add(known); } else { @@ -115,7 +152,27 @@ internal static ImmutableArray Generate( } } - if (supportedResults.Count == 0 && metadataModelRoots.Count == 0 && !hasCompletionMethods) + var hasResponseRoots = supportedResults.Count > 0 || metadataModelRoots.Count > 0 || hasCompletionMethods; + foreach (var argument in arguments.OrderBy(static entry => entry.Key.ToDisplayString(), StringComparer.Ordinal)) + { + if (coveredConstructionTypes.Contains(argument.Key)) continue; + if (SerializerFactoryGenerator.TryCreate(services, [argument.Key], cancellationToken, out var argumentGraph, out var failure, useDefaultFactories: true) + && !argumentGraph.Registrations.Keys.OfType().Any(type => SymbolEqualityComparer.Default.Equals(type.OriginalDefinition, dictionaryDefinition))) + { + argumentRoots.Add(argumentGraph); + foreach (var known in argumentGraph.Registrations.Keys) coveredConstructionTypes.Add(known); + } + else if (!options.ValidateRpcResponseFactories) + { + metadataModelRoots.Add(SerializerFactoryGenerator.CreateRpcConstructionRoot(services, argument.Key, cancellationToken)); + } + else + { + Report(argument.Value, argument.Key, failure?.Reason ?? "the argument graph requires an explicit closed construction contract"); + } + } + + if (supportedResults.Count == 0 && metadataModelRoots.Count == 0 && argumentRoots.Count == 0 && !hasCompletionMethods) { return output.ToImmutable(); } @@ -150,6 +207,11 @@ internal static ImmutableArray Generate( source.AppendLine(graph.ConfigurationStatements); } + foreach (var argumentRoot in argumentRoots) + { + source.AppendLine(argumentRoot.ConfigurationStatements); + } + if (metadataModelRoots.Count > 0) { source.AppendLine("if (!options.RequireExplicitTypeRegistration)"); @@ -161,14 +223,17 @@ internal static ImmutableArray Generate( source.AppendLine("}"); } - source.AppendLine("options.AddDefaultSerializerService(static provider => new ResponseFieldCodec());"); - source.AppendLine("options.AddDefaultSerializerService(static provider => new ResponseFieldCopier());"); - source.AppendLine("options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null!, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null!, provider));"); - source.AppendLine("options.AddDefaultSerializerService(static provider => new CompletedResponseActivator());"); - source.AppendLine("options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null!, provider)));"); - source.AppendLine("options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier());"); - source.AppendLine("options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null!, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null!, provider));"); - source.AppendLine("options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse));"); + if (hasResponseRoots) + { + source.AppendLine("options.AddDefaultSerializerService(static provider => new ResponseFieldCodec());"); + source.AppendLine("options.AddDefaultSerializerService(static provider => new ResponseFieldCopier());"); + source.AppendLine("options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null!, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null!, provider));"); + source.AppendLine("options.AddDefaultSerializerService(static provider => new CompletedResponseActivator());"); + source.AppendLine("options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null!, provider)));"); + source.AppendLine("options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier());"); + source.AppendLine("options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null!, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null!, provider));"); + source.AppendLine("options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse));"); + } source.AppendLine("#endif"); source.AppendLine("}"); @@ -215,7 +280,7 @@ void Report(IMethodSymbol method, ITypeSymbol resultType, string reason) } private static bool ContainsTypeParameter(ITypeSymbol type) - => type is ITypeParameterSymbol + => type is ITypeParameterSymbol or IErrorTypeSymbol || type is IArrayTypeSymbol array && ContainsTypeParameter(array.ElementType) || type is INamedTypeSymbol named && (named.TypeArguments.Any(ContainsTypeParameter) || named.ContainingType is { } containing && ContainsTypeParameter(containing)); diff --git a/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs b/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs index c9eb883fa55..4aa47d6d937 100644 --- a/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs +++ b/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs @@ -53,7 +53,15 @@ internal sealed record Failure(ITypeSymbol Type, string Reason); } var registration = new Registration(type); - var constructionModel = SerializableSourceOutputGenerator.CreateSerializableTypeDescription(services, type, inspectReferenceMetadata: true); + ISerializableTypeDescription? constructionModel; + try + { + constructionModel = SerializableSourceOutputGenerator.CreateSerializableTypeDescription(services, type, inspectReferenceMetadata: true); + } + catch (OrleansGeneratorDiagnosticAnalysisException) + { + return null; + } if (constructionModel is null) { return null; @@ -107,7 +115,7 @@ internal sealed record Failure(ITypeSymbol Type, string Reason); .Select(static member => member.Type) .Distinct(SymbolEqualityComparer.Default)) { - AppendConstructionDependency(memberType); + AppendConstructionDependency(services, memberType, cancellationToken, constructionTypes, result); } if (requiresActivator && constructionModel.HasActivatorConstructor @@ -152,59 +160,103 @@ bool HasActivatorDependency(INamedTypeSymbol implementation) && SymbolEqualityComparer.Default.Equals(dependency.OriginalDefinition, services.LibraryTypes.IActivator_1) && SymbolEqualityComparer.Default.Equals(dependency.TypeArguments[0], type)); - void AppendConstructionDependency(ITypeSymbol dependency) + } + + internal static Graph CreateRpcConstructionRoot(IGeneratorServices services, ITypeSymbol type, CancellationToken cancellationToken) + { + var result = new StringBuilder(); + AppendConstructionDependency(services, type, cancellationToken, new HashSet(SymbolEqualityComparer.Default), result); + return new Graph(new Dictionary(SymbolEqualityComparer.Default), result.ToString()); + } + + private static void AppendConstructionDependency(IGeneratorServices services, ITypeSymbol dependency, CancellationToken cancellationToken, + HashSet constructionTypes, StringBuilder result) + { + cancellationToken.ThrowIfCancellationRequested(); + dependency = dependency.WithNullableAnnotation(NullableAnnotation.None); + if (constructionTypes.Contains(dependency)) return; + if (TryCreate(services, [dependency], cancellationToken, out var finite, out _, useDefaultFactories: true) + && !finite.Registrations.Keys.OfType().Any(named => + SymbolEqualityComparer.Default.Equals(named.OriginalDefinition, services.Compilation.GetTypeByMetadataName("System.Collections.Generic.Dictionary`2")))) + { + foreach (var registered in finite.Registrations.Keys) constructionTypes.Add(registered); + result.AppendLine(finite.ConfigurationStatements); + return; + } + + if (dependency is INamedTypeSymbol modelType && modelType.HasAttribute(services.LibraryTypes.GenerateSerializerAttribute) + && CreateRpcModelRoot(services, modelType, cancellationToken, constructionTypes, includeResponse: false) is { } modelGraph) { - dependency = dependency.WithNullableAnnotation(NullableAnnotation.None); - if (constructionTypes.Contains(dependency)) return; - if (TryCreate(services, [dependency], cancellationToken, out var finite, out _, useDefaultFactories: true) - && !finite.Registrations.Keys.OfType().Any(named => - SymbolEqualityComparer.Default.Equals(named.OriginalDefinition, services.Compilation.GetTypeByMetadataName("System.Collections.Generic.Dictionary`2")))) - { - foreach (var registered in finite.Registrations.Keys) constructionTypes.Add(registered); - result.AppendLine(finite.ConfigurationStatements); - return; - } + result.AppendLine(modelGraph.ConfigurationStatements); + } + else + { + constructionTypes.Add(dependency); + } - if (dependency is INamedTypeSymbol modelType && modelType.HasAttribute(services.LibraryTypes.GenerateSerializerAttribute) - && CreateRpcModelRoot(services, modelType, cancellationToken, constructionTypes, includeResponse: false) is { } modelGraph) - { - result.AppendLine(modelGraph.ConfigurationStatements); - } - else + if (dependency is INamedTypeSymbol tupleType && TryGetTupleServices(services, tupleType, out var tupleCodec, out var tupleCopier)) + { + foreach (var element in tupleType.TypeArguments) AppendConstructionDependency(services, element, cancellationToken, constructionTypes, result); + result.Append("options.AddDefaultSerializerService<").Append(Name(tupleCodec)).Append(">(static provider => ") + .Append(ConstructReferenced(Name(tupleCodec), tupleCodec)).AppendLine(");"); + result.Append("options.AddDefaultSerializerService<").Append(Name(tupleCopier)).Append(">(static provider => ") + .Append(ConstructReferenced(Name(tupleCopier), tupleCopier)).AppendLine(");"); + result.Append("options.AddDefaultSerializer<").Append(Name(tupleType)).Append(">(static provider => ") + .Append(Resolve(Name(tupleCodec))).Append(", static provider => ").Append(Resolve(Name(tupleCopier))).AppendLine(");"); + return; + } + + if (dependency is INamedTypeSymbol collection + && services.LibraryTypes.WellKnownCodecs.FindByUnderlyingType(collection.OriginalDefinition) is { } collectionCodec + && services.LibraryTypes.WellKnownCopiers.FindByUnderlyingType(collection.OriginalDefinition) is { } collectionCopier + && collectionCodec.CodecType.IsGenericType && collectionCopier.CopierType.IsGenericType) + { + var codec = collectionCodec.CodecType.Construct([.. collection.TypeArguments]); + var copier = collectionCopier.CopierType.Construct([.. collection.TypeArguments]); + foreach (var argument in collection.TypeArguments) AppendConstructionDependency(services, argument, cancellationToken, constructionTypes, result); + foreach (var parameter in codec.InstanceConstructors.SelectMany(static constructor => constructor.Parameters)) { - constructionTypes.Add(dependency); + if (parameter.Type is INamedTypeSymbol contract + && SymbolEqualityComparer.Default.Equals(contract.OriginalDefinition, services.LibraryTypes.FieldCodec_1)) + AppendConstructionDependency(services, contract.TypeArguments[0], cancellationToken, constructionTypes, result); } - - var name = Name(dependency); - // Metadata bridges add service contracts, while type dispatch stays with ordinary metadata. - result.Append("options.AddDefaultSerializerService>(static provider => provider.GetCodec<").Append(name).AppendLine(">());"); - result.Append("options.AddDefaultSerializerService>(static provider => provider.GetDeepCopier<").Append(name).AppendLine(">());"); - if (dependency is INamedTypeSymbol named) + result.Append("options.AddDefaultSerializerService<").Append(Name(codec)).Append(">(static provider => ") + .Append(ConstructReferenced(Name(codec), codec, preferCompleteConstructor: true)).AppendLine(");"); + result.Append("options.AddDefaultSerializerService<").Append(Name(copier)).Append(">(static provider => ") + .Append(ConstructReferenced(Name(copier), copier)).AppendLine(");"); + result.Append("options.AddDefaultSerializer<").Append(Name(collection)).Append(">(static provider => ") + .Append(Resolve(Name(codec))).Append(", static provider => ").Append(Resolve(Name(copier))).AppendLine(");"); + return; + } + + var name = Name(dependency); + // Metadata bridges add service contracts, while type dispatch stays with ordinary metadata. + result.Append("options.AddDefaultSerializerService>(static provider => provider.GetCodec<").Append(name).AppendLine(">());"); + result.Append("options.AddDefaultSerializerService>(static provider => provider.GetDeepCopier<").Append(name).AppendLine(">());"); + if (dependency is INamedTypeSymbol named) + { + foreach (var argument in named.TypeArguments) AppendConstructionDependency(services, argument, cancellationToken, constructionTypes, result); + if (services.LibraryTypes.WellKnownCodecs.FindByUnderlyingType(named.OriginalDefinition) is { } knownCodec + && knownCodec.CodecType.IsGenericType) { - foreach (var argument in named.TypeArguments) AppendConstructionDependency(argument); - if (services.LibraryTypes.WellKnownCodecs.FindByUnderlyingType(named.OriginalDefinition) is { } knownCodec - && knownCodec.CodecType.IsGenericType) + var codec = knownCodec.CodecType.Construct([.. named.TypeArguments]); + foreach (var parameter in codec.InstanceConstructors.SelectMany(static constructor => constructor.Parameters)) { - var codec = knownCodec.CodecType.Construct([.. named.TypeArguments]); - foreach (var parameter in codec.InstanceConstructors.SelectMany(static constructor => constructor.Parameters)) + if (parameter.Type is INamedTypeSymbol service + && (SymbolEqualityComparer.Default.Equals(service.OriginalDefinition, services.LibraryTypes.FieldCodec_1) + || SymbolEqualityComparer.Default.Equals(service.OriginalDefinition, services.LibraryTypes.DeepCopier_1))) { - if (parameter.Type is INamedTypeSymbol service - && (SymbolEqualityComparer.Default.Equals(service.OriginalDefinition, services.LibraryTypes.FieldCodec_1) - || SymbolEqualityComparer.Default.Equals(service.OriginalDefinition, services.LibraryTypes.DeepCopier_1))) - { - AppendConstructionDependency(service.TypeArguments[0]); - } + AppendConstructionDependency(services, service.TypeArguments[0], cancellationToken, constructionTypes, result); } } } - else if (dependency is IArrayTypeSymbol array) - { - AppendConstructionDependency(array.ElementType); - } } - + else if (dependency is IArrayTypeSymbol array) + { + AppendConstructionDependency(services, array.ElementType, cancellationToken, constructionTypes, result); + } } internal static bool TryCreate( @@ -414,6 +466,15 @@ void ResolveResponseImplementations(Registration registration) registration.Dependencies.Add(named.TypeArguments[0]); return null; } + + if (TryGetTupleServices(services, named, out var tupleCodec, out var tupleCopier)) + { + registration.Codec = Name(tupleCodec); + registration.Copier = Name(tupleCopier); + registration.Dependencies.AddRange(named.TypeArguments); + return null; + } + var collection = definition switch { "System.Collections.Generic.List" => "List", @@ -608,6 +669,23 @@ private static void DescribeGeneratedModel(Registration registration, INamedType registration.Model = model; } + private static bool TryGetTupleServices(IGeneratorServices services, INamedTypeSymbol type, + [NotNullWhen(true)] out INamedTypeSymbol? codec, [NotNullWhen(true)] out INamedTypeSymbol? copier) + { + codec = null; + copier = null; + var arity = type.TypeArguments.Length; + if (arity == 0 || !SymbolEqualityComparer.Default.Equals(type.OriginalDefinition, + services.Compilation.GetTypeByMetadataName($"System.Tuple`{arity}"))) + { + return false; + } + + codec = services.Compilation.GetTypeByMetadataName($"Orleans.Serialization.Codecs.TupleCodec`{arity}")!.Construct([.. type.TypeArguments]); + copier = services.Compilation.GetTypeByMetadataName($"Orleans.Serialization.Codecs.TupleCopier`{arity}")!.Construct([.. type.TypeArguments]); + return true; + } + private static void ConstructGeneratedModel(Registration registration, IGeneratorServices services) { var codecDeclaration = new SerializerGenerator(services).Generate(registration.Model!); @@ -618,9 +696,12 @@ private static void ConstructGeneratedModel(Registration registration, IGenerato : ConstructGenerated(registration.Copier, copierDeclaration); } - private static string ConstructReferenced(string name, INamedTypeSymbol implementation) + private static string ConstructReferenced(string name, INamedTypeSymbol implementation, bool preferCompleteConstructor = false) { - var constructor = implementation.InstanceConstructors.Single(ctor => ctor.DeclaredAccessibility == Accessibility.Public); + var constructors = implementation.InstanceConstructors.Where(static constructor => constructor.DeclaredAccessibility == Accessibility.Public); + var constructor = preferCompleteConstructor + ? constructors.OrderByDescending(static constructor => constructor.Parameters.Length).First() + : constructors.Single(); var arguments = constructor.Parameters.Select(parameter => parameter.Type.ToDisplayString() == "Orleans.Serialization.Serializers.ICodecProvider" ? "provider" diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index d740fa33dd9..dada8fc95a6 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -2921,6 +2921,169 @@ public static bool Run() Assert.Equal(true, assembly.GetType("ArrayCycleProof")!.GetMethod("Run")!.Invoke(null, null)); } + [Theory] + [InlineData(1)] + [InlineData(2)] + [InlineData(3)] + public async Task RpcResponseFactoriesCloseCanonicalTupleConstruction(int arity) + { + var compilation = await CreateCompilation(""" + using Orleans; + namespace TestProject; + [GenerateSerializer] + public sealed class Item { [Id(0)] public int Value { get; set; } } + """, $"TupleConstructionProof{Guid.NewGuid():N}"); + var item = compilation.GetTypeByMetadataName("TestProject.Item"); + Assert.NotNull(item); + var elementTypes = Enumerable.Repeat(item, arity).ToArray(); + var tuple = compilation.GetTypeByMetadataName($"System.Tuple`{arity}")!.Construct(elementTypes); + Assert.True(SerializerFactoryGenerator.TryCreate(new GeneratorServices(compilation, new CodeGeneratorOptions()), + [tuple], TestContext.Current.CancellationToken, out var graph, out var failure), failure?.Reason); + Assert.NotNull(graph); + var generated = RunSourceGenerator(compilation); + Assert.Empty(generated.Diagnostics); + var tupleName = tuple.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); + var arguments = string.Join(", ", Enumerable.Repeat("item", arity)); + var values = string.Join(" && ", Enumerable.Range(1, arity).Select(index => $"copy.Item{index}.Value == 47 && result.Item{index}.Value == 47")); + var aliasing = arity > 1 ? "&& ReferenceEquals(copy.Item1, copy.Item2) && ReferenceEquals(result.Item1, result.Item2)" : ""; + var exercise = $$""" + using System; + using Microsoft.Extensions.DependencyInjection; + using Orleans.Serialization; + using Orleans.Serialization.Configuration; + using Orleans.Serialization.Serializers; + public sealed class TupleContext : SerializerContext + { + protected override void ConfigureInner(TypeManifestOptions options) + { + {{graph.ConfigurationStatements}} + } + } + public static class TupleProof + { + public static bool Run() + { + using var services = new ServiceCollection().AddSerializerContext(new TupleContext()).BuildServiceProvider(); + var provider = services.GetRequiredService(); + var serializer = new Serializer<{{tupleName}}>(provider.GetCodec<{{tupleName}}>(), + services.GetRequiredService()); + var copier = new DeepCopier<{{tupleName}}>(provider.GetDeepCopier<{{tupleName}}>(), + services.GetRequiredService()); + var item = new TestProject.Item { Value = 47 }; + var original = new {{tupleName}}({{arguments}}); + var copy = copier.Copy(original); + var wire = serializer.SerializeToArray(original); + var result = serializer.Deserialize(wire); + using var legacy = new ServiceCollection().AddSerializer(builder => builder.AddAssembly(typeof(TestProject.Item).Assembly)).BuildServiceProvider(); + var oldSerializer = new Serializer<{{tupleName}}>(legacy.GetRequiredService().GetCodec<{{tupleName}}>(), + legacy.GetRequiredService()); + return !ReferenceEquals(original, copy) && !ReferenceEquals(item, copy.Item1) + && {{values}} {{aliasing}} + && System.MemoryExtensions.SequenceEqual(wire, oldSerializer.SerializeToArray(original)); + } + } + """; + var output = compilation.AddReferences( + MetadataReference.CreateFromFile(typeof(Microsoft.Extensions.Options.IConfigureOptions<>).Assembly.Location), + MetadataReference.CreateFromFile(typeof(ServiceProvider).Assembly.Location)) + .AddSyntaxTrees(generated.GeneratedSources.Select(static source => CSharpSyntaxTree.ParseText(source.SourceText, path: source.HintName))) + .AddSyntaxTrees(CSharpSyntaxTree.ParseText(exercise, cancellationToken: TestContext.Current.CancellationToken)); + using var image = new System.IO.MemoryStream(); + var emit = output.Emit(image, cancellationToken: TestContext.Current.CancellationToken); + Assert.True(emit.Success, string.Join(Environment.NewLine, emit.Diagnostics)); + var assembly = System.Reflection.Assembly.Load(image.ToArray()); + Assert.Equal(true, assembly.GetType("TupleProof")!.GetMethod("Run")!.Invoke(null, null)); + } + + [Theory] + [InlineData("Task", true)] + [InlineData("Task", true)] + [InlineData("void", false)] + public async Task RpcResponseFactoriesConstructActualTupleArgumentProxies(string returnType, bool responseExpected) + { + var compilation = await CreateCompilation($$""" + using System; + using System.Threading.Tasks; + using Orleans; + using Orleans.Runtime; + using Orleans.Serialization.Cloning; + using Orleans.Serialization.Invocation; + using Orleans.Serialization.Serializers; + namespace TestProject; + [DefaultInvokableBaseType(typeof(Task<>), typeof(TaskRequest<>))] + [DefaultInvokableBaseType(typeof(Task), typeof(TaskRequest))] + [DefaultInvokableBaseType(typeof(void), typeof(VoidRequest))] + public abstract class TupleProxyBase + { + protected TupleProxyBase(ICodecProvider provider, CopyContextPool pool) + { + CodecProvider = provider; + CopyContextPool = pool; + } + protected ICodecProvider CodecProvider { get; } + protected CopyContextPool CopyContextPool { get; } + protected T GetInvokable() where T : class, IInvokable, new() => new T(); + protected ValueTask InvokeAsync(IInvokable body) => default; + protected ValueTask InvokeAsync(IInvokable body) => default; + protected void Invoke(IInvokable body) { } + } + [GenerateMethodSerializers(typeof(TupleProxyBase))] + public interface IContract + { + {{returnType}} InvokeTuple(System.Collections.Generic.List> value); + } + """, $"ProxyConstructionProof{Guid.NewGuid():N}"); + var generated = RunSourceGenerator(compilation); + Assert.Empty(generated.Diagnostics); + var source = Assert.Single(generated.GeneratedSources, static item => item.HintName.EndsWith(".orleans.rpcresponses.g.cs", StringComparison.Ordinal)).SourceText.ToString(); + Assert.Contains("new global::Orleans.Serialization.Codecs.TupleCopier", source); + Assert.Equal(responseExpected, source.Contains("options.AddDefaultSerializer", StringComparison.Ordinal)); + var tuple = compilation.GetTypeByMetadataName("System.Tuple`2")!.Construct( + compilation.GetTypeByMetadataName("Orleans.Runtime.SiloAddress")!, compilation.GetTypeByMetadataName("System.DateTime")!); + var list = compilation.GetTypeByMetadataName("System.Collections.Generic.List`1")!.Construct(tuple); + var construction = SerializerFactoryGenerator.CreateRpcConstructionRoot(new GeneratorServices(compilation, new CodeGeneratorOptions()), + list, TestContext.Current.CancellationToken); + var exercise = $$""" + using System; + using Microsoft.Extensions.DependencyInjection; + using Orleans.Serialization; + using Orleans.Serialization.Configuration; + using Orleans.Serialization.Serializers; + public sealed class ProxyContext : TypeManifestProviderBase + { + protected override void ConfigureInner(TypeManifestOptions options) + { + {{construction.ConfigurationStatements}} + } + } + public static class ProxyProof + { + public static bool Run() + { + using var services = new ServiceCollection().AddSerializer(builder => builder.Configure(new ProxyContext())).BuildServiceProvider(); + var provider = services.GetRequiredService(); + var pool = services.GetRequiredService(); + var proxy = new OrleansCodeGen.TestProject.Proxy_IContract(provider, pool); + var copier = provider.GetDeepCopier>(); + var input = Tuple.Create(Orleans.Runtime.SiloAddress.New(System.Net.IPAddress.Loopback, 1234, 1), new DateTime(638000000000000000L, DateTimeKind.Utc)); + var copy = new DeepCopier>(copier, pool).Copy(input); + return proxy is TestProject.IContract && ReferenceEquals(input, copy) + && ReferenceEquals(copier, provider.GetDeepCopier>()); + } + } + """; + var output = compilation.AddReferences( + MetadataReference.CreateFromFile(typeof(Microsoft.Extensions.Options.IConfigureOptions<>).Assembly.Location), + MetadataReference.CreateFromFile(typeof(ServiceProvider).Assembly.Location)) + .AddSyntaxTrees(generated.GeneratedSources.Select(static item => CSharpSyntaxTree.ParseText(item.SourceText, path: item.HintName))) + .AddSyntaxTrees(CSharpSyntaxTree.ParseText(exercise, cancellationToken: TestContext.Current.CancellationToken)); + using var image = new System.IO.MemoryStream(); + var emit = output.Emit(image, cancellationToken: TestContext.Current.CancellationToken); + Assert.True(emit.Success, string.Join(Environment.NewLine, emit.Diagnostics)); + var assembly = System.Reflection.Assembly.Load(image.ToArray()); + Assert.Equal(true, assembly.GetType("ProxyProof")!.GetMethod("Run")!.Invoke(null, null)); + } + [Fact] public async Task RpcResponseFactoriesPreserveGenericJitGenerationAndExplicitValidationOverride() { diff --git a/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs b/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs index 8b587d4b37d..2f339d91618 100644 --- a/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs +++ b/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs @@ -14,6 +14,26 @@ namespace Orleans.NativeAotSmoke; public static class RpcResponseContracts { + public static void ConstructTupleArgumentProxyBeforeInvocation() + { + using var services = CreateServices(); + var provider = services.GetRequiredService(); + var pool = services.GetRequiredService(); +#if NATIVE_AOT_SMOKE + IRpcTupleArguments proxy = new global::OrleansCodeGen.Orleans.NativeAotSmoke.Proxy_IRpcTupleArguments(provider, pool); + Ensure(proxy is not null, "The actual generated tuple-argument proxy constructs before invocation."); +#endif + var reference = new RpcTupleReference { Value = 47 }; + var tuple = Tuple.Create(reference, new DateTime(638000000000000000L, DateTimeKind.Utc)); + var input = new System.Collections.Generic.List> { tuple, tuple }; + var copier = provider.GetDeepCopier>>(); + var copy = new DeepCopier>>(copier, pool).Copy(input); + Ensure(!ReferenceEquals(input, copy) && ReferenceEquals(tuple, copy[0]) && ReferenceEquals(copy[0], copy[1]), + "Canonical tuple and list construction preserves immutable tuple identity."); + Ensure(copy[0].Item1.Value == 47 && copy[0].Item2 == tuple.Item2, + "Mixed reference/value argument tuples preserve their values."); + } + public static void CanonicalValueAndArrayServices() { using var services = CreateServices(); diff --git a/test/Orleans.NativeAotSmoke/RpcResponses.cs b/test/Orleans.NativeAotSmoke/RpcResponses.cs index 97389e4e3dd..a2fa17216bc 100644 --- a/test/Orleans.NativeAotSmoke/RpcResponses.cs +++ b/test/Orleans.NativeAotSmoke/RpcResponses.cs @@ -3,6 +3,7 @@ RpcResponseContracts.PrimitiveResponses(); RpcResponseContracts.CanonicalValueAndArrayServices(); +RpcResponseContracts.ConstructTupleArgumentProxyBeforeInvocation(); RpcResponseContracts.ReferenceResponsePreservesCycles(); RpcResponseContracts.NullResponsePayload(); RpcResponseContracts.CompletedAndExceptionResponses(); diff --git a/test/Orleans.NativeAotSmoke/RpcResponsesModels.cs b/test/Orleans.NativeAotSmoke/RpcResponsesModels.cs index 8b1c3584846..acb6b21ac65 100644 --- a/test/Orleans.NativeAotSmoke/RpcResponsesModels.cs +++ b/test/Orleans.NativeAotSmoke/RpcResponsesModels.cs @@ -1,6 +1,9 @@ using System.Threading.Tasks; using Orleans; using Orleans.Serialization.Invocation; +using Orleans.Serialization.Cloning; +using Orleans.Serialization.Serializers; +using Orleans.Runtime; namespace Orleans.NativeAotSmoke; @@ -36,6 +39,36 @@ public sealed class RpcResponseBox public T[] Value { get; set; } = null!; } +[GenerateSerializer, Immutable] +public sealed class RpcTupleReference +{ + [Id(0)] + public int Value { get; set; } +} + +[DefaultInvokableBaseType(typeof(Task<>), typeof(TaskRequest<>))] +public abstract class RpcTupleProxyBase +{ + protected RpcTupleProxyBase(ICodecProvider provider, CopyContextPool pool) + { + CodecProvider = provider; + CopyContextPool = pool; + } + + protected ICodecProvider CodecProvider { get; } + protected CopyContextPool CopyContextPool { get; } + protected T GetInvokable() where T : class, IInvokable, new() => new T(); + protected ValueTask InvokeAsync(IInvokable body) => default; + protected ValueTask InvokeAsync(IInvokable body) => default; + protected void Invoke(IInvokable body) { } +} + +[GenerateMethodSerializers(typeof(RpcTupleProxyBase))] +public interface IRpcTupleArguments +{ + Task Accept(System.Collections.Generic.List> input); +} + [GenerateSerializer] public sealed class RpcResponsePayload { diff --git a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs index 8cb438fcc6d..3782545c94a 100644 --- a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs +++ b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs @@ -129,6 +129,10 @@ public void GeneratedCompletedResponsesPreserveTransportIdentity() public void GeneratedValueAndArrayServicesRoundTripAndCopy() => NativeAotSmoke.RpcResponseContracts.CanonicalValueAndArrayServices(); + [Fact] + public void CanonicalTupleArgumentConstructionPreservesIdentity() + => NativeAotSmoke.RpcResponseContracts.ConstructTupleArgumentProxyBeforeInvocation(); + [Fact] public void ExplicitExceptionTransportRequiresDeclaredDependencyGraph() { From 5d0be372580c524036d359faaa879a74de011d49 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Fri, 2 Oct 2026 05:34:46 -0700 Subject: [PATCH 14/54] test(codegen): update canonical tuple response registration snapshot --- ...TestGrainWithDifferentKeyTypes.verified.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.verified.cs index bd14a9a01cb..944b687f9cd 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.verified.cs @@ -777,6 +777,14 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response>)); + options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response>)); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); @@ -785,6 +793,18 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(global::System.Guid)); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::System.Tuple)); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::System.Tuple)); + options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.Int64Codec()); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(long)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); From 6620ccd14cad22d7d6ed2784885423de66599d73 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Fri, 2 Oct 2026 09:32:18 -0700 Subject: [PATCH 15/54] feat(rpc): generate self-writing copied response holders --- .../docs/implementation/serialization.md | 8 +- .../InvokableGenerator.cs | 52 +- .../RpcResponseGenerator.cs | 21 +- .../RpcResponseHolderGenerator.cs | 219 +++ src/Orleans.Core/Core/GrainMethodInvoker.cs | 19 +- .../Messaging/MessageSerializer.cs | 23 +- .../Runtime/InvokableObjectManager.cs | 16 +- .../Core/InsideRuntimeClient.cs | 19 +- .../Configuration/TypeManifestOptions.cs | 14 + .../Invocation/IRawResponseReader.cs | 24 + .../Invocation/IRawResponseWriter.cs | 17 + .../Invocation/IResponseInvokable.cs | 20 + .../Invocation/Pools/ResponsePool.cs | 19 + .../Serializers/CodecProvider.cs | 23 + src/api/Orleans.Runtime/Orleans.Runtime.cs | 15 + .../OrleansSourceGeneratorTests.cs | 64 + ...SourceGeneratorTests.TestAlias.verified.cs | 1 + ...eGeneratorTests.TestBasicClass.verified.cs | 2 + ...tBasicClassWithAnnotatedFields.verified.cs | 2 + ...ssWithDifferentAccessModifiers.verified.cs | 4 + ....TestBasicClassWithInheritance.verified.cs | 4 + ...TestBasicClassWithoutNamespace.verified.cs | 2 + ...ests.TestBasicGrain.DotNet10_0.verified.cs | 499 ++++++ ...Tests.TestBasicGrain.DotNet8_0.verified.cs | 500 ++++++ ...eGeneratorTests.TestBasicGrain.verified.cs | 178 +- ...GeneratorTests.TestBasicStruct.verified.cs | 1 + ...atorTests.TestClassNestedTypes.verified.cs | 2 + ...rTests.TestClassPrimitiveTypes.verified.cs | 2 + ...assPrimitiveTypesUsingFullName.verified.cs | 2 + ...s.TestClassReferenceProperties.verified.cs | 2 + ...rializersAnnotation.DotNet10_0.verified.cs | 401 +++++ ...erializersAnnotation.DotNet8_0.verified.cs | 402 +++++ ...ateMethodSerializersAnnotation.verified.cs | 176 +- ...thGenerateSerializerAnnotation.verified.cs | 3 + ...hInterfaceConstructorParameter.verified.cs | 2 + ...tClassWithNoPublicConstructors.verified.cs | 2 + ...hOptionalConstructorParameters.verified.cs | 2 + ...ssWithParameterizedConstructor.verified.cs | 4 + ...ActivatorConstructorAnnotation.verified.cs | 2 + ...torTests.TestCompoundTypeAlias.verified.cs | 4 + ...eneratorTests.TestGenericClass.verified.cs | 4 + ...ructorParameters.FieldAccessor.verified.cs | 4 + ...uctorParameters.UnsafeAccessor.verified.cs | 4 + ...stGrainComplexGrain.DotNet10_0.verified.cs | 701 ++++++++ ...estGrainComplexGrain.DotNet8_0.verified.cs | 701 ++++++++ ...torTests.TestGrainComplexGrain.verified.cs | 176 +- ...thInvokableBaseType.DotNet10_0.verified.cs | 504 ++++++ ...ithInvokableBaseType.DotNet8_0.verified.cs | 505 ++++++ ...AnnotatedWithInvokableBaseType.verified.cs | 178 +- ...WithResponseTimeout.DotNet10_0.verified.cs | 401 +++++ ...dWithResponseTimeout.DotNet8_0.verified.cs | 402 +++++ ...odAnnotatedWithResponseTimeout.verified.cs | 176 +- ...thDifferentKeyTypes.DotNet10_0.verified.cs | 1561 ++++++++++++++++ ...ithDifferentKeyTypes.DotNet8_0.verified.cs | 1565 +++++++++++++++++ ...TestGrainWithDifferentKeyTypes.verified.cs | 676 ++++++- ...hMultipleInterfaces.DotNet10_0.verified.cs | 561 ++++++ ...thMultipleInterfaces.DotNet8_0.verified.cs | 562 ++++++ ...estGrainWithMultipleInterfaces.verified.cs | 197 ++- ...urceGeneratorTests.TestRecords.verified.cs | 5 + ...cordsWithParameterIdAttributes.verified.cs | 5 + ...tDefaultMemberValuesAnnotation.verified.cs | 2 + ...ressReferenceTrackingAttribute.verified.cs | 2 + .../SelfWritingResponseFilterTests.cs | 302 ++++ .../SelfWritingResponseMessageTests.cs | 476 +++++ .../RpcResponses.Contracts.cs | 63 + test/Orleans.NativeAotSmoke/RpcResponses.cs | 1 + .../RpcResponsesModels.cs | 16 +- .../RpcResponseTests.cs | 270 +++ 68 files changed, 12723 insertions(+), 69 deletions(-) create mode 100644 src/Orleans.CodeGenerator/RpcResponseHolderGenerator.cs create mode 100644 src/Orleans.Serialization/Invocation/IRawResponseReader.cs create mode 100644 src/Orleans.Serialization/Invocation/IRawResponseWriter.cs create mode 100644 src/Orleans.Serialization/Invocation/IResponseInvokable.cs create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs create mode 100644 test/Orleans.Core.Tests/Serialization/SelfWritingResponseFilterTests.cs create mode 100644 test/Orleans.Core.Tests/Serialization/SelfWritingResponseMessageTests.cs diff --git a/docs/site/src/content/docs/implementation/serialization.md b/docs/site/src/content/docs/implementation/serialization.md index f12dafa46cd..3d50984d7b5 100644 --- a/docs/site/src/content/docs/implementation/serialization.md +++ b/docs/site/src/content/docs/implementation/serialization.md @@ -133,6 +133,12 @@ Arguments and result values use normal Orleans.Serialization codecs and copiers. ### Closed RPC response factories +For supported non-generic methods using the built-in task and value-task request bases, generated invokables also implement . The runtime selects this contract in the ordinary, incoming-filter, and observer paths. The invokable binds the selected serialization dependencies and rents a concrete, non-generic response holder after copying a mutable result. Immutable results retain their existing copy semantics. Isolation completes before incoming filters resume, and this path creates one pooled envelope for the successful result. + +Generated holders implement . The message serializer selects their direct writer before runtime-type codec lookup. Primitive holders call the existing static primitive codecs; reference holders use their bound concrete result codec and the message's serialization session. The wire representation retains the result-type header, field zero, end marker, null behavior, cycles, and shared references. Returning a holder to its pool clears both its result and its provider-owned factory binding. + +The receiving message serializer first consults using the result type from the wire header. Generated registrations reconstruct a bound holder directly. Compatibility paths retain ordinary response codecs for custom response/payload implementations, custom invokable bases, and unresolved generic contracts. Generated direct factories activate only when the selected result and response codecs/copiers match the canonical implementations, so explicit application behavior retains precedence. + For concrete `Task` and `ValueTask` method results, generated metadata supplies a closed response codec and copier graph for NativeAOT execution. The graph uses the concrete result implementations in and . Recursive result dependencies resolve with a construction caller after the response implementation has been allocated. Reference payload codecs and copiers preserve payload cycles and shared references, and the pooled response envelope retains the existing field and raw-message encoding. The graph also registers polymorphic codec and copier dispatch for the non-generic boundary used by the runtime client. That dispatch selects the closed implementation for the actual response type and preserves the identity of immutable completed and exception responses. The native smoke uses with `Response`, matching the runtime's response-copy boundary. @@ -141,7 +147,7 @@ Completed response transport uses the existing generated codec and its canonical The finite strict response graph supplies successful typed results and completed-response transport, plus immutable exception-envelope copying. Exception transport in an explicit context requires an codec and the declared exception and `Data` value type graph. Lookup reports that registration contract when it is missing. Ordinary metadata mode retains the existing exception codecs and their serialization-constructor support. -These supplemental registrations are defaults: explicit closed factory registrations take precedence in either configuration order. The automatic provider activates when runtime code generation is unavailable. JIT execution continues to use the existing serializer and copier selection, including application-provided payload implementations. Explicit factory and context registration also works in JIT execution. +These supplemental registrations are defaults: explicit closed factory registrations take precedence in either configuration order. The native closed dependency graph activates when runtime code generation is unavailable. Direct-holder factories and raw-reader registrations bind the selected provider implementations in both JIT and native execution. Custom application codec/copier selection uses the compatibility invocation and serialization path. Explicit factory and context registration also works in JIT execution. Ordinary metadata mode also supplies static response factories for non-generic generated result models. These factories construct the model's canonical generated codec and copier using their generated constructor signatures. Construction dependencies include the selected activator and declared codec/copier service contracts; source-known finite dependencies use closed factories, while interface contracts use ordinary metadata dispatch. This keeps construction within the provider's publication boundary and preserves canonical service identity and rollback. Default activation uses the existing reference- or value-type activator implementation, and custom activation retains its declared contract. Explicit context mode uses the complete finite dependency graph and validates each declared member shape. diff --git a/src/Orleans.CodeGenerator/InvokableGenerator.cs b/src/Orleans.CodeGenerator/InvokableGenerator.cs index af4ce145bd4..fbcf7c3f4f1 100644 --- a/src/Orleans.CodeGenerator/InvokableGenerator.cs +++ b/src/Orleans.CodeGenerator/InvokableGenerator.cs @@ -153,6 +153,37 @@ private ClassDeclarationSyntax GetClassDeclarationSyntax( GenerateTryCancelMethod(method, fieldDescriptions), GenerateIsCancellableProperty(method)); + if (method.AllTypeParameters.Count == 0 + && method.Method.ReturnType is INamedTypeSymbol { TypeArguments.Length: 1 } result + && baseClassType.OriginalDefinition.ToDisplayString() is "Orleans.Runtime.TaskRequest" or "Orleans.Runtime.Request" + && RpcResponseHolderGenerator.TryDescribe(_generationContext, result.TypeArguments[0], out _, out _)) + { + var type = result.TypeArguments[0].ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); + var factory = $"global::{RpcResponseHolderGenerator.GetNamespace(_generationContext.Compilation)}.{RpcResponseHolderGenerator.GetName(result.TypeArguments[0])}Factory"; + classDeclaration = classDeclaration.AddBaseListTypes(SimpleBaseType(ParseTypeName("global::Orleans.Serialization.Invocation.IResponseInvokable"))); + classDeclaration = classDeclaration.AddMembers(ParseMemberDeclaration($$""" + async global::System.Threading.Tasks.ValueTask + global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy( + global::Orleans.Serialization.Serializers.ICodecProvider provider, + global::Orleans.Serialization.Cloning.CopyContextPool contexts, + global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = {{factory}}.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + {{type}} value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } + """)!); + } + if (method.AllTypeParameters.Count > 0) { classDeclaration = SyntaxFactoryUtility.AddGenericTypeParameters(classDeclaration, method.AllTypeParameters); @@ -738,21 +769,24 @@ MemberDeclarationSyntax GetFieldDeclaration(InvokerFieldDescription description) { var methodTypeArguments = GetTypesArray(method, method.MethodTypeParameters.Select(p => p.Parameter)); var parameterTypes = GetTypesArray(method, method.Method.Parameters.Select(p => p.Type)); + var methodLookup = method.AllTypeParameters.Count == 0 + ? ParseExpression($"typeof({method.Method.ContainingType.ToTypeSyntax(method.TypeParameterSubstitutions)}).GetMethod({method.Method.Name.GetLiteralExpression()}, 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, {(method.Method.Parameters.Length == 0 ? "global::System.Type.EmptyTypes" : parameterTypes.ToString())}, null)") + : InvocationExpression( + IdentifierName("OrleansGeneratedCodeHelper").Member("GetMethodInfoOrDefault"), + ArgumentList(SeparatedList( + [ + Argument(TypeOfExpression(method.Method.ContainingType.ToTypeSyntax(method.TypeParameterSubstitutions))), + Argument(method.Method.Name.GetLiteralExpression()), + Argument(methodTypeArguments), + Argument(parameterTypes), + ]))); field = FieldDeclaration( VariableDeclaration( LibraryTypes.MethodInfo.ToTypeSyntax(), SingletonSeparatedList(VariableDeclarator(description.FieldName) .WithInitializer(EqualsValueClause( - InvocationExpression( - IdentifierName("OrleansGeneratedCodeHelper").Member("GetMethodInfoOrDefault"), - ArgumentList(SeparatedList( - [ - Argument(TypeOfExpression(method.Method.ContainingType.ToTypeSyntax(method.TypeParameterSubstitutions))), - Argument(method.Method.Name.GetLiteralExpression()), - Argument(methodTypeArguments), - Argument(parameterTypes), - ])))))))) + methodLookup))))) .AddModifiers(Token(SyntaxKind.PrivateKeyword), Token(SyntaxKind.StaticKeyword), Token(SyntaxKind.ReadOnlyKeyword)); } else diff --git a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs index 8465211acf4..f7695ed6474 100644 --- a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs +++ b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs @@ -118,6 +118,7 @@ internal static ImmutableArray Generate( } var supportedResults = new List(); + var responseHolders = new Dictionary(SymbolEqualityComparer.Default); var coveredConstructionTypes = new HashSet(SymbolEqualityComparer.Default); var metadataModelRoots = new List(); var argumentRoots = new List(); @@ -126,6 +127,8 @@ internal static ImmutableArray Generate( { var resultType = entry.Key; var method = entry.Value; + if (RpcResponseHolderGenerator.TryDescribe(services, resultType, out var holderCodec, out var holderCopier)) + responseHolders.Add(resultType, (holderCodec, holderCopier)); if (SerializerFactoryGenerator.TryCreate(services, [responseDefinition.Construct(resultType)], cancellationToken, out var candidate, out var failure)) { var dictionary = candidate.Registrations.Keys.OfType() @@ -172,7 +175,7 @@ internal static ImmutableArray Generate( } } - if (supportedResults.Count == 0 && metadataModelRoots.Count == 0 && argumentRoots.Count == 0 && !hasCompletionMethods) + if (supportedResults.Count == 0 && metadataModelRoots.Count == 0 && argumentRoots.Count == 0 && responseHolders.Count == 0 && !hasCompletionMethods) { return output.ToImmutable(); } @@ -193,6 +196,8 @@ internal static ImmutableArray Generate( var source = new StringBuilder(); source.AppendLine("// "); source.AppendLine("#nullable disable"); + source.AppendLine("using global::Orleans.Serialization.Codecs;"); + source.AppendLine("using global::Orleans.Serialization.GeneratedCodeHelpers;"); source.AppendLine($"[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof({generatedNamespace}.RpcResponseFactories))]"); source.AppendLine($"namespace {generatedNamespace}"); source.AppendLine("{"); @@ -200,6 +205,16 @@ internal static ImmutableArray Generate( source.AppendLine("{"); source.AppendLine("protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options)"); source.AppendLine("{"); + foreach (var holder in responseHolders) + { + var name = RpcResponseHolderGenerator.GetName(holder.Key); + var factory = name + "Factory"; + var type = holder.Key.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); + var resolve = $"{factory}.Resolve(provider)"; + source.AppendLine($"options.AddDefaultSerializerService<{factory}>(static provider => new {factory}(provider));"); + source.AppendLine($"options.AddDefaultSerializer<{name}>(static provider => {resolve}, static provider => {resolve});"); + source.AppendLine($"options.AddRawResponseReader<{type}>(static provider => {resolve});"); + } source.AppendLine("#if NET5_0_OR_GREATER"); source.AppendLine("if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) return;"); if (graph is not null) @@ -258,6 +273,10 @@ internal static ImmutableArray Generate( source.AppendLine("}"); source.AppendLine("}"); source.AppendLine("}"); + foreach (var holder in responseHolders) + { + source.AppendLine(RpcResponseHolderGenerator.Generate(services, holder.Key, holder.Value.Codec, holder.Value.Copier)); + } source.AppendLine("}"); var unit = CSharpSyntaxTree.ParseText(source.ToString(), options: new CSharpParseOptions(preprocessorSymbols: ["NET5_0_OR_GREATER"]), diff --git a/src/Orleans.CodeGenerator/RpcResponseHolderGenerator.cs b/src/Orleans.CodeGenerator/RpcResponseHolderGenerator.cs new file mode 100644 index 00000000000..5a7c9f27d77 --- /dev/null +++ b/src/Orleans.CodeGenerator/RpcResponseHolderGenerator.cs @@ -0,0 +1,219 @@ +using System.Text; +using Microsoft.CodeAnalysis; +using Orleans.CodeGenerator.Hashing; +using Orleans.CodeGenerator.SyntaxGeneration; + +namespace Orleans.CodeGenerator; + +internal static class RpcResponseHolderGenerator +{ + internal static string GetName(ITypeSymbol resultType) + => $"RpcResponse_{HexConverter.ToString(XxHash32.Hash(Encoding.UTF8.GetBytes(resultType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat))))}"; + + internal static string GetNamespace(Compilation compilation) + => $"{GeneratedCodeUtilities.CodeGeneratorName}.{Identifier.SanitizeIdentifierName(compilation.AssemblyName ?? "Assembly").EscapeIdentifier()}"; + + internal static bool TryDescribe(IGeneratorServices services, ITypeSymbol resultType, out string codec, out string copier) + { + codec = copier = ""; + if (ContainsParameter(resultType)) return false; + if (SerializerFactoryGenerator.TryCreate(services, [resultType], CancellationToken.None, out var graph, out _)) + { + if (graph.Registrations.Keys.OfType().Any(type => + SymbolEqualityComparer.Default.Equals(type.OriginalDefinition, services.Compilation.GetTypeByMetadataName("System.Collections.Generic.Dictionary`2")))) + return false; + var registration = graph.Registrations[resultType.WithNullableAnnotation(NullableAnnotation.None)]; + codec = registration.Codec; + copier = registration.Copier; + return true; + } + + if (resultType is INamedTypeSymbol named + && SerializerFactoryGenerator.CreateRpcModelRoot(services, named, CancellationToken.None) is { } partial) + { + var registration = partial.Registrations[resultType.WithNullableAnnotation(NullableAnnotation.None)]; + if (!SymbolEqualityComparer.Default.Equals(named.ContainingAssembly, services.Compilation.Assembly)) + { + var codecType = services.Compilation.GetTypeByMetadataName($"{SerializerGenerator.GetGeneratedNamespaceName(named)}.{SerializerGenerator.GetSimpleClassName(named.Name)}"); + if (codecType is null || ReferencedSerializerImplementation.Validate(codecType) is not null) + return false; + } + codec = registration.Codec; + copier = registration.Copier; + return true; + } + + return false; + } + + internal static string Generate(IGeneratorServices services, ITypeSymbol resultType, string codec, string copier) + { + var type = resultType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); + var name = GetName(resultType); + var factory = name + "Factory"; + var shallow = services.LibraryTypes.IsShallowCopyable(resultType); + var staticCodec = services.LibraryTypes.StaticCodecs.FindByUnderlyingType(resultType)?.CodecType; + var staticWrite = staticCodec?.GetMembers("WriteField").OfType() + .Any(static method => method.IsStatic && method.Parameters.Length == 3) == true; + var writeResult = staticWrite + ? $"{codec}.WriteField(ref writer, 0, value);" + : $"_codec.WriteField(ref writer, 0, typeof({type}), value);"; + var readResult = staticCodec is not null + ? $"{codec}.ReadValue(ref reader, field)" + : "_codec.ReadValue(ref reader, field)"; + var staticCopier = services.LibraryTypes.StaticCopiers.FindByUnderlyingType(resultType)?.CopierType; + var copierReceiver = staticCopier?.GetMembers("DeepCopy").OfType().Any(static method => method.IsStatic) == true + ? copier : "_copier"; + var copied = shallow ? "value" : $"{copierReceiver}.DeepCopy(value, context)"; + var writeBody = resultType.IsValueType && resultType.OriginalDefinition.SpecialType != SpecialType.System_Nullable_T + ? writeResult : $"if (value is not null) {{ {writeResult} }}"; + var writeEnvelopeBody = resultType.IsValueType && resultType.OriginalDefinition.SpecialType != SpecialType.System_Nullable_T + ? writeResult.Replace("value);", "value.Value);") + : $"if (value.Value is not null) {{ {writeResult.Replace("value);", "value.Value);")} }}"; + var holderWrite = staticWrite + ? $"writer.WriteStartObject(0, null, typeof({type})); {writeBody.Replace("value", "Value")} writer.WriteEndObject();" + : "_factory.WriteResult(ref writer, Value);"; + var rentCopiedBody = shallow + ? $"return {name}.Rent(value, this);" + : $"using var context = contexts.GetContext(); return {name}.Rent({copied}, this);"; + return $$""" + internal sealed class {{name}} : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal {{type}} Value; + private {{factory}} _factory; + public {{name}}() { } + internal static {{name}} Rent({{type}} value, {{factory}} factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated<{{name}}>(); + result.Value = value; + result._factory = factory; + return result; + } + public override object Result { get => Value; set => Value = ({{type}})value; } + public override global::System.Exception Exception + { + get => null; + set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); + } + public override global::System.Type GetSimpleResultType() => typeof({{type}}); + public override T GetResult() + { + if (typeof(T) == typeof({{type}})) + return global::System.Runtime.CompilerServices.Unsafe.As<{{type}}, T>(ref Value); + return (T)(object)Value; + } + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) throw new global::System.ObjectDisposedException(GetType().Name); + {{holderWrite}} + } + public override void Dispose() + { + if (_factory is null) return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class {{factory}} : global::Orleans.Serialization.Invocation.ResponseCodec, + global::Orleans.Serialization.Codecs.IFieldCodec<{{name}}>, + global::Orleans.Serialization.Cloning.IDeepCopier<{{name}}>, + global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly {{codec}} _codec; + private readonly {{copier}} _copier; + public bool IsSupported { get; } + internal static {{factory}} Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec<{{type}}>(); + provider.GetDeepCopier<{{type}}>(); + provider.GetCodec>(); + provider.GetDeepCopier>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService<{{factory}}>(null, provider); + } + public {{factory}}(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec<{{type}}>() as {{codec}}; + _copier = provider.GetDeepCopier<{{type}}>() as {{copier}}; + var responseCodec = provider.GetCodec>(); + var responseCopier = provider.GetDeepCopier>(); + IsSupported = _codec is not null && _copier is not null + && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec<{{type}}, {{codec}}> + || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec<{{type}}, global::Orleans.Serialization.Codecs.IFieldCodec<{{type}}>>) + && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier<{{type}}, {{copier}}> + || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier<{{type}}, global::Orleans.Serialization.Cloning.IDeepCopier<{{type}}>>); + } + internal global::Orleans.Serialization.Invocation.Response RentCopied({{type}} value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + {{rentCopiedBody}} + } + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public {{name}} DeepCopy({{name}} input, global::Orleans.Serialization.Cloning.CopyContext context) + => input is null ? null : {{name}}.Rent({{(shallow ? "input.Value" : $"{copierReceiver}.DeepCopy(input.Value, context)")}}, this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, {{type}} value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof({{type}})); + {{writeBody}} + writer.WriteEndObject(); + } + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) + => WriteResult(ref writer, (({{name}})value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw( + ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + => ReadResult(ref reader, ref field); + private {{name}} ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = {{name}}.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = {{readResult}}; + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + return result; + } + catch + { + result.Dispose(); + throw; + } + } + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, {{name}} value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response<{{type}}>)); + {{writeEnvelopeBody}} + writer.WriteEndObject(); + } + public {{name}} ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference<{{name}}, TInput>(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + """; + } + + private static bool ContainsParameter(ITypeSymbol type) + => type is ITypeParameterSymbol or IErrorTypeSymbol + || type is IArrayTypeSymbol array && ContainsParameter(array.ElementType) + || type is INamedTypeSymbol named && (named.TypeArguments.Any(ContainsParameter) + || named.ContainingType is { } containing && ContainsParameter(containing)); +} diff --git a/src/Orleans.Core/Core/GrainMethodInvoker.cs b/src/Orleans.Core/Core/GrainMethodInvoker.cs index ec3a0a6673a..126ecae08ca 100644 --- a/src/Orleans.Core/Core/GrainMethodInvoker.cs +++ b/src/Orleans.Core/Core/GrainMethodInvoker.cs @@ -6,6 +6,8 @@ using System.Threading.Tasks; using Orleans.Serialization; using Orleans.Serialization.Invocation; +using Orleans.Serialization.Cloning; +using Orleans.Serialization.Serializers; namespace Orleans.Runtime { @@ -20,6 +22,8 @@ internal sealed class GrainMethodInvoker : IIncomingGrainCallContext private readonly InterfaceToImplementationMappingCache interfaceToImplementationMapping; private readonly DeepCopier responseCopier; private readonly IGrainContext grainContext; + private readonly ICodecProvider codecProvider; + private readonly CopyContextPool copyContexts; private int stage; /// @@ -31,13 +35,17 @@ internal sealed class GrainMethodInvoker : IIncomingGrainCallContext /// The invocation interceptors. /// The implementation map. /// The response copier. + /// The provider for generated response dependencies. + /// The pool for isolating source-known invocation results. public GrainMethodInvoker( Message message, IGrainContext grainContext, IInvokable request, List filters, InterfaceToImplementationMappingCache interfaceToImplementationMapping, - DeepCopier responseCopier) + DeepCopier responseCopier, + ICodecProvider codecProvider, + CopyContextPool copyContexts) { this.message = message; this.request = request; @@ -45,6 +53,8 @@ public GrainMethodInvoker( this.filters = filters; this.interfaceToImplementationMapping = interfaceToImplementationMapping; this.responseCopier = responseCopier; + this.codecProvider = codecProvider; + this.copyContexts = copyContexts; } public IInvokable Request => request; @@ -124,7 +134,9 @@ public async Task Invoke() { // Finally call the root-level invoker. stage++; - this.Response = await request.Invoke(); + this.Response = request is IResponseInvokable direct + ? await direct.InvokeAndCopy(codecProvider, copyContexts, responseCopier) + : await request.Invoke(); // Propagate exceptions to other filters. if (this.Response.Exception is { } exception) @@ -132,7 +144,8 @@ public async Task Invoke() ExceptionDispatchInfo.Capture(exception).Throw(); } - this.Response = this.responseCopier.Copy(this.Response); + if (request is not IResponseInvokable) + this.Response = this.responseCopier.Copy(this.Response); return; } diff --git a/src/Orleans.Core/Messaging/MessageSerializer.cs b/src/Orleans.Core/Messaging/MessageSerializer.cs index 38c13fe8f4c..bdb21fd0d69 100644 --- a/src/Orleans.Core/Messaging/MessageSerializer.cs +++ b/src/Orleans.Core/Messaging/MessageSerializer.cs @@ -21,6 +21,7 @@ internal sealed class MessageSerializer : IDisposable private const int MessageSizeHint = 4096; private const int MaxRequestContextInitialCapacity = 1024; private readonly Dictionary _rawResponseCodecs = []; + private readonly Dictionary _rawResponseReaders = []; private readonly CodecProvider _codecProvider; private readonly IFieldCodec _activationAddressCodec; private readonly CachingSiloAddressCodec _readerSiloAddressCodec = new(); @@ -84,6 +85,15 @@ internal void ReadBodyObject(Message message, MessageReadRequest readRequest) if (message.Result == ResponseTypes.Success) { message.Result = ResponseTypes.None; // reset raw response indicator + var fieldType = field.FieldType!; + if (!_rawResponseReaders.TryGetValue(fieldType, out var registered) + && _codecProvider.TryGetRawResponseReader(fieldType, out registered)) + _rawResponseReaders.Add(fieldType, registered); + if (registered is not null) + { + message._bodyObject = registered.ReadRaw(ref reader, ref field); + return; + } if (!_rawResponseCodecs.TryGetValue(field.FieldType!, out var rawCodec)) rawCodec = GetRawCodec(field.FieldType!); message._bodyObject = rawCodec.ReadRaw(ref reader, ref field); @@ -112,12 +122,18 @@ private ResponseCodec GetRawCodec(Type fieldType) var headers = message.Headers; IFieldCodec? bodyCodec = null; ResponseCodec? rawCodec = null; + IRawResponseWriter? rawWriter = null; var bodyObject = message._bodyObject; var readRequest = bodyObject as MessageReadRequest; if (readRequest is not null) { headers.ResponseType = readRequest._originalResponseType; } + else if (headers.ResponseType is ResponseTypes.None && bodyObject is Response and IRawResponseWriter responseWriter) + { + rawWriter = responseWriter; + headers.ResponseType = ResponseTypes.Success; + } else if (bodyObject is not null) { bodyCodec = _codecProvider.GetCodec(bodyObject.GetType()); @@ -144,12 +160,13 @@ private ResponseCodec GetRawCodec(Type fieldType) bodyLength = readRequest.BodyLength; readRequest.Body.CopyTo(buffer); } - else if (bodyCodec is not null) + else if (bodyCodec is not null || rawWriter is not null) { Debug.Assert(bodyObject is not null); writer = Writer.Create(buffer, _serializationSession); - if (rawCodec != null) rawCodec.WriteRaw(ref writer, bodyObject); - else bodyCodec.WriteField(ref writer, 0, null, bodyObject); + if (rawWriter is not null) rawWriter.WriteRaw(ref writer); + else if (rawCodec != null) rawCodec.WriteRaw(ref writer, bodyObject); + else bodyCodec!.WriteField(ref writer, 0, null, bodyObject); writer.Commit(); bodyLength = writer.Position; } diff --git a/src/Orleans.Core/Runtime/InvokableObjectManager.cs b/src/Orleans.Core/Runtime/InvokableObjectManager.cs index f45a8881aa6..c48e1d30c1e 100644 --- a/src/Orleans.Core/Runtime/InvokableObjectManager.cs +++ b/src/Orleans.Core/Runtime/InvokableObjectManager.cs @@ -385,15 +385,23 @@ private async Task ProcessMessageAsync(Message message) Response response; if (filters is { Count: > 0 } || LocalObject is IIncomingGrainCallFilter) { - var invoker = new GrainMethodInvoker(message, this, request, filters, _manager._interfaceToImplementationMapping, _manager._responseCopier); + var invoker = new GrainMethodInvoker(message, this, request, filters, _manager._interfaceToImplementationMapping, + _manager._responseCopier, _manager.runtimeClient.ServiceProvider.GetRequiredService(), + _manager.runtimeClient.ServiceProvider.GetRequiredService()); await invoker.Invoke(); response = invoker.Response!; } else { - response = await request.Invoke(); - // The copier preserves the null state of its input. - response = _manager._responseCopier.Copy(response)!; + if (request is IResponseInvokable direct) + response = await direct.InvokeAndCopy( + _manager.runtimeClient.ServiceProvider.GetRequiredService(), + _manager.runtimeClient.ServiceProvider.GetRequiredService(), _manager._responseCopier); + else + { + response = await request.Invoke(); + response = _manager._responseCopier.Copy(response)!; + } } if (message.Direction != Message.Directions.OneWay) diff --git a/src/Orleans.Runtime/Core/InsideRuntimeClient.cs b/src/Orleans.Runtime/Core/InsideRuntimeClient.cs index 8ec03015ce6..2b2a84a6576 100644 --- a/src/Orleans.Runtime/Core/InsideRuntimeClient.cs +++ b/src/Orleans.Runtime/Core/InsideRuntimeClient.cs @@ -17,6 +17,8 @@ using Orleans.Runtime.Messaging; using Orleans.Serialization; using Orleans.Serialization.Invocation; +using Orleans.Serialization.Cloning; +using Orleans.Serialization.Serializers; using Orleans.Storage; using static Orleans.Internal.StandardExtensions; @@ -52,6 +54,8 @@ internal sealed partial class InsideRuntimeClient : IRuntimeClient, ILifecyclePa private Task? callbackTimerTask; private readonly MessagingTrace messagingTrace; private readonly DeepCopier responseCopier; + private readonly ICodecProvider responseCodecProvider; + private readonly CopyContextPool responseCopyContexts; public InsideRuntimeClient( ILocalSiloDetails siloDetails, @@ -83,6 +87,8 @@ public InsideRuntimeClient( this.messagingOptions = messagingOptions.Value; this.messagingTrace = messagingTrace; this.responseCopier = deepCopier.GetCopier(); + this.responseCodecProvider = serviceProvider.GetRequiredService(); + this.responseCopyContexts = serviceProvider.GetRequiredService(); var period = Max(TimeSpan.FromMilliseconds(1), Min(this.messagingOptions.ResponseTimeout, TimeSpan.FromSeconds(1))); this.callbackTimer = new PeriodicTimer(period, timeProvider); @@ -315,15 +321,20 @@ public async Task Invoke(IGrainContext target, Message message) CancellationSourcesExtension.RegisterCancellationTokens(target, invokable); if (GrainCallFilters is { Count: > 0 } || target.GrainInstance is IIncomingGrainCallFilter) { - var invoker = new GrainMethodInvoker(message, target, invokable, GrainCallFilters, this.interfaceToImplementationMapping, this.responseCopier); + var invoker = new GrainMethodInvoker(message, target, invokable, GrainCallFilters, this.interfaceToImplementationMapping, + this.responseCopier, this.responseCodecProvider, this.responseCopyContexts); await invoker.Invoke(); response = invoker.Response!; } else { - response = await invokable.Invoke(); - // The copier preserves the null state of its input. - response = this.responseCopier.Copy(response)!; + if (invokable is IResponseInvokable direct) + response = await direct.InvokeAndCopy(this.responseCodecProvider, this.responseCopyContexts, this.responseCopier); + else + { + response = await invokable.Invoke(); + response = this.responseCopier.Copy(response)!; + } } invokable.Dispose(); diff --git a/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs b/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs index f57bfab0c07..a860081f3fa 100644 --- a/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs +++ b/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs @@ -7,6 +7,7 @@ using Orleans.Serialization.Activators; using Orleans.Serialization.Cloning; using Orleans.Serialization.Codecs; +using Orleans.Serialization.Invocation; using Orleans.Serialization.Serializers; using Orleans.Serialization.TypeSystem; @@ -47,6 +48,19 @@ public sealed class TypeManifestOptions internal Dictionary> CodecFactories { get; } = new(); internal Dictionary> CopierFactories { get; } = new(); internal Dictionary> SerializerServiceFactories { get; } = new(); + internal Dictionary> RawResponseReaderFactories { get; } = new(); + + /// + /// Registers a statically constructed raw response reader for a closed invocation result type. + /// + /// The invocation result type encoded in the wire header. + /// The reader factory. + /// The first reader registration for a result type is used. + public void AddRawResponseReader(Func factory) + { + if (factory is null) throw new ArgumentNullException(nameof(factory)); + RawResponseReaderFactories.TryAdd(typeof(TResult), factory); + } private readonly HashSet _defaultSerializerServices = new(); internal HashSet ContextTypes { get; } = new(); diff --git a/src/Orleans.Serialization/Invocation/IRawResponseReader.cs b/src/Orleans.Serialization/Invocation/IRawResponseReader.cs new file mode 100644 index 00000000000..84d3b4ee8bf --- /dev/null +++ b/src/Orleans.Serialization/Invocation/IRawResponseReader.cs @@ -0,0 +1,24 @@ +using Orleans.Serialization.Buffers; +using Orleans.Serialization.WireProtocol; + +namespace Orleans.Serialization.Invocation; + +/// +/// Reads raw invocation responses for a statically registered result type. +/// +public interface IRawResponseReader +{ + /// + /// Gets whether this reader preserves the selected codec's raw response contract. + /// + bool IsSupported { get; } + + /// + /// Reads a raw response using the supplied message session. + /// + /// The reader input type. + /// The message body reader. + /// The result-type field header. + /// The reconstructed response. + Response ReadRaw(ref Reader reader, scoped ref Field field); +} diff --git a/src/Orleans.Serialization/Invocation/IRawResponseWriter.cs b/src/Orleans.Serialization/Invocation/IRawResponseWriter.cs new file mode 100644 index 00000000000..4216c45b326 --- /dev/null +++ b/src/Orleans.Serialization/Invocation/IRawResponseWriter.cs @@ -0,0 +1,17 @@ +using System.Buffers; +using Orleans.Serialization.Buffers; + +namespace Orleans.Serialization.Invocation; + +/// +/// Writes an invocation response directly using its bound serialization dependencies. +/// +public interface IRawResponseWriter +{ + /// + /// Writes the existing raw response representation into the supplied message session. + /// + /// The output buffer writer type. + /// The message body writer. + void WriteRaw(ref Writer writer) where TBufferWriter : IBufferWriter; +} diff --git a/src/Orleans.Serialization/Invocation/IResponseInvokable.cs b/src/Orleans.Serialization/Invocation/IResponseInvokable.cs new file mode 100644 index 00000000000..b039ccf9f4f --- /dev/null +++ b/src/Orleans.Serialization/Invocation/IResponseInvokable.cs @@ -0,0 +1,20 @@ +using System.Threading.Tasks; +using Orleans.Serialization.Cloning; +using Orleans.Serialization.Serializers; + +namespace Orleans.Serialization.Invocation; + +/// +/// Invokes a source-known method and creates a response whose result satisfies the runtime copy boundary. +/// +public interface IResponseInvokable +{ + /// + /// Invokes the method and isolates its successful result before returning to incoming filters. + /// + /// The invocation's serialization provider. + /// The invocation's copy-context pool. + /// The compatibility copier for custom response implementations. + /// The isolated response. + ValueTask InvokeAndCopy(ICodecProvider codecProvider, CopyContextPool copyContextPool, DeepCopier responseCopier); +} diff --git a/src/Orleans.Serialization/Invocation/Pools/ResponsePool.cs b/src/Orleans.Serialization/Invocation/Pools/ResponsePool.cs index 1b3adf82b95..e5ab2deea3c 100644 --- a/src/Orleans.Serialization/Invocation/Pools/ResponsePool.cs +++ b/src/Orleans.Serialization/Invocation/Pools/ResponsePool.cs @@ -19,6 +19,25 @@ public static class ResponsePool /// The value to return to the pool. public static void Return(Response obj) => TypedPool.Pool.Return(obj); + /// + /// Rents a generated concrete response holder. + /// + /// The concrete response type. + /// A reset response holder. + public static TResponse GetGenerated() where TResponse : Response, new() => GeneratedPool.Pool.Get(); + + /// + /// Returns a generated response after its value and provider dependencies have been cleared. + /// + /// The concrete response type. + /// The reset response. + public static void ReturnGenerated(TResponse response) where TResponse : Response, new() => GeneratedPool.Pool.Return(response); + + private static class GeneratedPool where TResponse : Response, new() + { + public static readonly ConcurrentObjectPool Pool = new(); + } + private static class TypedPool { public static readonly ConcurrentObjectPool> Pool = new(); diff --git a/src/Orleans.Serialization/Serializers/CodecProvider.cs b/src/Orleans.Serialization/Serializers/CodecProvider.cs index 22df77d3f70..6525a78821d 100644 --- a/src/Orleans.Serialization/Serializers/CodecProvider.cs +++ b/src/Orleans.Serialization/Serializers/CodecProvider.cs @@ -70,6 +70,29 @@ public CodecProvider(IServiceProvider serviceProvider, IOptions public IServiceProvider Services => _manifest.SerializerServiceFactories.Count == 0 ? _serviceProvider : _constructionServices; + /// + /// Resolves a statically registered reader for a raw invocation result. + /// + /// The closed result type from the message field header. + /// The registered reader, when supported by the selected response codec. + /// Whether a compatible registered reader is available. + public bool TryGetRawResponseReader(Type resultType, [NotNullWhen(true)] out Invocation.IRawResponseReader? reader) + { + if (resultType is null) throw new ArgumentNullException(nameof(resultType)); + if (_manifest.RawResponseReaderFactories.TryGetValue(resultType, out var factory)) + { + var candidate = factory(this); + if (candidate.IsSupported) + { + reader = candidate; + return true; + } + } + + reader = null; + return false; + } + private void Initialize() { lock (_initializationLock) diff --git a/src/api/Orleans.Runtime/Orleans.Runtime.cs b/src/api/Orleans.Runtime/Orleans.Runtime.cs index edaf0437875..10da216e275 100644 --- a/src/api/Orleans.Runtime/Orleans.Runtime.cs +++ b/src/api/Orleans.Runtime/Orleans.Runtime.cs @@ -1486,6 +1486,7 @@ namespace OrleansCodeGen.Orleans.LeaseProviders [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [System.ComponentModel.Description("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed partial class Codec_Invokable_ILeaseProvider_GrainReference_5C7B2877 : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Codecs.IFieldCodec { public Codec_Invokable_ILeaseProvider_GrainReference_5C7B2877(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) { } @@ -1504,6 +1505,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [System.ComponentModel.Description("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed partial class Codec_Invokable_ILeaseProvider_GrainReference_ACF8E0DD : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Codecs.IFieldCodec { public Codec_Invokable_ILeaseProvider_GrainReference_ACF8E0DD(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) { } @@ -1522,6 +1524,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [System.ComponentModel.Description("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed partial class Codec_Invokable_ILeaseProvider_GrainReference_F2BF11D0 : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Codecs.IFieldCodec { public Codec_Invokable_ILeaseProvider_GrainReference_F2BF11D0(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) { } @@ -1540,6 +1543,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [System.ComponentModel.Description("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed partial class Copier_Invokable_ILeaseProvider_GrainReference_5C7B2877 : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IDeepCopier { public Copier_Invokable_ILeaseProvider_GrainReference_5C7B2877(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) { } @@ -1550,6 +1554,7 @@ public Copier_Invokable_ILeaseProvider_GrainReference_5C7B2877(global::Orleans.S [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [System.ComponentModel.Description("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed partial class Copier_Invokable_ILeaseProvider_GrainReference_ACF8E0DD : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IDeepCopier { public Copier_Invokable_ILeaseProvider_GrainReference_ACF8E0DD(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) { } @@ -1560,6 +1565,7 @@ public Copier_Invokable_ILeaseProvider_GrainReference_ACF8E0DD(global::Orleans.S [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [System.ComponentModel.Description("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed partial class Copier_Invokable_ILeaseProvider_GrainReference_F2BF11D0 : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IDeepCopier { public Copier_Invokable_ILeaseProvider_GrainReference_F2BF11D0(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) { } @@ -1672,6 +1678,7 @@ namespace OrleansCodeGen.Orleans.Runtime [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [System.ComponentModel.Description("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed partial class Codec_ClusterMember : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Codecs.IFieldCodec { public Codec_ClusterMember(global::Orleans.Serialization.Activators.IActivator _activator, global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) { } @@ -1690,6 +1697,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [System.ComponentModel.Description("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed partial class Codec_ClusterMembershipSnapshot : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Codecs.IFieldCodec { public Codec_ClusterMembershipSnapshot(global::Orleans.Serialization.Activators.IActivator _activator, global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) { } @@ -1708,6 +1716,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [System.ComponentModel.Description("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed partial class Codec_ClusterMembershipUpdate : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Codecs.IFieldCodec { public Codec_ClusterMembershipUpdate(global::Orleans.Serialization.Activators.IActivator _activator, global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) { } @@ -1729,6 +1738,7 @@ namespace OrleansCodeGen.Orleans.Runtime.MembershipService [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [System.ComponentModel.Description("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed partial class Codec_OrleansClusterConnectivityCheckFailedException : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Codecs.IFieldCodec { public Codec_OrleansClusterConnectivityCheckFailedException(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) { } @@ -1747,6 +1757,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [System.ComponentModel.Description("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed partial class Codec_OrleansMissingMembershipEntryException : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Codecs.IFieldCodec { public Codec_OrleansMissingMembershipEntryException(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) { } @@ -1765,6 +1776,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [System.ComponentModel.Description("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed partial class Copier_OrleansClusterConnectivityCheckFailedException : global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.ExceptionCopier { public Copier_OrleansClusterConnectivityCheckFailedException(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) : base(default(Serialization.Serializers.ICodecProvider)!) { } @@ -1773,6 +1785,7 @@ public Copier_OrleansClusterConnectivityCheckFailedException(global::Orleans.Ser [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [System.ComponentModel.Description("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed partial class Copier_OrleansMissingMembershipEntryException : global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.ExceptionCopier { public Copier_OrleansMissingMembershipEntryException(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) : base(default(Serialization.Serializers.ICodecProvider)!) { } @@ -1784,6 +1797,7 @@ namespace OrleansCodeGen.Orleans.Runtime.MembershipService.SiloMetadata [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [System.ComponentModel.Description("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed partial class Codec_SiloMetadata : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec, global::Orleans.Serialization.Serializers.IBaseCodec { public Codec_SiloMetadata(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) { } @@ -1802,6 +1816,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [System.ComponentModel.Description("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed partial class Copier_SiloMetadata : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier, global::Orleans.Serialization.Cloning.IBaseCopier { public void DeepCopy(global::Orleans.Runtime.MembershipService.SiloMetadata.SiloMetadata input, global::Orleans.Runtime.MembershipService.SiloMetadata.SiloMetadata output, global::Orleans.Serialization.Cloning.CopyContext context) { } diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index dada8fc95a6..d1ad3bcc1e6 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -3133,6 +3133,66 @@ public interface IChild : IParent Assert.DoesNotContain("Response", source); } + [Theory] + [InlineData("Task")] + [InlineData("ValueTask")] + public async Task RpcResponseHoldersGenerateDirectPrimitiveWritesAndCopiedInvocations(string returnType) + { + var compilation = await CreateCompilation($$""" + using Orleans; + using System.Threading.Tasks; + namespace TestProject; + public interface IWriter : IGrainWithIntegerKey { {{returnType}} Get(); } + """); + var result = RunSourceGenerator(compilation); + Assert.Empty(result.Diagnostics); + var response = Assert.Single(result.GeneratedSources, static item => item.HintName.EndsWith(".orleans.rpcresponses.g.cs", StringComparison.Ordinal)).SourceText.ToString(); + var proxy = Assert.Single(result.GeneratedSources, static item => item.HintName.Contains(".orleans.proxy.", StringComparison.Ordinal)).SourceText.ToString(); + Assert.Contains("IRawResponseWriter", response); + Assert.Contains("IRawResponseReader", response); + Assert.Contains("Int32Codec.WriteField(ref writer, 0, Value)", response); + Assert.Contains("ResponsePool.GetGenerated<", response); + Assert.Contains("_factory = null", response); + Assert.Contains("options.AddRawResponseReader", response); + Assert.Contains("IResponseInvokable.InvokeAndCopy", proxy); + Assert.Contains("factory.RentCopied(value, contexts)", proxy); + Assert.DoesNotContain("MakeGenericType", response); + var holders = CSharpSyntaxTree.ParseText(response, cancellationToken: TestContext.Current.CancellationToken) + .GetCompilationUnitRoot(TestContext.Current.CancellationToken).DescendantNodes() + .OfType().Where(static type => type.BaseList?.ToString().Contains("IRawResponseWriter", StringComparison.Ordinal) == true).ToArray(); + var holder = Assert.Single(holders); + Assert.Null(holder.TypeParameterList); + var output = compilation.AddReferences(MetadataReference.CreateFromFile(typeof(Microsoft.Extensions.Options.IConfigureOptions<>).Assembly.Location)) + .AddSyntaxTrees(result.GeneratedSources.Select(static item => CSharpSyntaxTree.ParseText(item.SourceText, + options: new CSharpParseOptions().WithPreprocessorSymbols("NET5_0_OR_GREATER"), path: item.HintName))); + Assert.Empty(output.GetDiagnostics(TestContext.Current.CancellationToken).Where(static item => item.Severity == DiagnosticSeverity.Error)); + } + + [Fact] + public async Task RpcResponseHoldersKeepCustomAndGenericInvokerContracts() + { + var compilation = await CreateCompilation(""" + using System; + using System.Threading.Tasks; + using Orleans; + using Orleans.Runtime; + namespace TestProject; + [InvokableBaseType(typeof(GrainReference), typeof(Task<>), typeof(CustomRequest<>))] + [AttributeUsage(AttributeTargets.Method)] + public sealed class CustomAttribute : Attribute { } + public abstract class CustomRequest : TaskRequest { } + public interface ICompatibility : IGrainWithIntegerKey + { + [Custom] Task Custom(); + Task Generic(); + } + """); + var result = RunSourceGenerator(compilation); + Assert.Empty(result.Diagnostics); + var proxy = Assert.Single(result.GeneratedSources, static item => item.HintName.Contains(".orleans.proxy.", StringComparison.Ordinal)).SourceText.ToString(); + Assert.DoesNotContain("IResponseInvokable", proxy); + } + private static GeneratorRunResult RunSourceGenerator( CSharpCompilation compilation, IReadOnlyDictionary? globalOptions = null) @@ -3170,6 +3230,10 @@ private static async Task AssertSuccessfulSourceGeneration(string code, string? var supportsGenericAccessors = SourceGeneratorOptionsParser.ParseOptions(TestCompilationHelper.CreateOptionsProvider().GlobalOptions).SupportsGenericUnsafeAccessors; snapshot = snapshot.UseFileName($"{nameof(OrleansSourceGeneratorTests)}.{snapshotName}.{(supportsGenericAccessors ? "UnsafeAccessor" : "FieldAccessor")}"); } + if (generatedSource.Contains("global::Orleans.Serialization.Invocation.IRawResponseWriter", StringComparison.Ordinal)) + { + snapshot = snapshot.UniqueForRuntimeAndVersion(); + } await snapshot; } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestAlias.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestAlias.verified.cs index 8d745837d8a..50873b581a6 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestAlias.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestAlias.verified.cs @@ -11,6 +11,7 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_MyTypeAliasStruct : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IValueSerializer { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.MyTypeAliasStruct); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClass.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClass.verified.cs index 34deeb5e3b7..3fc4b7e8f6b 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClass.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClass.verified.cs @@ -11,6 +11,7 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_DemoData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DemoData); @@ -79,6 +80,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_DemoData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithAnnotatedFields.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithAnnotatedFields.verified.cs index 5fc7297b5d8..f90b5bce847 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithAnnotatedFields.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithAnnotatedFields.verified.cs @@ -11,6 +11,7 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_DemoDataWithFields : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DemoDataWithFields); @@ -99,6 +100,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_DemoDataWithFields : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Activators.IActivator _activator; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithDifferentAccessModifiers.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithDifferentAccessModifiers.verified.cs index e523ef25d63..edeff1eb256 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithDifferentAccessModifiers.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithDifferentAccessModifiers.verified.cs @@ -11,6 +11,7 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_PublicDemoData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.PublicDemoData); @@ -79,6 +80,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_PublicDemoData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -108,6 +110,7 @@ internal sealed class Activator_PublicDemoData : global::Orleans.Serialization.A } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] internal sealed class Codec_InternalDemoData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.InternalDemoData); @@ -176,6 +179,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] internal sealed class Copier_InternalDemoData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithInheritance.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithInheritance.verified.cs index 5b0ac2e2fa5..5cfc9ef7eaf 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithInheritance.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithInheritance.verified.cs @@ -11,6 +11,7 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_BaseData : global::Orleans.Serialization.Serializers.AbstractTypeSerializer { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -43,6 +44,7 @@ public override void Deserialize(ref global::Orleans.Serialization } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_BaseData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -59,6 +61,7 @@ public void DeepCopy(global::TestProject.BaseData input, global::TestProject.Bas } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_DerivedData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DerivedData); @@ -140,6 +143,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_DerivedData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly OrleansCodeGen.TestProject.Copier_BaseData _baseTypeCopier; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithoutNamespace.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithoutNamespace.verified.cs index 561bf0a11cc..fc1d4b3a34d 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithoutNamespace.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithoutNamespace.verified.cs @@ -11,6 +11,7 @@ namespace OrleansCodeGen using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_DemoData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::DemoData); @@ -79,6 +80,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_DemoData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs new file mode 100644 index 00000000000..7e52eb185a1 --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs @@ -0,0 +1,499 @@ +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] +#pragma warning disable +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IBasicGrain), "6B0E24A1")] + public sealed class Invokable_IBasicGrain_GrainReference_6B0E24A1 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + { + public string arg0; + global::TestProject.IBasicGrain _target; + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IBasicGrain).GetMethod("SayHello", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new[] { typeof(string) }, null); + public override int GetArgumentCount() => 1; + public override string GetMethodName() => "SayHello"; + public override string GetInterfaceName() => "TestProject.IBasicGrain"; + public override string GetActivityName() => "IBasicGrain/SayHello"; + public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IBasicGrain); + public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; + public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = (global::TestProject.IBasicGrain)holder.GetTarget(); + public override object GetTarget() => _target; + public override void Dispose() + { + arg0 = default; + _target = default; + } + + public override object GetArgument(int index) + { + switch (index) + { + case 0: + return arg0; + default: + return OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + } + } + + public override void SetArgument(int index, object value) + { + switch (index) + { + case 0: + arg0 = (string)value; + return; + default: + OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + return; + } + } + + protected override global::System.Threading.Tasks.Task InvokeInner() => _target.SayHello(arg0); + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + string value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Proxy_IBasicGrain : global::Orleans.Runtime.GrainReference, global::TestProject.IBasicGrain + { + public Proxy_IBasicGrain(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) + { + } + + global::System.Threading.Tasks.Task global::TestProject.IBasicGrain.SayHello(string arg0) + { + var request = new OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1(); + request.arg0 = arg0; + return base.InvokeAsync(request).AsTask(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_Invokable_IBasicGrain_GrainReference_6B0E24A1 : global::Orleans.Serialization.Codecs.IFieldCodec + { + private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1 instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.arg0); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1 instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + instance.arg0 = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1 @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null) + { + ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + var result = new OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1(); + ReferenceCodec.MarkValueField(reader.Session); + Deserialize(ref reader, result); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_Invokable_IBasicGrain_GrainReference_6B0E24A1 : global::Orleans.Serialization.Cloning.IDeepCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1 DeepCopy(OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1 original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (original is null) + return null; + var result = new OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1(); + result.arg0 = original.arg0; + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_BasicGrain : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.BasicGrain); + private readonly global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer; + public Codec_BasicGrain(global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer) + { + this._baseTypeSerializer = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeSerializer); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.BasicGrain instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + _baseTypeSerializer.Serialize(ref writer, instance); + writer.WriteEndBase(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.BasicGrain instance) + { + _baseTypeSerializer.Deserialize(ref reader, instance); + reader.ConsumeEndBaseOrEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.BasicGrain @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::TestProject.BasicGrain)) + { + if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) + return; + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.BasicGrain ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = new global::TestProject.BasicGrain(); + ReferenceCodec.RecordObject(reader.Session, result); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_BasicGrain : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.BasicGrain DeepCopy(global::TestProject.BasicGrain original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context.TryGetCopy(original, out global::TestProject.BasicGrain existing)) + return existing; + if (original.GetType() != typeof(global::TestProject.BasicGrain)) + return context.DeepCopy(original); + var result = new global::TestProject.BasicGrain(); + context.RecordCopy(original, result); + DeepCopy(original, result, context); + return result; + } + + public Copier_BasicGrain(global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier) + { + this._baseTypeCopier = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeCopier); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::TestProject.BasicGrain input, global::TestProject.BasicGrain output, global::Orleans.Serialization.Cloning.CopyContext context) + { + _baseTypeCopier.DeepCopy(input, output, context); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Activator_BasicGrain : global::Orleans.Serialization.Activators.IActivator + { + public global::TestProject.BasicGrain Create() => new global::TestProject.BasicGrain(); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class RpcResponseFactories : global::Orleans.Serialization.SerializerContext + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) + { + options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); + options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); + options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); +#if NET5_0_OR_GREATER + if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) + return; + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(string)); + options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); + options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); + options.AddDefaultSerializerService(static provider => new CompletedResponseActivator()); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); +#endif + } + + private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator + { + public CompletedResponseActivator() + { + } + + public global::Orleans.Serialization.Invocation.CompletedResponse Create() => global::Orleans.Serialization.Invocation.CompletedResponse.Instance; + } + + private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer + { + public ResponseFieldCodec() + { + } + } + + private sealed class ResponseFieldCopier : global::Orleans.Serialization.Cloning.IDeepCopier + { + public ResponseFieldCopier() + { + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public global::Orleans.Serialization.Invocation.Response DeepCopy(global::Orleans.Serialization.Invocation.Response input, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context is null) + throw new global::System.ArgumentNullException(nameof(context)); + if (input is global::Orleans.Serialization.Invocation.CompletedResponse or global::Orleans.Serialization.Invocation.ExceptionResponse) + return input; + return (global::Orleans.Serialization.Invocation.Response)global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context); + } + } + } + + internal sealed class RpcResponse_9146C7E3 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal string Value; + private RpcResponse_9146C7E3Factory _factory; + public RpcResponse_9146C7E3() + { + } + + internal static RpcResponse_9146C7E3 Rent(string value, RpcResponse_9146C7E3Factory factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); + result.Value = value; + result._factory = factory; + return result; + } + + public override object Result { get => Value; set => Value = (string)value; } + public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } + + public override global::System.Type GetSimpleResultType() => typeof(string); + public override T GetResult() + { + if (typeof(T) == typeof(string)) + return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); + return (T)(object)Value; + } + + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) + throw new global::System.ObjectDisposedException(GetType().Name); + writer.WriteStartObject(0, null, typeof(string)); + if (Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, Value); + } + + writer.WriteEndObject(); + } + + public override void Dispose() + { + if (_factory is null) + return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; + private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; + public bool IsSupported { get; } + + internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec(); + provider.GetDeepCopier(); + provider.GetCodec>(); + provider.GetDeepCopier>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + } + + public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec() as global::Orleans.Serialization.Codecs.StringCodec; + _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; + var responseCodec = provider.GetCodec>(); + var responseCopier = provider.GetDeepCopier>(); + IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + } + + internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + return RpcResponse_9146C7E3.Rent(value, this); + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public RpcResponse_9146C7E3 DeepCopy(RpcResponse_9146C7E3 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_9146C7E3.Rent(input.Value, this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, string value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof(string)); + if (value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value); + } + + writer.WriteEndObject(); + } + + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = RpcResponse_9146C7E3.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, field); + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + + return result; + } + catch + { + result.Dispose(); + throw; + } + } + + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_9146C7E3 value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); + if (value.Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value.Value); + } + + writer.WriteEndObject(); + } + + public RpcResponse_9146C7E3 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IBasicGrain_GrainReference_6B0E24A1)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_BasicGrain)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IBasicGrain_GrainReference_6B0E24A1)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_BasicGrain)); + config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IBasicGrain)); + config.AddInterface(typeof(global::TestProject.IBasicGrain)); + config.AddInterfaceImplementation(typeof(global::TestProject.BasicGrain)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_BasicGrain)); + var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); + var n2 = n1.GetOrAdd(typeof(global::Orleans.Runtime.GrainReference)); + var n3 = n2.GetOrAdd(typeof(global::TestProject.IBasicGrain)); + n3.Add("6B0E24A1", typeof(OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1)); + } + } +} +#pragma warning restore \ No newline at end of file diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs new file mode 100644 index 00000000000..53ca71858b9 --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs @@ -0,0 +1,500 @@ +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] +#pragma warning disable +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IBasicGrain), "6B0E24A1")] + public sealed class Invokable_IBasicGrain_GrainReference_6B0E24A1 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + { + public string arg0; + global::TestProject.IBasicGrain _target; + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IBasicGrain).GetMethod("SayHello", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new[] { typeof(string) }, null); + public override int GetArgumentCount() => 1; + public override string GetMethodName() => "SayHello"; + public override string GetInterfaceName() => "TestProject.IBasicGrain"; + public override string GetActivityName() => "IBasicGrain/SayHello"; + public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IBasicGrain); + public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; + public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = (global::TestProject.IBasicGrain)holder.GetTarget(); + public override object GetTarget() => _target; + public override void Dispose() + { + arg0 = default; + _target = default; + } + + public override object GetArgument(int index) + { + switch (index) + { + case 0: + return arg0; + default: + return OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + } + } + + public override void SetArgument(int index, object value) + { + switch (index) + { + case 0: + arg0 = (string)value; + return; + default: + OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + return; + } + } + + protected override global::System.Threading.Tasks.Task InvokeInner() => _target.SayHello(arg0); + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + string value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Proxy_IBasicGrain : global::Orleans.Runtime.GrainReference, global::TestProject.IBasicGrain + { + public Proxy_IBasicGrain(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) + { + } + + global::System.Threading.Tasks.Task global::TestProject.IBasicGrain.SayHello(string arg0) + { + var request = new OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1(); + request.arg0 = arg0; + return base.InvokeAsync(request).AsTask(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_Invokable_IBasicGrain_GrainReference_6B0E24A1 : global::Orleans.Serialization.Codecs.IFieldCodec + { + private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1 instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.arg0); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1 instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + instance.arg0 = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1 @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null) + { + ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + var result = new OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1(); + ReferenceCodec.MarkValueField(reader.Session); + Deserialize(ref reader, result); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_Invokable_IBasicGrain_GrainReference_6B0E24A1 : global::Orleans.Serialization.Cloning.IDeepCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1 DeepCopy(OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1 original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (original is null) + return null; + var result = new OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1(); + result.arg0 = original.arg0; + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_BasicGrain : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.BasicGrain); + private readonly global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer; + public Codec_BasicGrain(global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer) + { + this._baseTypeSerializer = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeSerializer); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.BasicGrain instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + _baseTypeSerializer.Serialize(ref writer, instance); + writer.WriteEndBase(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.BasicGrain instance) + { + _baseTypeSerializer.Deserialize(ref reader, instance); + reader.ConsumeEndBaseOrEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.BasicGrain @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::TestProject.BasicGrain)) + { + if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) + return; + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.BasicGrain ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = new global::TestProject.BasicGrain(); + ReferenceCodec.RecordObject(reader.Session, result); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_BasicGrain : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.BasicGrain DeepCopy(global::TestProject.BasicGrain original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context.TryGetCopy(original, out global::TestProject.BasicGrain existing)) + return existing; + if (original.GetType() != typeof(global::TestProject.BasicGrain)) + return context.DeepCopy(original); + var result = new global::TestProject.BasicGrain(); + context.RecordCopy(original, result); + DeepCopy(original, result, context); + return result; + } + + public Copier_BasicGrain(global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier) + { + this._baseTypeCopier = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeCopier); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::TestProject.BasicGrain input, global::TestProject.BasicGrain output, global::Orleans.Serialization.Cloning.CopyContext context) + { + _baseTypeCopier.DeepCopy(input, output, context); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Activator_BasicGrain : global::Orleans.Serialization.Activators.IActivator + { + public global::TestProject.BasicGrain Create() => new global::TestProject.BasicGrain(); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class RpcResponseFactories : global::Orleans.Serialization.SerializerContext + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) + { + options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); + options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); + options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); +#if NET5_0_OR_GREATER + if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) + return; + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(string)); + options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); + options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); + options.AddDefaultSerializerService(static provider => new CompletedResponseActivator()); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); +#endif + } + + private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator + { + public CompletedResponseActivator() + { + } + + public global::Orleans.Serialization.Invocation.CompletedResponse Create() => global::Orleans.Serialization.Invocation.CompletedResponse.Instance; + } + + private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer + { + public ResponseFieldCodec() + { + } + } + + private sealed class ResponseFieldCopier : global::Orleans.Serialization.Cloning.IDeepCopier + { + public ResponseFieldCopier() + { + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public global::Orleans.Serialization.Invocation.Response DeepCopy(global::Orleans.Serialization.Invocation.Response input, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context is null) + throw new global::System.ArgumentNullException(nameof(context)); + if (input is global::Orleans.Serialization.Invocation.CompletedResponse or global::Orleans.Serialization.Invocation.ExceptionResponse) + return input; + return (global::Orleans.Serialization.Invocation.Response)global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context); + } + } + } + + internal sealed class RpcResponse_9146C7E3 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal string Value; + private RpcResponse_9146C7E3Factory _factory; + public RpcResponse_9146C7E3() + { + } + + internal static RpcResponse_9146C7E3 Rent(string value, RpcResponse_9146C7E3Factory factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); + result.Value = value; + result._factory = factory; + return result; + } + + public override object Result { get => Value; set => Value = (string)value; } + + public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } + + public override global::System.Type GetSimpleResultType() => typeof(string); + public override T GetResult() + { + if (typeof(T) == typeof(string)) + return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); + return (T)(object)Value; + } + + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) + throw new global::System.ObjectDisposedException(GetType().Name); + writer.WriteStartObject(0, null, typeof(string)); + if (Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, Value); + } + + writer.WriteEndObject(); + } + + public override void Dispose() + { + if (_factory is null) + return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; + private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; + public bool IsSupported { get; } + + internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec(); + provider.GetDeepCopier(); + provider.GetCodec>(); + provider.GetDeepCopier>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + } + + public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec() as global::Orleans.Serialization.Codecs.StringCodec; + _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; + var responseCodec = provider.GetCodec>(); + var responseCopier = provider.GetDeepCopier>(); + IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + } + + internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + return RpcResponse_9146C7E3.Rent(value, this); + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public RpcResponse_9146C7E3 DeepCopy(RpcResponse_9146C7E3 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_9146C7E3.Rent(input.Value, this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, string value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof(string)); + if (value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value); + } + + writer.WriteEndObject(); + } + + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = RpcResponse_9146C7E3.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, field); + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + + return result; + } + catch + { + result.Dispose(); + throw; + } + } + + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_9146C7E3 value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); + if (value.Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value.Value); + } + + writer.WriteEndObject(); + } + + public RpcResponse_9146C7E3 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IBasicGrain_GrainReference_6B0E24A1)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_BasicGrain)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IBasicGrain_GrainReference_6B0E24A1)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_BasicGrain)); + config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IBasicGrain)); + config.AddInterface(typeof(global::TestProject.IBasicGrain)); + config.AddInterfaceImplementation(typeof(global::TestProject.BasicGrain)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_BasicGrain)); + var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); + var n2 = n1.GetOrAdd(typeof(global::Orleans.Runtime.GrainReference)); + var n3 = n2.GetOrAdd(typeof(global::TestProject.IBasicGrain)); + n3.Add("6B0E24A1", typeof(OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1)); + } + } +} +#pragma warning restore \ No newline at end of file diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.verified.cs index aa1bf3fdc7c..17591d516cc 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.verified.cs @@ -1,6 +1,4 @@ -// -#nullable disable -[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] #pragma warning disable [assembly: global::Orleans.ApplicationPartAttribute("TestProject")] [assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] @@ -15,11 +13,11 @@ namespace OrleansCodeGen.TestProject [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IBasicGrain), "6B0E24A1")] - public sealed class Invokable_IBasicGrain_GrainReference_6B0E24A1 : global::Orleans.Runtime.TaskRequest + public sealed class Invokable_IBasicGrain_GrainReference_6B0E24A1 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable { public string arg0; global::TestProject.IBasicGrain _target; - private static readonly global::System.Reflection.MethodInfo MethodBackingField = OrleansGeneratedCodeHelper.GetMethodInfoOrDefault(typeof(global::TestProject.IBasicGrain), "SayHello", null, new[] { typeof(string) }); + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IBasicGrain).GetMethod("SayHello", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new[] { typeof(string) }, null); public override int GetArgumentCount() => 1; public override string GetMethodName() => "SayHello"; public override string GetInterfaceName() => "TestProject.IBasicGrain"; @@ -59,6 +57,21 @@ public override void SetArgument(int index, object value) } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.SayHello(arg0); + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + string value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] @@ -77,6 +90,7 @@ public Proxy_IBasicGrain(global::Orleans.Runtime.GrainReferenceShared arg0, glob } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IBasicGrain_GrainReference_6B0E24A1 : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1); @@ -139,6 +153,7 @@ public OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1 } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IBasicGrain_GrainReference_6B0E24A1 : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -153,6 +168,7 @@ public OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1 } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_BasicGrain : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.BasicGrain); @@ -213,6 +229,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_BasicGrain : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; @@ -252,6 +269,9 @@ internal sealed class RpcResponseFactories : global::Orleans.Serialization.Seria { protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) { + options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); + options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); + options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); #if NET5_0_OR_GREATER if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) return; @@ -308,6 +328,154 @@ public ResponseFieldCopier() } } + internal sealed class RpcResponse_9146C7E3 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal string Value; + private RpcResponse_9146C7E3Factory _factory; + public RpcResponse_9146C7E3() + { + } + + internal static RpcResponse_9146C7E3 Rent(string value, RpcResponse_9146C7E3Factory factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); + result.Value = value; + result._factory = factory; + return result; + } + + public override object Result { get => Value; set => Value = (string)value; } + public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } + + public override global::System.Type GetSimpleResultType() => typeof(string); + public override T GetResult() + { + if (typeof(T) == typeof(string)) + return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); + return (T)(object)Value; + } + + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) + throw new global::System.ObjectDisposedException(GetType().Name); + writer.WriteStartObject(0, null, typeof(string)); + if (Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, Value); + } + + writer.WriteEndObject(); + } + + public override void Dispose() + { + if (_factory is null) + return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; + private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; + public bool IsSupported { get; } + + internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec(); + provider.GetDeepCopier(); + provider.GetCodec>(); + provider.GetDeepCopier>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + } + + public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec() as global::Orleans.Serialization.Codecs.StringCodec; + _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; + var responseCodec = provider.GetCodec>(); + var responseCopier = provider.GetDeepCopier>(); + IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + } + + internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + return RpcResponse_9146C7E3.Rent(value, this); + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public RpcResponse_9146C7E3 DeepCopy(RpcResponse_9146C7E3 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_9146C7E3.Rent(input.Value, this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, string value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof(string)); + if (value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value); + } + + writer.WriteEndObject(); + } + + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = RpcResponse_9146C7E3.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, field); + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + + return result; + } + catch + { + result.Dispose(); + throw; + } + } + + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_9146C7E3 value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); + if (value.Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value.Value); + } + + writer.WriteEndObject(); + } + + public RpcResponse_9146C7E3 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase { diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicStruct.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicStruct.verified.cs index de13a21092e..7303380754d 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicStruct.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicStruct.verified.cs @@ -11,6 +11,7 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_DemoData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IValueSerializer { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DemoData); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassNestedTypes.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassNestedTypes.verified.cs index 3ac2cd83f0a..8b57f9e37d3 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassNestedTypes.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassNestedTypes.verified.cs @@ -11,6 +11,7 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_DemoData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DemoData); @@ -112,6 +113,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_DemoData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Cloning.IDeepCopier _copier_CyclicClass_AE634BDC96DD9410; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassPrimitiveTypes.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassPrimitiveTypes.verified.cs index 0e9a8cc8a8e..b8dcb32febd 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassPrimitiveTypes.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassPrimitiveTypes.verified.cs @@ -11,6 +11,7 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_DemoData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DemoData); @@ -256,6 +257,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_DemoData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Codecs.ArrayCopier _copier_Int32_1_BD21C8B2FA9EFF52; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassPrimitiveTypesUsingFullName.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassPrimitiveTypesUsingFullName.verified.cs index 0e9a8cc8a8e..b8dcb32febd 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassPrimitiveTypesUsingFullName.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassPrimitiveTypesUsingFullName.verified.cs @@ -11,6 +11,7 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_DemoData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DemoData); @@ -256,6 +257,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_DemoData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Codecs.ArrayCopier _copier_Int32_1_BD21C8B2FA9EFF52; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassReferenceProperties.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassReferenceProperties.verified.cs index 65bfc992332..f0871b68061 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassReferenceProperties.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassReferenceProperties.verified.cs @@ -11,6 +11,7 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_DemoData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DemoData); @@ -117,6 +118,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_DemoData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Activators.IActivator _activator; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs new file mode 100644 index 00000000000..c1d78c47d42 --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs @@ -0,0 +1,401 @@ +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] +#pragma warning disable +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::IMyGrain), "6D39E404")] + public sealed class Invokable_IMyGrain_GrainReference_6D39E404 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + { + public string arg0; + global::IMyGrain _target; + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::IMyGrain).GetMethod("SayHello", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new[] { typeof(string) }, null); + public override int GetArgumentCount() => 1; + public override string GetMethodName() => "SayHello"; + public override string GetInterfaceName() => "IMyGrain"; + public override string GetActivityName() => "IMyGrain/SayHello"; + public override global::System.Type GetInterfaceType() => typeof(global::IMyGrain); + public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; + public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = (global::IMyGrain)holder.GetTarget(); + public override object GetTarget() => _target; + public override void Dispose() + { + arg0 = default; + _target = default; + } + + public override object GetArgument(int index) + { + switch (index) + { + case 0: + return arg0; + default: + return OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + } + } + + public override void SetArgument(int index, object value) + { + switch (index) + { + case 0: + arg0 = (string)value; + return; + default: + OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + return; + } + } + + protected override global::System.Threading.Tasks.Task InvokeInner() => _target.SayHello(arg0); + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + string value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Proxy_IMyGrain : global::Orleans.Runtime.GrainReference, global::IMyGrain + { + public Proxy_IMyGrain(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) + { + } + + global::System.Threading.Tasks.Task global::IMyGrain.SayHello(string arg0) + { + var request = new OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404(); + request.arg0 = arg0; + return base.InvokeAsync(request).AsTask(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_Invokable_IMyGrain_GrainReference_6D39E404 : global::Orleans.Serialization.Codecs.IFieldCodec + { + private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404 instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.arg0); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404 instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + instance.arg0 = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404 @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null) + { + ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + var result = new OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404(); + ReferenceCodec.MarkValueField(reader.Session); + Deserialize(ref reader, result); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_Invokable_IMyGrain_GrainReference_6D39E404 : global::Orleans.Serialization.Cloning.IDeepCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404 DeepCopy(OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404 original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (original is null) + return null; + var result = new OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404(); + result.arg0 = original.arg0; + return result; + } + } +} + +namespace OrleansCodeGen.TestProject +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class RpcResponseFactories : global::Orleans.Serialization.SerializerContext + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) + { + options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); + options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); + options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); +#if NET5_0_OR_GREATER + if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) + return; + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(string)); + options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); + options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); + options.AddDefaultSerializerService(static provider => new CompletedResponseActivator()); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); +#endif + } + + private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator + { + public CompletedResponseActivator() + { + } + + public global::Orleans.Serialization.Invocation.CompletedResponse Create() => global::Orleans.Serialization.Invocation.CompletedResponse.Instance; + } + + private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer + { + public ResponseFieldCodec() + { + } + } + + private sealed class ResponseFieldCopier : global::Orleans.Serialization.Cloning.IDeepCopier + { + public ResponseFieldCopier() + { + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public global::Orleans.Serialization.Invocation.Response DeepCopy(global::Orleans.Serialization.Invocation.Response input, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context is null) + throw new global::System.ArgumentNullException(nameof(context)); + if (input is global::Orleans.Serialization.Invocation.CompletedResponse or global::Orleans.Serialization.Invocation.ExceptionResponse) + return input; + return (global::Orleans.Serialization.Invocation.Response)global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context); + } + } + } + + internal sealed class RpcResponse_9146C7E3 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal string Value; + private RpcResponse_9146C7E3Factory _factory; + public RpcResponse_9146C7E3() + { + } + + internal static RpcResponse_9146C7E3 Rent(string value, RpcResponse_9146C7E3Factory factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); + result.Value = value; + result._factory = factory; + return result; + } + + public override object Result { get => Value; set => Value = (string)value; } + public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } + + public override global::System.Type GetSimpleResultType() => typeof(string); + public override T GetResult() + { + if (typeof(T) == typeof(string)) + return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); + return (T)(object)Value; + } + + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) + throw new global::System.ObjectDisposedException(GetType().Name); + writer.WriteStartObject(0, null, typeof(string)); + if (Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, Value); + } + + writer.WriteEndObject(); + } + + public override void Dispose() + { + if (_factory is null) + return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; + private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; + public bool IsSupported { get; } + + internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec(); + provider.GetDeepCopier(); + provider.GetCodec>(); + provider.GetDeepCopier>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + } + + public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec() as global::Orleans.Serialization.Codecs.StringCodec; + _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; + var responseCodec = provider.GetCodec>(); + var responseCopier = provider.GetDeepCopier>(); + IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + } + + internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + return RpcResponse_9146C7E3.Rent(value, this); + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public RpcResponse_9146C7E3 DeepCopy(RpcResponse_9146C7E3 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_9146C7E3.Rent(input.Value, this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, string value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof(string)); + if (value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value); + } + + writer.WriteEndObject(); + } + + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = RpcResponse_9146C7E3.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, field); + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + + return result; + } + catch + { + result.Dispose(); + throw; + } + } + + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_9146C7E3 value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); + if (value.Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value.Value); + } + + writer.WriteEndObject(); + } + + public RpcResponse_9146C7E3 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.AddSerializer(typeof(OrleansCodeGen.Codec_Invokable_IMyGrain_GrainReference_6D39E404)); + config.AddCopier(typeof(OrleansCodeGen.Copier_Invokable_IMyGrain_GrainReference_6D39E404)); + config.AddInterfaceProxy(typeof(OrleansCodeGen.Proxy_IMyGrain)); + config.AddInterface(typeof(global::IMyGrain)); + var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); + var n2 = n1.GetOrAdd(typeof(global::Orleans.Runtime.GrainReference)); + var n3 = n2.GetOrAdd(typeof(global::IMyGrain)); + n3.Add("6D39E404", typeof(OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404)); + } + } +} +#pragma warning restore \ No newline at end of file diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs new file mode 100644 index 00000000000..1df7ce87fea --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs @@ -0,0 +1,402 @@ +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] +#pragma warning disable +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::IMyGrain), "6D39E404")] + public sealed class Invokable_IMyGrain_GrainReference_6D39E404 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + { + public string arg0; + global::IMyGrain _target; + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::IMyGrain).GetMethod("SayHello", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new[] { typeof(string) }, null); + public override int GetArgumentCount() => 1; + public override string GetMethodName() => "SayHello"; + public override string GetInterfaceName() => "IMyGrain"; + public override string GetActivityName() => "IMyGrain/SayHello"; + public override global::System.Type GetInterfaceType() => typeof(global::IMyGrain); + public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; + public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = (global::IMyGrain)holder.GetTarget(); + public override object GetTarget() => _target; + public override void Dispose() + { + arg0 = default; + _target = default; + } + + public override object GetArgument(int index) + { + switch (index) + { + case 0: + return arg0; + default: + return OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + } + } + + public override void SetArgument(int index, object value) + { + switch (index) + { + case 0: + arg0 = (string)value; + return; + default: + OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + return; + } + } + + protected override global::System.Threading.Tasks.Task InvokeInner() => _target.SayHello(arg0); + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + string value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Proxy_IMyGrain : global::Orleans.Runtime.GrainReference, global::IMyGrain + { + public Proxy_IMyGrain(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) + { + } + + global::System.Threading.Tasks.Task global::IMyGrain.SayHello(string arg0) + { + var request = new OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404(); + request.arg0 = arg0; + return base.InvokeAsync(request).AsTask(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_Invokable_IMyGrain_GrainReference_6D39E404 : global::Orleans.Serialization.Codecs.IFieldCodec + { + private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404 instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.arg0); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404 instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + instance.arg0 = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404 @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null) + { + ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + var result = new OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404(); + ReferenceCodec.MarkValueField(reader.Session); + Deserialize(ref reader, result); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_Invokable_IMyGrain_GrainReference_6D39E404 : global::Orleans.Serialization.Cloning.IDeepCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404 DeepCopy(OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404 original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (original is null) + return null; + var result = new OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404(); + result.arg0 = original.arg0; + return result; + } + } +} + +namespace OrleansCodeGen.TestProject +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class RpcResponseFactories : global::Orleans.Serialization.SerializerContext + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) + { + options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); + options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); + options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); +#if NET5_0_OR_GREATER + if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) + return; + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(string)); + options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); + options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); + options.AddDefaultSerializerService(static provider => new CompletedResponseActivator()); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); +#endif + } + + private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator + { + public CompletedResponseActivator() + { + } + + public global::Orleans.Serialization.Invocation.CompletedResponse Create() => global::Orleans.Serialization.Invocation.CompletedResponse.Instance; + } + + private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer + { + public ResponseFieldCodec() + { + } + } + + private sealed class ResponseFieldCopier : global::Orleans.Serialization.Cloning.IDeepCopier + { + public ResponseFieldCopier() + { + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public global::Orleans.Serialization.Invocation.Response DeepCopy(global::Orleans.Serialization.Invocation.Response input, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context is null) + throw new global::System.ArgumentNullException(nameof(context)); + if (input is global::Orleans.Serialization.Invocation.CompletedResponse or global::Orleans.Serialization.Invocation.ExceptionResponse) + return input; + return (global::Orleans.Serialization.Invocation.Response)global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context); + } + } + } + + internal sealed class RpcResponse_9146C7E3 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal string Value; + private RpcResponse_9146C7E3Factory _factory; + public RpcResponse_9146C7E3() + { + } + + internal static RpcResponse_9146C7E3 Rent(string value, RpcResponse_9146C7E3Factory factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); + result.Value = value; + result._factory = factory; + return result; + } + + public override object Result { get => Value; set => Value = (string)value; } + + public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } + + public override global::System.Type GetSimpleResultType() => typeof(string); + public override T GetResult() + { + if (typeof(T) == typeof(string)) + return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); + return (T)(object)Value; + } + + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) + throw new global::System.ObjectDisposedException(GetType().Name); + writer.WriteStartObject(0, null, typeof(string)); + if (Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, Value); + } + + writer.WriteEndObject(); + } + + public override void Dispose() + { + if (_factory is null) + return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; + private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; + public bool IsSupported { get; } + + internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec(); + provider.GetDeepCopier(); + provider.GetCodec>(); + provider.GetDeepCopier>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + } + + public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec() as global::Orleans.Serialization.Codecs.StringCodec; + _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; + var responseCodec = provider.GetCodec>(); + var responseCopier = provider.GetDeepCopier>(); + IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + } + + internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + return RpcResponse_9146C7E3.Rent(value, this); + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public RpcResponse_9146C7E3 DeepCopy(RpcResponse_9146C7E3 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_9146C7E3.Rent(input.Value, this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, string value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof(string)); + if (value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value); + } + + writer.WriteEndObject(); + } + + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = RpcResponse_9146C7E3.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, field); + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + + return result; + } + catch + { + result.Dispose(); + throw; + } + } + + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_9146C7E3 value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); + if (value.Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value.Value); + } + + writer.WriteEndObject(); + } + + public RpcResponse_9146C7E3 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.AddSerializer(typeof(OrleansCodeGen.Codec_Invokable_IMyGrain_GrainReference_6D39E404)); + config.AddCopier(typeof(OrleansCodeGen.Copier_Invokable_IMyGrain_GrainReference_6D39E404)); + config.AddInterfaceProxy(typeof(OrleansCodeGen.Proxy_IMyGrain)); + config.AddInterface(typeof(global::IMyGrain)); + var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); + var n2 = n1.GetOrAdd(typeof(global::Orleans.Runtime.GrainReference)); + var n3 = n2.GetOrAdd(typeof(global::IMyGrain)); + n3.Add("6D39E404", typeof(OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404)); + } + } +} +#pragma warning restore \ No newline at end of file diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.verified.cs index 6bf6c45e852..59569672718 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.verified.cs @@ -1,6 +1,4 @@ -// -#nullable disable -[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] #pragma warning disable [assembly: global::Orleans.ApplicationPartAttribute("TestProject")] [assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] @@ -15,11 +13,11 @@ namespace OrleansCodeGen [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::IMyGrain), "6D39E404")] - public sealed class Invokable_IMyGrain_GrainReference_6D39E404 : global::Orleans.Runtime.TaskRequest + public sealed class Invokable_IMyGrain_GrainReference_6D39E404 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable { public string arg0; global::IMyGrain _target; - private static readonly global::System.Reflection.MethodInfo MethodBackingField = OrleansGeneratedCodeHelper.GetMethodInfoOrDefault(typeof(global::IMyGrain), "SayHello", null, new[] { typeof(string) }); + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::IMyGrain).GetMethod("SayHello", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new[] { typeof(string) }, null); public override int GetArgumentCount() => 1; public override string GetMethodName() => "SayHello"; public override string GetInterfaceName() => "IMyGrain"; @@ -59,6 +57,21 @@ public override void SetArgument(int index, object value) } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.SayHello(arg0); + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + string value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] @@ -77,6 +90,7 @@ public Proxy_IMyGrain(global::Orleans.Runtime.GrainReferenceShared arg0, global: } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IMyGrain_GrainReference_6D39E404 : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404); @@ -139,6 +153,7 @@ public OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404 ReadValue { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -160,6 +175,9 @@ internal sealed class RpcResponseFactories : global::Orleans.Serialization.Seria { protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) { + options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); + options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); + options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); #if NET5_0_OR_GREATER if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) return; @@ -216,6 +234,154 @@ public ResponseFieldCopier() } } + internal sealed class RpcResponse_9146C7E3 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal string Value; + private RpcResponse_9146C7E3Factory _factory; + public RpcResponse_9146C7E3() + { + } + + internal static RpcResponse_9146C7E3 Rent(string value, RpcResponse_9146C7E3Factory factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); + result.Value = value; + result._factory = factory; + return result; + } + + public override object Result { get => Value; set => Value = (string)value; } + public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } + + public override global::System.Type GetSimpleResultType() => typeof(string); + public override T GetResult() + { + if (typeof(T) == typeof(string)) + return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); + return (T)(object)Value; + } + + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) + throw new global::System.ObjectDisposedException(GetType().Name); + writer.WriteStartObject(0, null, typeof(string)); + if (Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, Value); + } + + writer.WriteEndObject(); + } + + public override void Dispose() + { + if (_factory is null) + return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; + private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; + public bool IsSupported { get; } + + internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec(); + provider.GetDeepCopier(); + provider.GetCodec>(); + provider.GetDeepCopier>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + } + + public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec() as global::Orleans.Serialization.Codecs.StringCodec; + _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; + var responseCodec = provider.GetCodec>(); + var responseCopier = provider.GetDeepCopier>(); + IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + } + + internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + return RpcResponse_9146C7E3.Rent(value, this); + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public RpcResponse_9146C7E3 DeepCopy(RpcResponse_9146C7E3 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_9146C7E3.Rent(input.Value, this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, string value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof(string)); + if (value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value); + } + + writer.WriteEndObject(); + } + + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = RpcResponse_9146C7E3.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, field); + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + + return result; + } + catch + { + result.Dispose(); + throw; + } + } + + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_9146C7E3 value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); + if (value.Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value.Value); + } + + writer.WriteEndObject(); + } + + public RpcResponse_9146C7E3 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase { diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateSerializerAnnotation.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateSerializerAnnotation.verified.cs index 24edc2fab33..af94f99b8cd 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateSerializerAnnotation.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateSerializerAnnotation.verified.cs @@ -11,6 +11,7 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_MyCustomEnum : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.MyCustomEnum); @@ -29,6 +30,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_ClassWithImplicitFieldIds : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.ClassWithImplicitFieldIds); @@ -116,6 +118,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_ClassWithImplicitFieldIds : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithInterfaceConstructorParameter.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithInterfaceConstructorParameter.verified.cs index 172cf1f1c63..7e9effa496a 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithInterfaceConstructorParameter.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithInterfaceConstructorParameter.verified.cs @@ -11,6 +11,7 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_InterfaceCtorParam : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.InterfaceCtorParam); @@ -90,6 +91,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_InterfaceCtorParam : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Activators.IActivator _activator; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithNoPublicConstructors.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithNoPublicConstructors.verified.cs index 4b1adaa7217..98245e15e62 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithNoPublicConstructors.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithNoPublicConstructors.verified.cs @@ -11,6 +11,7 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_NoPublicCtor : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.NoPublicCtor); @@ -85,6 +86,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_NoPublicCtor : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Activators.IActivator _activator; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithOptionalConstructorParameters.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithOptionalConstructorParameters.verified.cs index 767270fa502..e435b8d8deb 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithOptionalConstructorParameters.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithOptionalConstructorParameters.verified.cs @@ -11,6 +11,7 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_OptionalCtorParams : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.OptionalCtorParams); @@ -99,6 +100,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_OptionalCtorParams : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Activators.IActivator _activator; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithParameterizedConstructor.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithParameterizedConstructor.verified.cs index dae152224e7..e3a5a396c9f 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithParameterizedConstructor.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithParameterizedConstructor.verified.cs @@ -11,6 +11,7 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_MyServiceConsumer : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.MyServiceConsumer); @@ -85,6 +86,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_MyServiceConsumer : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Activators.IActivator _activator; @@ -114,6 +116,7 @@ public void DeepCopy(global::TestProject.MyServiceConsumer input, global::TestPr } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_RootType : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.RootType); @@ -189,6 +192,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_RootType : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly OrleansCodeGen.TestProject.Copier_MyServiceConsumer _copier_MyServiceConsumer_FAF0B52DDDE25F7A; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassesWithGeneratedActivatorConstructorAnnotation.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassesWithGeneratedActivatorConstructorAnnotation.verified.cs index a9dcb6b944e..aa24b0454af 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassesWithGeneratedActivatorConstructorAnnotation.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassesWithGeneratedActivatorConstructorAnnotation.verified.cs @@ -11,6 +11,7 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_ClassWithGeneratedActivatorConstructor : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.ClassWithGeneratedActivatorConstructor); @@ -89,6 +90,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_ClassWithGeneratedActivatorConstructor : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestCompoundTypeAlias.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestCompoundTypeAlias.verified.cs index d1ba3da19f8..d602490f2ac 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestCompoundTypeAlias.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestCompoundTypeAlias.verified.cs @@ -11,6 +11,7 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_MyCompoundTypeAliasBaseClass : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.MyCompoundTypeAliasBaseClass); @@ -79,6 +80,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_MyCompoundTypeAliasBaseClass : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -108,6 +110,7 @@ internal sealed class Activator_MyCompoundTypeAliasBaseClass : global::Orleans.S } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_MyCompoundTypeAliasClass : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.MyCompoundTypeAliasClass); @@ -195,6 +198,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_MyCompoundTypeAliasClass : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly OrleansCodeGen.TestProject.Copier_MyCompoundTypeAliasBaseClass _baseTypeCopier; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClass.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClass.verified.cs index b57fa34ea8a..9f5ffc2fd27 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClass.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClass.verified.cs @@ -11,6 +11,7 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_GenericData : global::Orleans.Serialization.Codecs.IFieldCodec>, global::Orleans.Serialization.Serializers.IBaseCodec> { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GenericData); @@ -96,6 +97,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_GenericData : global::Orleans.Serialization.Cloning.IDeepCopier>, global::Orleans.Serialization.Cloning.IBaseCopier> { private readonly global::Orleans.Serialization.Cloning.IDeepCopier _copier_T_0CA466BDFA032082; @@ -132,6 +134,7 @@ internal sealed class Activator_GenericData : global::Orleans.Serialization.A } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_ConcreteUsage : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.ConcreteUsage); @@ -220,6 +223,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_ConcreteUsage : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly OrleansCodeGen.TestProject.Copier_GenericData _copier_GenericData_Int32_9F0DA0207759221D; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClassWithConstructorParameters.FieldAccessor.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClassWithConstructorParameters.FieldAccessor.verified.cs index 9d506016e39..14ac1dacadb 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClassWithConstructorParameters.FieldAccessor.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClassWithConstructorParameters.FieldAccessor.verified.cs @@ -11,6 +11,7 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Dynamic")] public sealed class Codec_GenericWithCtor : global::Orleans.Serialization.Codecs.IFieldCodec>, global::Orleans.Serialization.Serializers.IBaseCodec> { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GenericWithCtor); @@ -102,6 +103,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Dynamic")] public sealed class Copier_GenericWithCtor : global::Orleans.Serialization.Cloning.IDeepCopier>, global::Orleans.Serialization.Cloning.IBaseCopier> { private readonly global::Orleans.Serialization.Activators.IActivator> _activator; @@ -138,6 +140,7 @@ public void DeepCopy(global::TestProject.GenericWithCtor input, global::TestP } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_UsesGenericWithCtor : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.UsesGenericWithCtor); @@ -213,6 +216,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_UsesGenericWithCtor : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly OrleansCodeGen.TestProject.Copier_GenericWithCtor _copier_GenericWithCtor_String_C8ECFC0964C2C2C3; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClassWithConstructorParameters.UnsafeAccessor.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClassWithConstructorParameters.UnsafeAccessor.verified.cs index abfffbd2dc5..3a263d98634 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClassWithConstructorParameters.UnsafeAccessor.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClassWithConstructorParameters.UnsafeAccessor.verified.cs @@ -11,6 +11,7 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_GenericWithCtor : global::Orleans.Serialization.Codecs.IFieldCodec>, global::Orleans.Serialization.Serializers.IBaseCodec> { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GenericWithCtor); @@ -102,6 +103,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_GenericWithCtor : global::Orleans.Serialization.Cloning.IDeepCopier>, global::Orleans.Serialization.Cloning.IBaseCopier> { private readonly global::Orleans.Serialization.Activators.IActivator> _activator; @@ -138,6 +140,7 @@ public void DeepCopy(global::TestProject.GenericWithCtor input, global::TestP } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_UsesGenericWithCtor : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.UsesGenericWithCtor); @@ -213,6 +216,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_UsesGenericWithCtor : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly OrleansCodeGen.TestProject.Copier_GenericWithCtor _copier_GenericWithCtor_String_C8ECFC0964C2C2C3; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs new file mode 100644 index 00000000000..d0354a36b1e --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs @@ -0,0 +1,701 @@ +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] +#pragma warning disable +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IComplexGrain), "67FE5808")] + public sealed class Invokable_IComplexGrain_GrainReference_67FE5808 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + { + public int arg0; + public string arg1; + public global::TestProject.ComplexData arg2; + public global::System.Threading.CancellationToken arg3; + global::TestProject.IComplexGrain _target; + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IComplexGrain).GetMethod("ProcessData", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new[] { typeof(int), typeof(string), typeof(global::TestProject.ComplexData), typeof(global::System.Threading.CancellationToken) }, null); + global::System.Threading.CancellationTokenSource _cts; + public override int GetArgumentCount() => 4; + public override string GetMethodName() => "ProcessData"; + public override string GetInterfaceName() => "TestProject.IComplexGrain"; + public override string GetActivityName() => "IComplexGrain/ProcessData"; + public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IComplexGrain); + public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; + public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) + { + _target = (global::TestProject.IComplexGrain)holder.GetTarget(); + _cts = new(); + arg3 = _cts.Token; + } + + public override object GetTarget() => _target; + public override void Dispose() + { + arg0 = default; + arg1 = default; + arg2 = default; + arg3 = default; + _target = default; + _cts?.Dispose(); + _cts = default; + } + + public override object GetArgument(int index) + { + switch (index) + { + case 0: + return arg0; + case 1: + return arg1; + case 2: + return arg2; + case 3: + return arg3; + default: + return OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 3); + } + } + + public override void SetArgument(int index, object value) + { + switch (index) + { + case 0: + arg0 = (int)value; + return; + case 1: + arg1 = (string)value; + return; + case 2: + arg2 = (global::TestProject.ComplexData)value; + return; + case 3: + arg3 = (global::System.Threading.CancellationToken)value; + return; + default: + OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 3); + return; + } + } + + protected override global::System.Threading.Tasks.Task InvokeInner() => _target.ProcessData(arg0, arg1, arg2, arg3); + public override global::System.Threading.CancellationToken GetCancellationToken() => arg3; + public override bool TryCancel() + { + if (_cts is { } cts) + { + cts.Cancel(false); + return true; + } + + return false; + } + + public override bool IsCancellable => true; + + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_FC7DD5BDFactory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + global::TestProject.ComplexData value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Proxy_IComplexGrain : global::Orleans.Runtime.GrainReference, global::TestProject.IComplexGrain + { + private readonly OrleansCodeGen.TestProject.Copier_ComplexData _copier_ComplexData_765A40ED2309AF35; + public Proxy_IComplexGrain(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) + { + _copier_ComplexData_765A40ED2309AF35 = OrleansGeneratedCodeHelper.GetService(this, CodecProvider); + } + + global::System.Threading.Tasks.Task global::TestProject.IComplexGrain.ProcessData(int arg0, string arg1, global::TestProject.ComplexData arg2, global::System.Threading.CancellationToken arg3) + { + var request = new OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808(); + request.arg0 = arg0; + request.arg1 = arg1; + using var copyContext = base.CopyContextPool.GetContext(); + request.arg2 = _copier_ComplexData_765A40ED2309AF35.DeepCopy(arg2, copyContext); + request.arg3 = arg3; + return base.InvokeAsync(request).AsTask(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_ComplexData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.ComplexData); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.ComplexData instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.Int32Codec.WriteField(ref writer, 0U, instance.IntValue); + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 1U, instance.StringValue); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.ComplexData instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + instance.IntValue = global::Orleans.Serialization.Codecs.Int32Codec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + } + + if (id == 1U) + { + instance.StringValue = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.ComplexData @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::TestProject.ComplexData)) + { + if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) + return; + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.ComplexData ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = new global::TestProject.ComplexData(); + ReferenceCodec.RecordObject(reader.Session, result); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_ComplexData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.ComplexData DeepCopy(global::TestProject.ComplexData original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context.TryGetCopy(original, out global::TestProject.ComplexData existing)) + return existing; + if (original.GetType() != typeof(global::TestProject.ComplexData)) + return context.DeepCopy(original); + var result = new global::TestProject.ComplexData(); + context.RecordCopy(original, result); + DeepCopy(original, result, context); + return result; + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::TestProject.ComplexData input, global::TestProject.ComplexData output, global::Orleans.Serialization.Cloning.CopyContext context) + { + output.IntValue = input.IntValue; + output.StringValue = input.StringValue; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Activator_ComplexData : global::Orleans.Serialization.Activators.IActivator + { + public global::TestProject.ComplexData Create() => new global::TestProject.ComplexData(); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_Invokable_IComplexGrain_GrainReference_67FE5808 : global::Orleans.Serialization.Codecs.IFieldCodec + { + private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808); + private readonly global::System.Type _type_ComplexData_765A40ED2309AF35 = typeof(global::TestProject.ComplexData); + private readonly OrleansCodeGen.TestProject.Codec_ComplexData _codec_ComplexData_765A40ED2309AF35; + public Codec_Invokable_IComplexGrain_GrainReference_67FE5808(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) + { + _codec_ComplexData_765A40ED2309AF35 = OrleansGeneratedCodeHelper.GetService(this, codecProvider); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808 instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.Int32Codec.WriteField(ref writer, 0U, instance.arg0); + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 1U, instance.arg1); + _codec_ComplexData_765A40ED2309AF35.WriteField(ref writer, 1U, _type_ComplexData_765A40ED2309AF35, instance.arg2); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808 instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + instance.arg0 = global::Orleans.Serialization.Codecs.Int32Codec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + } + + if (id == 1U) + { + instance.arg1 = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + } + + if (id == 2U) + { + instance.arg2 = _codec_ComplexData_765A40ED2309AF35.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808 @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null) + { + ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + var result = new OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808(); + ReferenceCodec.MarkValueField(reader.Session); + Deserialize(ref reader, result); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_Invokable_IComplexGrain_GrainReference_67FE5808 : global::Orleans.Serialization.Cloning.IDeepCopier + { + private readonly OrleansCodeGen.TestProject.Copier_ComplexData _copier_ComplexData_765A40ED2309AF35; + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808 DeepCopy(OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808 original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (original is null) + return null; + var result = new OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808(); + result.arg0 = original.arg0; + result.arg1 = original.arg1; + result.arg2 = _copier_ComplexData_765A40ED2309AF35.DeepCopy(original.arg2, context); + result.arg3 = original.arg3; + return result; + } + + public Copier_Invokable_IComplexGrain_GrainReference_67FE5808(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) + { + _copier_ComplexData_765A40ED2309AF35 = OrleansGeneratedCodeHelper.GetService(this, codecProvider); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_ComplexGrain : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.ComplexGrain); + private readonly global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer; + public Codec_ComplexGrain(global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer) + { + this._baseTypeSerializer = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeSerializer); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.ComplexGrain instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + _baseTypeSerializer.Serialize(ref writer, instance); + writer.WriteEndBase(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.ComplexGrain instance) + { + _baseTypeSerializer.Deserialize(ref reader, instance); + reader.ConsumeEndBaseOrEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.ComplexGrain @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::TestProject.ComplexGrain)) + { + if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) + return; + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.ComplexGrain ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = new global::TestProject.ComplexGrain(); + ReferenceCodec.RecordObject(reader.Session, result); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_ComplexGrain : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.ComplexGrain DeepCopy(global::TestProject.ComplexGrain original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context.TryGetCopy(original, out global::TestProject.ComplexGrain existing)) + return existing; + if (original.GetType() != typeof(global::TestProject.ComplexGrain)) + return context.DeepCopy(original); + var result = new global::TestProject.ComplexGrain(); + context.RecordCopy(original, result); + DeepCopy(original, result, context); + return result; + } + + public Copier_ComplexGrain(global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier) + { + this._baseTypeCopier = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeCopier); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::TestProject.ComplexGrain input, global::TestProject.ComplexGrain output, global::Orleans.Serialization.Cloning.CopyContext context) + { + _baseTypeCopier.DeepCopy(input, output, context); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Activator_ComplexGrain : global::Orleans.Serialization.Activators.IActivator + { + public global::TestProject.ComplexGrain Create() => new global::TestProject.ComplexGrain(); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class RpcResponseFactories : global::Orleans.Serialization.SerializerContext + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) + { + options.AddDefaultSerializerService(static provider => new RpcResponse_FC7DD5BDFactory(provider)); + options.AddDefaultSerializer(static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider), static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider)); + options.AddRawResponseReader(static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider)); +#if NET5_0_OR_GREATER + if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) + return; + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Codec_ComplexData()); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Copier_ComplexData()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); + options.AddAllowedType(typeof(global::TestProject.ComplexData)); + options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.Int32Codec()); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(int)); + options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(string)); + options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); + options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); + options.AddDefaultSerializerService(static provider => new CompletedResponseActivator()); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); +#endif + } + + private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator + { + public CompletedResponseActivator() + { + } + + public global::Orleans.Serialization.Invocation.CompletedResponse Create() => global::Orleans.Serialization.Invocation.CompletedResponse.Instance; + } + + private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer + { + public ResponseFieldCodec() + { + } + } + + private sealed class ResponseFieldCopier : global::Orleans.Serialization.Cloning.IDeepCopier + { + public ResponseFieldCopier() + { + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public global::Orleans.Serialization.Invocation.Response DeepCopy(global::Orleans.Serialization.Invocation.Response input, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context is null) + throw new global::System.ArgumentNullException(nameof(context)); + if (input is global::Orleans.Serialization.Invocation.CompletedResponse or global::Orleans.Serialization.Invocation.ExceptionResponse) + return input; + return (global::Orleans.Serialization.Invocation.Response)global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context); + } + } + } + + internal sealed class RpcResponse_FC7DD5BD : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal global::TestProject.ComplexData Value; + private RpcResponse_FC7DD5BDFactory _factory; + public RpcResponse_FC7DD5BD() + { + } + + internal static RpcResponse_FC7DD5BD Rent(global::TestProject.ComplexData value, RpcResponse_FC7DD5BDFactory factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); + result.Value = value; + result._factory = factory; + return result; + } + + public override object Result { get => Value; set => Value = (global::TestProject.ComplexData)value; } + public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } + + public override global::System.Type GetSimpleResultType() => typeof(global::TestProject.ComplexData); + public override T GetResult() + { + if (typeof(T) == typeof(global::TestProject.ComplexData)) + return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); + return (T)(object)Value; + } + + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) + throw new global::System.ObjectDisposedException(GetType().Name); + _factory.WriteResult(ref writer, Value); + } + + public override void Dispose() + { + if (_factory is null) + return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class RpcResponse_FC7DD5BDFactory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly global::OrleansCodeGen.TestProject.Codec_ComplexData _codec; + private readonly global::OrleansCodeGen.TestProject.Copier_ComplexData _copier; + public bool IsSupported { get; } + + internal static RpcResponse_FC7DD5BDFactory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec(); + provider.GetDeepCopier(); + provider.GetCodec>(); + provider.GetDeepCopier>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + } + + public RpcResponse_FC7DD5BDFactory(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec() as global::OrleansCodeGen.TestProject.Codec_ComplexData; + _copier = provider.GetDeepCopier() as global::OrleansCodeGen.TestProject.Copier_ComplexData; + var responseCodec = provider.GetCodec>(); + var responseCopier = provider.GetDeepCopier>(); + IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + } + + internal global::Orleans.Serialization.Invocation.Response RentCopied(global::TestProject.ComplexData value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + using var context = contexts.GetContext(); + return RpcResponse_FC7DD5BD.Rent(_copier.DeepCopy(value, context), this); + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public RpcResponse_FC7DD5BD DeepCopy(RpcResponse_FC7DD5BD input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_FC7DD5BD.Rent(_copier.DeepCopy(input.Value, context), this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.ComplexData value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof(global::TestProject.ComplexData)); + if (value is not null) + { + _codec.WriteField(ref writer, 0, typeof(global::TestProject.ComplexData), value); + } + + writer.WriteEndObject(); + } + + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_FC7DD5BD)value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + private RpcResponse_FC7DD5BD ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = RpcResponse_FC7DD5BD.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = _codec.ReadValue(ref reader, field); + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + + return result; + } + catch + { + result.Dispose(); + throw; + } + } + + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_FC7DD5BD value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); + if (value.Value is not null) + { + _codec.WriteField(ref writer, 0, typeof(global::TestProject.ComplexData), value.Value); + } + + writer.WriteEndObject(); + } + + public RpcResponse_FC7DD5BD ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_ComplexData)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IComplexGrain_GrainReference_67FE5808)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_ComplexGrain)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_ComplexData)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IComplexGrain_GrainReference_67FE5808)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_ComplexGrain)); + config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IComplexGrain)); + config.AddInterface(typeof(global::TestProject.IComplexGrain)); + config.AddInterfaceImplementation(typeof(global::TestProject.ComplexGrain)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_ComplexData)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_ComplexGrain)); + var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); + var n2 = n1.GetOrAdd(typeof(global::Orleans.Runtime.GrainReference)); + var n3 = n2.GetOrAdd(typeof(global::TestProject.IComplexGrain)); + n3.Add("67FE5808", typeof(OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808)); + } + } +} +#pragma warning restore \ No newline at end of file diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs new file mode 100644 index 00000000000..dd7dac19858 --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs @@ -0,0 +1,701 @@ +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] +#pragma warning disable +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IComplexGrain), "67FE5808")] + public sealed class Invokable_IComplexGrain_GrainReference_67FE5808 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + { + public int arg0; + public string arg1; + public global::TestProject.ComplexData arg2; + public global::System.Threading.CancellationToken arg3; + global::TestProject.IComplexGrain _target; + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IComplexGrain).GetMethod("ProcessData", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new[] { typeof(int), typeof(string), typeof(global::TestProject.ComplexData), typeof(global::System.Threading.CancellationToken) }, null); + global::System.Threading.CancellationTokenSource _cts; + public override int GetArgumentCount() => 4; + public override string GetMethodName() => "ProcessData"; + public override string GetInterfaceName() => "TestProject.IComplexGrain"; + public override string GetActivityName() => "IComplexGrain/ProcessData"; + public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IComplexGrain); + public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; + public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) + { + _target = (global::TestProject.IComplexGrain)holder.GetTarget(); + _cts = new(); + arg3 = _cts.Token; + } + + public override object GetTarget() => _target; + public override void Dispose() + { + arg0 = default; + arg1 = default; + arg2 = default; + arg3 = default; + _target = default; + _cts?.Dispose(); + _cts = default; + } + + public override object GetArgument(int index) + { + switch (index) + { + case 0: + return arg0; + case 1: + return arg1; + case 2: + return arg2; + case 3: + return arg3; + default: + return OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 3); + } + } + + public override void SetArgument(int index, object value) + { + switch (index) + { + case 0: + arg0 = (int)value; + return; + case 1: + arg1 = (string)value; + return; + case 2: + arg2 = (global::TestProject.ComplexData)value; + return; + case 3: + arg3 = (global::System.Threading.CancellationToken)value; + return; + default: + OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 3); + return; + } + } + + protected override global::System.Threading.Tasks.Task InvokeInner() => _target.ProcessData(arg0, arg1, arg2, arg3); + public override global::System.Threading.CancellationToken GetCancellationToken() => arg3; + public override bool TryCancel() + { + if (_cts is { } cts) + { + cts.Cancel(false); + return true; + } + + return false; + } + + public override bool IsCancellable => true; + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_FC7DD5BDFactory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + global::TestProject.ComplexData value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Proxy_IComplexGrain : global::Orleans.Runtime.GrainReference, global::TestProject.IComplexGrain + { + private readonly OrleansCodeGen.TestProject.Copier_ComplexData _copier_ComplexData_765A40ED2309AF35; + public Proxy_IComplexGrain(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) + { + _copier_ComplexData_765A40ED2309AF35 = OrleansGeneratedCodeHelper.GetService(this, CodecProvider); + } + + global::System.Threading.Tasks.Task global::TestProject.IComplexGrain.ProcessData(int arg0, string arg1, global::TestProject.ComplexData arg2, global::System.Threading.CancellationToken arg3) + { + var request = new OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808(); + request.arg0 = arg0; + request.arg1 = arg1; + using var copyContext = base.CopyContextPool.GetContext(); + request.arg2 = _copier_ComplexData_765A40ED2309AF35.DeepCopy(arg2, copyContext); + request.arg3 = arg3; + return base.InvokeAsync(request).AsTask(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_ComplexData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.ComplexData); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.ComplexData instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.Int32Codec.WriteField(ref writer, 0U, instance.IntValue); + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 1U, instance.StringValue); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.ComplexData instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + instance.IntValue = global::Orleans.Serialization.Codecs.Int32Codec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + } + + if (id == 1U) + { + instance.StringValue = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.ComplexData @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::TestProject.ComplexData)) + { + if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) + return; + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.ComplexData ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = new global::TestProject.ComplexData(); + ReferenceCodec.RecordObject(reader.Session, result); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_ComplexData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.ComplexData DeepCopy(global::TestProject.ComplexData original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context.TryGetCopy(original, out global::TestProject.ComplexData existing)) + return existing; + if (original.GetType() != typeof(global::TestProject.ComplexData)) + return context.DeepCopy(original); + var result = new global::TestProject.ComplexData(); + context.RecordCopy(original, result); + DeepCopy(original, result, context); + return result; + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::TestProject.ComplexData input, global::TestProject.ComplexData output, global::Orleans.Serialization.Cloning.CopyContext context) + { + output.IntValue = input.IntValue; + output.StringValue = input.StringValue; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Activator_ComplexData : global::Orleans.Serialization.Activators.IActivator + { + public global::TestProject.ComplexData Create() => new global::TestProject.ComplexData(); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_Invokable_IComplexGrain_GrainReference_67FE5808 : global::Orleans.Serialization.Codecs.IFieldCodec + { + private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808); + private readonly global::System.Type _type_ComplexData_765A40ED2309AF35 = typeof(global::TestProject.ComplexData); + private readonly OrleansCodeGen.TestProject.Codec_ComplexData _codec_ComplexData_765A40ED2309AF35; + public Codec_Invokable_IComplexGrain_GrainReference_67FE5808(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) + { + _codec_ComplexData_765A40ED2309AF35 = OrleansGeneratedCodeHelper.GetService(this, codecProvider); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808 instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.Int32Codec.WriteField(ref writer, 0U, instance.arg0); + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 1U, instance.arg1); + _codec_ComplexData_765A40ED2309AF35.WriteField(ref writer, 1U, _type_ComplexData_765A40ED2309AF35, instance.arg2); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808 instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + instance.arg0 = global::Orleans.Serialization.Codecs.Int32Codec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + } + + if (id == 1U) + { + instance.arg1 = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + } + + if (id == 2U) + { + instance.arg2 = _codec_ComplexData_765A40ED2309AF35.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808 @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null) + { + ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + var result = new OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808(); + ReferenceCodec.MarkValueField(reader.Session); + Deserialize(ref reader, result); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_Invokable_IComplexGrain_GrainReference_67FE5808 : global::Orleans.Serialization.Cloning.IDeepCopier + { + private readonly OrleansCodeGen.TestProject.Copier_ComplexData _copier_ComplexData_765A40ED2309AF35; + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808 DeepCopy(OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808 original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (original is null) + return null; + var result = new OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808(); + result.arg0 = original.arg0; + result.arg1 = original.arg1; + result.arg2 = _copier_ComplexData_765A40ED2309AF35.DeepCopy(original.arg2, context); + result.arg3 = original.arg3; + return result; + } + + public Copier_Invokable_IComplexGrain_GrainReference_67FE5808(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) + { + _copier_ComplexData_765A40ED2309AF35 = OrleansGeneratedCodeHelper.GetService(this, codecProvider); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_ComplexGrain : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.ComplexGrain); + private readonly global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer; + public Codec_ComplexGrain(global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer) + { + this._baseTypeSerializer = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeSerializer); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.ComplexGrain instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + _baseTypeSerializer.Serialize(ref writer, instance); + writer.WriteEndBase(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.ComplexGrain instance) + { + _baseTypeSerializer.Deserialize(ref reader, instance); + reader.ConsumeEndBaseOrEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.ComplexGrain @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::TestProject.ComplexGrain)) + { + if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) + return; + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.ComplexGrain ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = new global::TestProject.ComplexGrain(); + ReferenceCodec.RecordObject(reader.Session, result); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_ComplexGrain : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.ComplexGrain DeepCopy(global::TestProject.ComplexGrain original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context.TryGetCopy(original, out global::TestProject.ComplexGrain existing)) + return existing; + if (original.GetType() != typeof(global::TestProject.ComplexGrain)) + return context.DeepCopy(original); + var result = new global::TestProject.ComplexGrain(); + context.RecordCopy(original, result); + DeepCopy(original, result, context); + return result; + } + + public Copier_ComplexGrain(global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier) + { + this._baseTypeCopier = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeCopier); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::TestProject.ComplexGrain input, global::TestProject.ComplexGrain output, global::Orleans.Serialization.Cloning.CopyContext context) + { + _baseTypeCopier.DeepCopy(input, output, context); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Activator_ComplexGrain : global::Orleans.Serialization.Activators.IActivator + { + public global::TestProject.ComplexGrain Create() => new global::TestProject.ComplexGrain(); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class RpcResponseFactories : global::Orleans.Serialization.SerializerContext + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) + { + options.AddDefaultSerializerService(static provider => new RpcResponse_FC7DD5BDFactory(provider)); + options.AddDefaultSerializer(static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider), static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider)); + options.AddRawResponseReader(static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider)); +#if NET5_0_OR_GREATER + if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) + return; + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Codec_ComplexData()); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Copier_ComplexData()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); + options.AddAllowedType(typeof(global::TestProject.ComplexData)); + options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.Int32Codec()); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(int)); + options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(string)); + options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); + options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); + options.AddDefaultSerializerService(static provider => new CompletedResponseActivator()); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); +#endif + } + + private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator + { + public CompletedResponseActivator() + { + } + + public global::Orleans.Serialization.Invocation.CompletedResponse Create() => global::Orleans.Serialization.Invocation.CompletedResponse.Instance; + } + + private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer + { + public ResponseFieldCodec() + { + } + } + + private sealed class ResponseFieldCopier : global::Orleans.Serialization.Cloning.IDeepCopier + { + public ResponseFieldCopier() + { + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public global::Orleans.Serialization.Invocation.Response DeepCopy(global::Orleans.Serialization.Invocation.Response input, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context is null) + throw new global::System.ArgumentNullException(nameof(context)); + if (input is global::Orleans.Serialization.Invocation.CompletedResponse or global::Orleans.Serialization.Invocation.ExceptionResponse) + return input; + return (global::Orleans.Serialization.Invocation.Response)global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context); + } + } + } + + internal sealed class RpcResponse_FC7DD5BD : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal global::TestProject.ComplexData Value; + private RpcResponse_FC7DD5BDFactory _factory; + public RpcResponse_FC7DD5BD() + { + } + + internal static RpcResponse_FC7DD5BD Rent(global::TestProject.ComplexData value, RpcResponse_FC7DD5BDFactory factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); + result.Value = value; + result._factory = factory; + return result; + } + + public override object Result { get => Value; set => Value = (global::TestProject.ComplexData)value; } + + public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } + + public override global::System.Type GetSimpleResultType() => typeof(global::TestProject.ComplexData); + public override T GetResult() + { + if (typeof(T) == typeof(global::TestProject.ComplexData)) + return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); + return (T)(object)Value; + } + + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) + throw new global::System.ObjectDisposedException(GetType().Name); + _factory.WriteResult(ref writer, Value); + } + + public override void Dispose() + { + if (_factory is null) + return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class RpcResponse_FC7DD5BDFactory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly global::OrleansCodeGen.TestProject.Codec_ComplexData _codec; + private readonly global::OrleansCodeGen.TestProject.Copier_ComplexData _copier; + public bool IsSupported { get; } + + internal static RpcResponse_FC7DD5BDFactory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec(); + provider.GetDeepCopier(); + provider.GetCodec>(); + provider.GetDeepCopier>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + } + + public RpcResponse_FC7DD5BDFactory(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec() as global::OrleansCodeGen.TestProject.Codec_ComplexData; + _copier = provider.GetDeepCopier() as global::OrleansCodeGen.TestProject.Copier_ComplexData; + var responseCodec = provider.GetCodec>(); + var responseCopier = provider.GetDeepCopier>(); + IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + } + + internal global::Orleans.Serialization.Invocation.Response RentCopied(global::TestProject.ComplexData value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + using var context = contexts.GetContext(); + return RpcResponse_FC7DD5BD.Rent(_copier.DeepCopy(value, context), this); + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public RpcResponse_FC7DD5BD DeepCopy(RpcResponse_FC7DD5BD input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_FC7DD5BD.Rent(_copier.DeepCopy(input.Value, context), this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.ComplexData value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof(global::TestProject.ComplexData)); + if (value is not null) + { + _codec.WriteField(ref writer, 0, typeof(global::TestProject.ComplexData), value); + } + + writer.WriteEndObject(); + } + + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_FC7DD5BD)value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + private RpcResponse_FC7DD5BD ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = RpcResponse_FC7DD5BD.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = _codec.ReadValue(ref reader, field); + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + + return result; + } + catch + { + result.Dispose(); + throw; + } + } + + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_FC7DD5BD value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); + if (value.Value is not null) + { + _codec.WriteField(ref writer, 0, typeof(global::TestProject.ComplexData), value.Value); + } + + writer.WriteEndObject(); + } + + public RpcResponse_FC7DD5BD ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_ComplexData)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IComplexGrain_GrainReference_67FE5808)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_ComplexGrain)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_ComplexData)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IComplexGrain_GrainReference_67FE5808)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_ComplexGrain)); + config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IComplexGrain)); + config.AddInterface(typeof(global::TestProject.IComplexGrain)); + config.AddInterfaceImplementation(typeof(global::TestProject.ComplexGrain)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_ComplexData)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_ComplexGrain)); + var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); + var n2 = n1.GetOrAdd(typeof(global::Orleans.Runtime.GrainReference)); + var n3 = n2.GetOrAdd(typeof(global::TestProject.IComplexGrain)); + n3.Add("67FE5808", typeof(OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808)); + } + } +} +#pragma warning restore \ No newline at end of file diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.verified.cs index b721d5ac06b..a637eb04e60 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.verified.cs @@ -1,6 +1,4 @@ -// -#nullable disable -[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] #pragma warning disable [assembly: global::Orleans.ApplicationPartAttribute("TestProject")] [assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] @@ -15,14 +13,14 @@ namespace OrleansCodeGen.TestProject [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IComplexGrain), "67FE5808")] - public sealed class Invokable_IComplexGrain_GrainReference_67FE5808 : global::Orleans.Runtime.TaskRequest + public sealed class Invokable_IComplexGrain_GrainReference_67FE5808 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable { public int arg0; public string arg1; public global::TestProject.ComplexData arg2; public global::System.Threading.CancellationToken arg3; global::TestProject.IComplexGrain _target; - private static readonly global::System.Reflection.MethodInfo MethodBackingField = OrleansGeneratedCodeHelper.GetMethodInfoOrDefault(typeof(global::TestProject.IComplexGrain), "ProcessData", null, new[] { typeof(int), typeof(string), typeof(global::TestProject.ComplexData), typeof(global::System.Threading.CancellationToken) }); + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IComplexGrain).GetMethod("ProcessData", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new[] { typeof(int), typeof(string), typeof(global::TestProject.ComplexData), typeof(global::System.Threading.CancellationToken) }, null); global::System.Threading.CancellationTokenSource _cts; public override int GetArgumentCount() => 4; public override string GetMethodName() => "ProcessData"; @@ -102,6 +100,22 @@ public override bool TryCancel() } public override bool IsCancellable => true; + + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_FC7DD5BDFactory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + global::TestProject.ComplexData value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] @@ -126,6 +140,7 @@ public Proxy_IComplexGrain(global::Orleans.Runtime.GrainReferenceShared arg0, gl } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_ComplexData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.ComplexData); @@ -204,6 +219,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_ComplexData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -234,6 +250,7 @@ internal sealed class Activator_ComplexData : global::Orleans.Serialization.Acti } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IComplexGrain_GrainReference_67FE5808 : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808); @@ -323,6 +340,7 @@ public OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE580 } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IComplexGrain_GrainReference_67FE5808 : global::Orleans.Serialization.Cloning.IDeepCopier { private readonly OrleansCodeGen.TestProject.Copier_ComplexData _copier_ComplexData_765A40ED2309AF35; @@ -346,6 +364,7 @@ public Copier_Invokable_IComplexGrain_GrainReference_67FE5808(global::Orleans.Se } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_ComplexGrain : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.ComplexGrain); @@ -406,6 +425,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_ComplexGrain : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; @@ -445,6 +465,9 @@ internal sealed class RpcResponseFactories : global::Orleans.Serialization.Seria { protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) { + options.AddDefaultSerializerService(static provider => new RpcResponse_FC7DD5BDFactory(provider)); + options.AddDefaultSerializer(static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider), static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider)); + options.AddRawResponseReader(static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider)); #if NET5_0_OR_GREATER if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) return; @@ -509,6 +532,149 @@ public ResponseFieldCopier() } } + internal sealed class RpcResponse_FC7DD5BD : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal global::TestProject.ComplexData Value; + private RpcResponse_FC7DD5BDFactory _factory; + public RpcResponse_FC7DD5BD() + { + } + + internal static RpcResponse_FC7DD5BD Rent(global::TestProject.ComplexData value, RpcResponse_FC7DD5BDFactory factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); + result.Value = value; + result._factory = factory; + return result; + } + + public override object Result { get => Value; set => Value = (global::TestProject.ComplexData)value; } + public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } + + public override global::System.Type GetSimpleResultType() => typeof(global::TestProject.ComplexData); + public override T GetResult() + { + if (typeof(T) == typeof(global::TestProject.ComplexData)) + return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); + return (T)(object)Value; + } + + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) + throw new global::System.ObjectDisposedException(GetType().Name); + _factory.WriteResult(ref writer, Value); + } + + public override void Dispose() + { + if (_factory is null) + return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class RpcResponse_FC7DD5BDFactory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly global::OrleansCodeGen.TestProject.Codec_ComplexData _codec; + private readonly global::OrleansCodeGen.TestProject.Copier_ComplexData _copier; + public bool IsSupported { get; } + + internal static RpcResponse_FC7DD5BDFactory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec(); + provider.GetDeepCopier(); + provider.GetCodec>(); + provider.GetDeepCopier>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + } + + public RpcResponse_FC7DD5BDFactory(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec() as global::OrleansCodeGen.TestProject.Codec_ComplexData; + _copier = provider.GetDeepCopier() as global::OrleansCodeGen.TestProject.Copier_ComplexData; + var responseCodec = provider.GetCodec>(); + var responseCopier = provider.GetDeepCopier>(); + IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + } + + internal global::Orleans.Serialization.Invocation.Response RentCopied(global::TestProject.ComplexData value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + using var context = contexts.GetContext(); + return RpcResponse_FC7DD5BD.Rent(_copier.DeepCopy(value, context), this); + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public RpcResponse_FC7DD5BD DeepCopy(RpcResponse_FC7DD5BD input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_FC7DD5BD.Rent(_copier.DeepCopy(input.Value, context), this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.ComplexData value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof(global::TestProject.ComplexData)); + if (value is not null) + { + _codec.WriteField(ref writer, 0, typeof(global::TestProject.ComplexData), value); + } + + writer.WriteEndObject(); + } + + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_FC7DD5BD)value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + private RpcResponse_FC7DD5BD ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = RpcResponse_FC7DD5BD.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = _codec.ReadValue(ref reader, field); + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + + return result; + } + catch + { + result.Dispose(); + throw; + } + } + + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_FC7DD5BD value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); + if (value.Value is not null) + { + _codec.WriteField(ref writer, 0, typeof(global::TestProject.ComplexData), value.Value); + } + + writer.WriteEndObject(); + } + + public RpcResponse_FC7DD5BD ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase { diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs new file mode 100644 index 00000000000..c82c7c5e7ed --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs @@ -0,0 +1,504 @@ +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] +#pragma warning disable +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IHelloGrain), "5336307F")] + public sealed class Invokable_IHelloGrain_GrainReference_5336307F : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + { + public string arg0; + global::TestProject.IHelloGrain _target; + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IHelloGrain).GetMethod("SayHello", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new[] { typeof(string) }, null); + public Invokable_IHelloGrain_GrainReference_5336307F() : base() + { + SetLoggingOptions("Hello"); + } + + public override int GetArgumentCount() => 1; + public override string GetMethodName() => "SayHello"; + public override string GetInterfaceName() => "TestProject.IHelloGrain"; + public override string GetActivityName() => "IHelloGrain/SayHello"; + public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IHelloGrain); + public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; + public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = (global::TestProject.IHelloGrain)holder.GetTarget(); + public override object GetTarget() => _target; + public override void Dispose() + { + arg0 = default; + _target = default; + } + + public override object GetArgument(int index) + { + switch (index) + { + case 0: + return arg0; + default: + return OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + } + } + + public override void SetArgument(int index, object value) + { + switch (index) + { + case 0: + arg0 = (string)value; + return; + default: + OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + return; + } + } + + protected override global::System.Threading.Tasks.Task InvokeInner() => _target.SayHello(arg0); + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + string value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Proxy_IHelloGrain : global::Orleans.Runtime.GrainReference, global::TestProject.IHelloGrain + { + public Proxy_IHelloGrain(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) + { + } + + global::System.Threading.Tasks.Task global::TestProject.IHelloGrain.SayHello(string arg0) + { + var request = new OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F(); + request.arg0 = arg0; + return base.InvokeAsync(request).AsTask(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_Invokable_IHelloGrain_GrainReference_5336307F : global::Orleans.Serialization.Codecs.IFieldCodec + { + private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.arg0); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + instance.arg0 = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null) + { + ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + var result = new OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F(); + ReferenceCodec.MarkValueField(reader.Session); + Deserialize(ref reader, result); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_Invokable_IHelloGrain_GrainReference_5336307F : global::Orleans.Serialization.Cloning.IDeepCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F DeepCopy(OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (original is null) + return null; + var result = new OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F(); + result.arg0 = original.arg0; + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_HelloGrain : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.HelloGrain); + private readonly global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer; + public Codec_HelloGrain(global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer) + { + this._baseTypeSerializer = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeSerializer); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.HelloGrain instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + _baseTypeSerializer.Serialize(ref writer, instance); + writer.WriteEndBase(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.HelloGrain instance) + { + _baseTypeSerializer.Deserialize(ref reader, instance); + reader.ConsumeEndBaseOrEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.HelloGrain @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::TestProject.HelloGrain)) + { + if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) + return; + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.HelloGrain ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = new global::TestProject.HelloGrain(); + ReferenceCodec.RecordObject(reader.Session, result); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_HelloGrain : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.HelloGrain DeepCopy(global::TestProject.HelloGrain original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context.TryGetCopy(original, out global::TestProject.HelloGrain existing)) + return existing; + if (original.GetType() != typeof(global::TestProject.HelloGrain)) + return context.DeepCopy(original); + var result = new global::TestProject.HelloGrain(); + context.RecordCopy(original, result); + DeepCopy(original, result, context); + return result; + } + + public Copier_HelloGrain(global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier) + { + this._baseTypeCopier = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeCopier); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::TestProject.HelloGrain input, global::TestProject.HelloGrain output, global::Orleans.Serialization.Cloning.CopyContext context) + { + _baseTypeCopier.DeepCopy(input, output, context); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Activator_HelloGrain : global::Orleans.Serialization.Activators.IActivator + { + public global::TestProject.HelloGrain Create() => new global::TestProject.HelloGrain(); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class RpcResponseFactories : global::Orleans.Serialization.SerializerContext + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) + { + options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); + options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); + options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); +#if NET5_0_OR_GREATER + if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) + return; + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(string)); + options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); + options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); + options.AddDefaultSerializerService(static provider => new CompletedResponseActivator()); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); +#endif + } + + private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator + { + public CompletedResponseActivator() + { + } + + public global::Orleans.Serialization.Invocation.CompletedResponse Create() => global::Orleans.Serialization.Invocation.CompletedResponse.Instance; + } + + private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer + { + public ResponseFieldCodec() + { + } + } + + private sealed class ResponseFieldCopier : global::Orleans.Serialization.Cloning.IDeepCopier + { + public ResponseFieldCopier() + { + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public global::Orleans.Serialization.Invocation.Response DeepCopy(global::Orleans.Serialization.Invocation.Response input, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context is null) + throw new global::System.ArgumentNullException(nameof(context)); + if (input is global::Orleans.Serialization.Invocation.CompletedResponse or global::Orleans.Serialization.Invocation.ExceptionResponse) + return input; + return (global::Orleans.Serialization.Invocation.Response)global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context); + } + } + } + + internal sealed class RpcResponse_9146C7E3 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal string Value; + private RpcResponse_9146C7E3Factory _factory; + public RpcResponse_9146C7E3() + { + } + + internal static RpcResponse_9146C7E3 Rent(string value, RpcResponse_9146C7E3Factory factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); + result.Value = value; + result._factory = factory; + return result; + } + + public override object Result { get => Value; set => Value = (string)value; } + public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } + + public override global::System.Type GetSimpleResultType() => typeof(string); + public override T GetResult() + { + if (typeof(T) == typeof(string)) + return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); + return (T)(object)Value; + } + + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) + throw new global::System.ObjectDisposedException(GetType().Name); + writer.WriteStartObject(0, null, typeof(string)); + if (Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, Value); + } + + writer.WriteEndObject(); + } + + public override void Dispose() + { + if (_factory is null) + return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; + private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; + public bool IsSupported { get; } + + internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec(); + provider.GetDeepCopier(); + provider.GetCodec>(); + provider.GetDeepCopier>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + } + + public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec() as global::Orleans.Serialization.Codecs.StringCodec; + _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; + var responseCodec = provider.GetCodec>(); + var responseCopier = provider.GetDeepCopier>(); + IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + } + + internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + return RpcResponse_9146C7E3.Rent(value, this); + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public RpcResponse_9146C7E3 DeepCopy(RpcResponse_9146C7E3 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_9146C7E3.Rent(input.Value, this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, string value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof(string)); + if (value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value); + } + + writer.WriteEndObject(); + } + + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = RpcResponse_9146C7E3.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, field); + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + + return result; + } + catch + { + result.Dispose(); + throw; + } + } + + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_9146C7E3 value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); + if (value.Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value.Value); + } + + writer.WriteEndObject(); + } + + public RpcResponse_9146C7E3 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IHelloGrain_GrainReference_5336307F)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_HelloGrain)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IHelloGrain_GrainReference_5336307F)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_HelloGrain)); + config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IHelloGrain)); + config.AddInterface(typeof(global::TestProject.IHelloGrain)); + config.AddInterfaceImplementation(typeof(global::TestProject.HelloGrain)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_HelloGrain)); + var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); + var n2 = n1.GetOrAdd(typeof(global::Orleans.Runtime.GrainReference)); + var n3 = n2.GetOrAdd(typeof(global::TestProject.IHelloGrain)); + n3.Add("5336307F", typeof(OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F)); + } + } +} +#pragma warning restore \ No newline at end of file diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs new file mode 100644 index 00000000000..1ad0819ecc4 --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs @@ -0,0 +1,505 @@ +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] +#pragma warning disable +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IHelloGrain), "5336307F")] + public sealed class Invokable_IHelloGrain_GrainReference_5336307F : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + { + public string arg0; + global::TestProject.IHelloGrain _target; + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IHelloGrain).GetMethod("SayHello", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new[] { typeof(string) }, null); + public Invokable_IHelloGrain_GrainReference_5336307F() : base() + { + SetLoggingOptions("Hello"); + } + + public override int GetArgumentCount() => 1; + public override string GetMethodName() => "SayHello"; + public override string GetInterfaceName() => "TestProject.IHelloGrain"; + public override string GetActivityName() => "IHelloGrain/SayHello"; + public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IHelloGrain); + public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; + public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = (global::TestProject.IHelloGrain)holder.GetTarget(); + public override object GetTarget() => _target; + public override void Dispose() + { + arg0 = default; + _target = default; + } + + public override object GetArgument(int index) + { + switch (index) + { + case 0: + return arg0; + default: + return OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + } + } + + public override void SetArgument(int index, object value) + { + switch (index) + { + case 0: + arg0 = (string)value; + return; + default: + OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + return; + } + } + + protected override global::System.Threading.Tasks.Task InvokeInner() => _target.SayHello(arg0); + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + string value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Proxy_IHelloGrain : global::Orleans.Runtime.GrainReference, global::TestProject.IHelloGrain + { + public Proxy_IHelloGrain(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) + { + } + + global::System.Threading.Tasks.Task global::TestProject.IHelloGrain.SayHello(string arg0) + { + var request = new OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F(); + request.arg0 = arg0; + return base.InvokeAsync(request).AsTask(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_Invokable_IHelloGrain_GrainReference_5336307F : global::Orleans.Serialization.Codecs.IFieldCodec + { + private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.arg0); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + instance.arg0 = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null) + { + ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + var result = new OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F(); + ReferenceCodec.MarkValueField(reader.Session); + Deserialize(ref reader, result); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_Invokable_IHelloGrain_GrainReference_5336307F : global::Orleans.Serialization.Cloning.IDeepCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F DeepCopy(OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (original is null) + return null; + var result = new OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F(); + result.arg0 = original.arg0; + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_HelloGrain : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.HelloGrain); + private readonly global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer; + public Codec_HelloGrain(global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer) + { + this._baseTypeSerializer = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeSerializer); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.HelloGrain instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + _baseTypeSerializer.Serialize(ref writer, instance); + writer.WriteEndBase(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.HelloGrain instance) + { + _baseTypeSerializer.Deserialize(ref reader, instance); + reader.ConsumeEndBaseOrEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.HelloGrain @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::TestProject.HelloGrain)) + { + if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) + return; + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.HelloGrain ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = new global::TestProject.HelloGrain(); + ReferenceCodec.RecordObject(reader.Session, result); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_HelloGrain : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.HelloGrain DeepCopy(global::TestProject.HelloGrain original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context.TryGetCopy(original, out global::TestProject.HelloGrain existing)) + return existing; + if (original.GetType() != typeof(global::TestProject.HelloGrain)) + return context.DeepCopy(original); + var result = new global::TestProject.HelloGrain(); + context.RecordCopy(original, result); + DeepCopy(original, result, context); + return result; + } + + public Copier_HelloGrain(global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier) + { + this._baseTypeCopier = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeCopier); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::TestProject.HelloGrain input, global::TestProject.HelloGrain output, global::Orleans.Serialization.Cloning.CopyContext context) + { + _baseTypeCopier.DeepCopy(input, output, context); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Activator_HelloGrain : global::Orleans.Serialization.Activators.IActivator + { + public global::TestProject.HelloGrain Create() => new global::TestProject.HelloGrain(); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class RpcResponseFactories : global::Orleans.Serialization.SerializerContext + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) + { + options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); + options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); + options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); +#if NET5_0_OR_GREATER + if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) + return; + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(string)); + options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); + options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); + options.AddDefaultSerializerService(static provider => new CompletedResponseActivator()); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); +#endif + } + + private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator + { + public CompletedResponseActivator() + { + } + + public global::Orleans.Serialization.Invocation.CompletedResponse Create() => global::Orleans.Serialization.Invocation.CompletedResponse.Instance; + } + + private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer + { + public ResponseFieldCodec() + { + } + } + + private sealed class ResponseFieldCopier : global::Orleans.Serialization.Cloning.IDeepCopier + { + public ResponseFieldCopier() + { + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public global::Orleans.Serialization.Invocation.Response DeepCopy(global::Orleans.Serialization.Invocation.Response input, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context is null) + throw new global::System.ArgumentNullException(nameof(context)); + if (input is global::Orleans.Serialization.Invocation.CompletedResponse or global::Orleans.Serialization.Invocation.ExceptionResponse) + return input; + return (global::Orleans.Serialization.Invocation.Response)global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context); + } + } + } + + internal sealed class RpcResponse_9146C7E3 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal string Value; + private RpcResponse_9146C7E3Factory _factory; + public RpcResponse_9146C7E3() + { + } + + internal static RpcResponse_9146C7E3 Rent(string value, RpcResponse_9146C7E3Factory factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); + result.Value = value; + result._factory = factory; + return result; + } + + public override object Result { get => Value; set => Value = (string)value; } + + public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } + + public override global::System.Type GetSimpleResultType() => typeof(string); + public override T GetResult() + { + if (typeof(T) == typeof(string)) + return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); + return (T)(object)Value; + } + + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) + throw new global::System.ObjectDisposedException(GetType().Name); + writer.WriteStartObject(0, null, typeof(string)); + if (Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, Value); + } + + writer.WriteEndObject(); + } + + public override void Dispose() + { + if (_factory is null) + return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; + private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; + public bool IsSupported { get; } + + internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec(); + provider.GetDeepCopier(); + provider.GetCodec>(); + provider.GetDeepCopier>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + } + + public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec() as global::Orleans.Serialization.Codecs.StringCodec; + _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; + var responseCodec = provider.GetCodec>(); + var responseCopier = provider.GetDeepCopier>(); + IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + } + + internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + return RpcResponse_9146C7E3.Rent(value, this); + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public RpcResponse_9146C7E3 DeepCopy(RpcResponse_9146C7E3 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_9146C7E3.Rent(input.Value, this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, string value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof(string)); + if (value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value); + } + + writer.WriteEndObject(); + } + + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = RpcResponse_9146C7E3.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, field); + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + + return result; + } + catch + { + result.Dispose(); + throw; + } + } + + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_9146C7E3 value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); + if (value.Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value.Value); + } + + writer.WriteEndObject(); + } + + public RpcResponse_9146C7E3 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IHelloGrain_GrainReference_5336307F)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_HelloGrain)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IHelloGrain_GrainReference_5336307F)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_HelloGrain)); + config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IHelloGrain)); + config.AddInterface(typeof(global::TestProject.IHelloGrain)); + config.AddInterfaceImplementation(typeof(global::TestProject.HelloGrain)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_HelloGrain)); + var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); + var n2 = n1.GetOrAdd(typeof(global::Orleans.Runtime.GrainReference)); + var n3 = n2.GetOrAdd(typeof(global::TestProject.IHelloGrain)); + n3.Add("5336307F", typeof(OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F)); + } + } +} +#pragma warning restore \ No newline at end of file diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.verified.cs index dd42b6d4396..1411ec351c9 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.verified.cs @@ -1,6 +1,4 @@ -// -#nullable disable -[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] #pragma warning disable [assembly: global::Orleans.ApplicationPartAttribute("TestProject")] [assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] @@ -15,11 +13,11 @@ namespace OrleansCodeGen.TestProject [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IHelloGrain), "5336307F")] - public sealed class Invokable_IHelloGrain_GrainReference_5336307F : global::Orleans.Runtime.TaskRequest + public sealed class Invokable_IHelloGrain_GrainReference_5336307F : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable { public string arg0; global::TestProject.IHelloGrain _target; - private static readonly global::System.Reflection.MethodInfo MethodBackingField = OrleansGeneratedCodeHelper.GetMethodInfoOrDefault(typeof(global::TestProject.IHelloGrain), "SayHello", null, new[] { typeof(string) }); + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IHelloGrain).GetMethod("SayHello", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new[] { typeof(string) }, null); public Invokable_IHelloGrain_GrainReference_5336307F() : base() { SetLoggingOptions("Hello"); @@ -64,6 +62,21 @@ public override void SetArgument(int index, object value) } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.SayHello(arg0); + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + string value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] @@ -82,6 +95,7 @@ public Proxy_IHelloGrain(global::Orleans.Runtime.GrainReferenceShared arg0, glob } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IHelloGrain_GrainReference_5336307F : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F); @@ -144,6 +158,7 @@ public OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IHelloGrain_GrainReference_5336307F : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -158,6 +173,7 @@ public OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_HelloGrain : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.HelloGrain); @@ -218,6 +234,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_HelloGrain : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; @@ -257,6 +274,9 @@ internal sealed class RpcResponseFactories : global::Orleans.Serialization.Seria { protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) { + options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); + options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); + options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); #if NET5_0_OR_GREATER if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) return; @@ -313,6 +333,154 @@ public ResponseFieldCopier() } } + internal sealed class RpcResponse_9146C7E3 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal string Value; + private RpcResponse_9146C7E3Factory _factory; + public RpcResponse_9146C7E3() + { + } + + internal static RpcResponse_9146C7E3 Rent(string value, RpcResponse_9146C7E3Factory factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); + result.Value = value; + result._factory = factory; + return result; + } + + public override object Result { get => Value; set => Value = (string)value; } + public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } + + public override global::System.Type GetSimpleResultType() => typeof(string); + public override T GetResult() + { + if (typeof(T) == typeof(string)) + return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); + return (T)(object)Value; + } + + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) + throw new global::System.ObjectDisposedException(GetType().Name); + writer.WriteStartObject(0, null, typeof(string)); + if (Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, Value); + } + + writer.WriteEndObject(); + } + + public override void Dispose() + { + if (_factory is null) + return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; + private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; + public bool IsSupported { get; } + + internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec(); + provider.GetDeepCopier(); + provider.GetCodec>(); + provider.GetDeepCopier>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + } + + public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec() as global::Orleans.Serialization.Codecs.StringCodec; + _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; + var responseCodec = provider.GetCodec>(); + var responseCopier = provider.GetDeepCopier>(); + IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + } + + internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + return RpcResponse_9146C7E3.Rent(value, this); + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public RpcResponse_9146C7E3 DeepCopy(RpcResponse_9146C7E3 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_9146C7E3.Rent(input.Value, this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, string value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof(string)); + if (value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value); + } + + writer.WriteEndObject(); + } + + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = RpcResponse_9146C7E3.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, field); + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + + return result; + } + catch + { + result.Dispose(); + throw; + } + } + + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_9146C7E3 value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); + if (value.Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value.Value); + } + + writer.WriteEndObject(); + } + + public RpcResponse_9146C7E3 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase { diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs new file mode 100644 index 00000000000..a88dcc50ab8 --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs @@ -0,0 +1,401 @@ +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] +#pragma warning disable +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IResponseTimeoutGrain), "6BE752C8")] + public sealed class Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + { + public string arg0; + global::TestProject.IResponseTimeoutGrain _target; + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IResponseTimeoutGrain).GetMethod("LongRunningMethod", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new[] { typeof(string) }, null); + private static readonly global::System.TimeSpan _responseTimeoutValue = global::System.TimeSpan.FromTicks(100000000L); + public override global::System.TimeSpan? GetDefaultResponseTimeout() => _responseTimeoutValue; + public override int GetArgumentCount() => 1; + public override string GetMethodName() => "LongRunningMethod"; + public override string GetInterfaceName() => "TestProject.IResponseTimeoutGrain"; + public override string GetActivityName() => "IResponseTimeoutGrain/LongRunningMethod"; + public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IResponseTimeoutGrain); + public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; + public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = (global::TestProject.IResponseTimeoutGrain)holder.GetTarget(); + public override object GetTarget() => _target; + public override void Dispose() + { + arg0 = default; + _target = default; + } + + public override object GetArgument(int index) + { + switch (index) + { + case 0: + return arg0; + default: + return OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + } + } + + public override void SetArgument(int index, object value) + { + switch (index) + { + case 0: + arg0 = (string)value; + return; + default: + OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + return; + } + } + + protected override global::System.Threading.Tasks.Task InvokeInner() => _target.LongRunningMethod(arg0); + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + string value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Proxy_IResponseTimeoutGrain : global::Orleans.Runtime.GrainReference, global::TestProject.IResponseTimeoutGrain + { + public Proxy_IResponseTimeoutGrain(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) + { + } + + global::System.Threading.Tasks.Task global::TestProject.IResponseTimeoutGrain.LongRunningMethod(string arg0) + { + var request = new OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8(); + request.arg0 = arg0; + return base.InvokeAsync(request).AsTask(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 : global::Orleans.Serialization.Codecs.IFieldCodec + { + private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.arg0); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + instance.arg0 = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null) + { + ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + var result = new OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8(); + ReferenceCodec.MarkValueField(reader.Session); + Deserialize(ref reader, result); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 : global::Orleans.Serialization.Cloning.IDeepCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 DeepCopy(OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (original is null) + return null; + var result = new OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8(); + result.arg0 = original.arg0; + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class RpcResponseFactories : global::Orleans.Serialization.SerializerContext + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) + { + options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); + options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); + options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); +#if NET5_0_OR_GREATER + if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) + return; + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(string)); + options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); + options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); + options.AddDefaultSerializerService(static provider => new CompletedResponseActivator()); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); +#endif + } + + private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator + { + public CompletedResponseActivator() + { + } + + public global::Orleans.Serialization.Invocation.CompletedResponse Create() => global::Orleans.Serialization.Invocation.CompletedResponse.Instance; + } + + private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer + { + public ResponseFieldCodec() + { + } + } + + private sealed class ResponseFieldCopier : global::Orleans.Serialization.Cloning.IDeepCopier + { + public ResponseFieldCopier() + { + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public global::Orleans.Serialization.Invocation.Response DeepCopy(global::Orleans.Serialization.Invocation.Response input, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context is null) + throw new global::System.ArgumentNullException(nameof(context)); + if (input is global::Orleans.Serialization.Invocation.CompletedResponse or global::Orleans.Serialization.Invocation.ExceptionResponse) + return input; + return (global::Orleans.Serialization.Invocation.Response)global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context); + } + } + } + + internal sealed class RpcResponse_9146C7E3 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal string Value; + private RpcResponse_9146C7E3Factory _factory; + public RpcResponse_9146C7E3() + { + } + + internal static RpcResponse_9146C7E3 Rent(string value, RpcResponse_9146C7E3Factory factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); + result.Value = value; + result._factory = factory; + return result; + } + + public override object Result { get => Value; set => Value = (string)value; } + public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } + + public override global::System.Type GetSimpleResultType() => typeof(string); + public override T GetResult() + { + if (typeof(T) == typeof(string)) + return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); + return (T)(object)Value; + } + + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) + throw new global::System.ObjectDisposedException(GetType().Name); + writer.WriteStartObject(0, null, typeof(string)); + if (Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, Value); + } + + writer.WriteEndObject(); + } + + public override void Dispose() + { + if (_factory is null) + return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; + private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; + public bool IsSupported { get; } + + internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec(); + provider.GetDeepCopier(); + provider.GetCodec>(); + provider.GetDeepCopier>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + } + + public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec() as global::Orleans.Serialization.Codecs.StringCodec; + _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; + var responseCodec = provider.GetCodec>(); + var responseCopier = provider.GetDeepCopier>(); + IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + } + + internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + return RpcResponse_9146C7E3.Rent(value, this); + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public RpcResponse_9146C7E3 DeepCopy(RpcResponse_9146C7E3 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_9146C7E3.Rent(input.Value, this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, string value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof(string)); + if (value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value); + } + + writer.WriteEndObject(); + } + + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = RpcResponse_9146C7E3.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, field); + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + + return result; + } + catch + { + result.Dispose(); + throw; + } + } + + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_9146C7E3 value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); + if (value.Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value.Value); + } + + writer.WriteEndObject(); + } + + public RpcResponse_9146C7E3 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8)); + config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IResponseTimeoutGrain)); + config.AddInterface(typeof(global::TestProject.IResponseTimeoutGrain)); + config.AddInterfaceImplementation(typeof(global::TestProject.ResponseTimeoutGrain)); + var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); + var n2 = n1.GetOrAdd(typeof(global::Orleans.Runtime.GrainReference)); + var n3 = n2.GetOrAdd(typeof(global::TestProject.IResponseTimeoutGrain)); + n3.Add("6BE752C8", typeof(OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8)); + } + } +} +#pragma warning restore \ No newline at end of file diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs new file mode 100644 index 00000000000..94f2edadeaa --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs @@ -0,0 +1,402 @@ +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] +#pragma warning disable +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IResponseTimeoutGrain), "6BE752C8")] + public sealed class Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + { + public string arg0; + global::TestProject.IResponseTimeoutGrain _target; + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IResponseTimeoutGrain).GetMethod("LongRunningMethod", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new[] { typeof(string) }, null); + private static readonly global::System.TimeSpan _responseTimeoutValue = global::System.TimeSpan.FromTicks(100000000L); + public override global::System.TimeSpan? GetDefaultResponseTimeout() => _responseTimeoutValue; + public override int GetArgumentCount() => 1; + public override string GetMethodName() => "LongRunningMethod"; + public override string GetInterfaceName() => "TestProject.IResponseTimeoutGrain"; + public override string GetActivityName() => "IResponseTimeoutGrain/LongRunningMethod"; + public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IResponseTimeoutGrain); + public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; + public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = (global::TestProject.IResponseTimeoutGrain)holder.GetTarget(); + public override object GetTarget() => _target; + public override void Dispose() + { + arg0 = default; + _target = default; + } + + public override object GetArgument(int index) + { + switch (index) + { + case 0: + return arg0; + default: + return OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + } + } + + public override void SetArgument(int index, object value) + { + switch (index) + { + case 0: + arg0 = (string)value; + return; + default: + OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + return; + } + } + + protected override global::System.Threading.Tasks.Task InvokeInner() => _target.LongRunningMethod(arg0); + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + string value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Proxy_IResponseTimeoutGrain : global::Orleans.Runtime.GrainReference, global::TestProject.IResponseTimeoutGrain + { + public Proxy_IResponseTimeoutGrain(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) + { + } + + global::System.Threading.Tasks.Task global::TestProject.IResponseTimeoutGrain.LongRunningMethod(string arg0) + { + var request = new OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8(); + request.arg0 = arg0; + return base.InvokeAsync(request).AsTask(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 : global::Orleans.Serialization.Codecs.IFieldCodec + { + private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.arg0); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + instance.arg0 = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null) + { + ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + var result = new OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8(); + ReferenceCodec.MarkValueField(reader.Session); + Deserialize(ref reader, result); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 : global::Orleans.Serialization.Cloning.IDeepCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 DeepCopy(OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (original is null) + return null; + var result = new OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8(); + result.arg0 = original.arg0; + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class RpcResponseFactories : global::Orleans.Serialization.SerializerContext + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) + { + options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); + options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); + options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); +#if NET5_0_OR_GREATER + if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) + return; + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(string)); + options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); + options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); + options.AddDefaultSerializerService(static provider => new CompletedResponseActivator()); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); +#endif + } + + private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator + { + public CompletedResponseActivator() + { + } + + public global::Orleans.Serialization.Invocation.CompletedResponse Create() => global::Orleans.Serialization.Invocation.CompletedResponse.Instance; + } + + private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer + { + public ResponseFieldCodec() + { + } + } + + private sealed class ResponseFieldCopier : global::Orleans.Serialization.Cloning.IDeepCopier + { + public ResponseFieldCopier() + { + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public global::Orleans.Serialization.Invocation.Response DeepCopy(global::Orleans.Serialization.Invocation.Response input, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context is null) + throw new global::System.ArgumentNullException(nameof(context)); + if (input is global::Orleans.Serialization.Invocation.CompletedResponse or global::Orleans.Serialization.Invocation.ExceptionResponse) + return input; + return (global::Orleans.Serialization.Invocation.Response)global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context); + } + } + } + + internal sealed class RpcResponse_9146C7E3 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal string Value; + private RpcResponse_9146C7E3Factory _factory; + public RpcResponse_9146C7E3() + { + } + + internal static RpcResponse_9146C7E3 Rent(string value, RpcResponse_9146C7E3Factory factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); + result.Value = value; + result._factory = factory; + return result; + } + + public override object Result { get => Value; set => Value = (string)value; } + + public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } + + public override global::System.Type GetSimpleResultType() => typeof(string); + public override T GetResult() + { + if (typeof(T) == typeof(string)) + return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); + return (T)(object)Value; + } + + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) + throw new global::System.ObjectDisposedException(GetType().Name); + writer.WriteStartObject(0, null, typeof(string)); + if (Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, Value); + } + + writer.WriteEndObject(); + } + + public override void Dispose() + { + if (_factory is null) + return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; + private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; + public bool IsSupported { get; } + + internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec(); + provider.GetDeepCopier(); + provider.GetCodec>(); + provider.GetDeepCopier>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + } + + public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec() as global::Orleans.Serialization.Codecs.StringCodec; + _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; + var responseCodec = provider.GetCodec>(); + var responseCopier = provider.GetDeepCopier>(); + IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + } + + internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + return RpcResponse_9146C7E3.Rent(value, this); + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public RpcResponse_9146C7E3 DeepCopy(RpcResponse_9146C7E3 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_9146C7E3.Rent(input.Value, this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, string value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof(string)); + if (value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value); + } + + writer.WriteEndObject(); + } + + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = RpcResponse_9146C7E3.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, field); + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + + return result; + } + catch + { + result.Dispose(); + throw; + } + } + + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_9146C7E3 value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); + if (value.Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value.Value); + } + + writer.WriteEndObject(); + } + + public RpcResponse_9146C7E3 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8)); + config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IResponseTimeoutGrain)); + config.AddInterface(typeof(global::TestProject.IResponseTimeoutGrain)); + config.AddInterfaceImplementation(typeof(global::TestProject.ResponseTimeoutGrain)); + var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); + var n2 = n1.GetOrAdd(typeof(global::Orleans.Runtime.GrainReference)); + var n3 = n2.GetOrAdd(typeof(global::TestProject.IResponseTimeoutGrain)); + n3.Add("6BE752C8", typeof(OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8)); + } + } +} +#pragma warning restore \ No newline at end of file diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.verified.cs index 4766710ef07..f6888e60505 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.verified.cs @@ -1,6 +1,4 @@ -// -#nullable disable -[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] #pragma warning disable [assembly: global::Orleans.ApplicationPartAttribute("TestProject")] [assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] @@ -15,11 +13,11 @@ namespace OrleansCodeGen.TestProject [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IResponseTimeoutGrain), "6BE752C8")] - public sealed class Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 : global::Orleans.Runtime.TaskRequest + public sealed class Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable { public string arg0; global::TestProject.IResponseTimeoutGrain _target; - private static readonly global::System.Reflection.MethodInfo MethodBackingField = OrleansGeneratedCodeHelper.GetMethodInfoOrDefault(typeof(global::TestProject.IResponseTimeoutGrain), "LongRunningMethod", null, new[] { typeof(string) }); + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IResponseTimeoutGrain).GetMethod("LongRunningMethod", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new[] { typeof(string) }, null); private static readonly global::System.TimeSpan _responseTimeoutValue = global::System.TimeSpan.FromTicks(100000000L); public override global::System.TimeSpan? GetDefaultResponseTimeout() => _responseTimeoutValue; public override int GetArgumentCount() => 1; @@ -61,6 +59,21 @@ public override void SetArgument(int index, object value) } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.LongRunningMethod(arg0); + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + string value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] @@ -79,6 +92,7 @@ public Proxy_IResponseTimeoutGrain(global::Orleans.Runtime.GrainReferenceShared } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8); @@ -141,6 +155,7 @@ public OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -159,6 +174,9 @@ internal sealed class RpcResponseFactories : global::Orleans.Serialization.Seria { protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) { + options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); + options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); + options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); #if NET5_0_OR_GREATER if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) return; @@ -215,6 +233,154 @@ public ResponseFieldCopier() } } + internal sealed class RpcResponse_9146C7E3 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal string Value; + private RpcResponse_9146C7E3Factory _factory; + public RpcResponse_9146C7E3() + { + } + + internal static RpcResponse_9146C7E3 Rent(string value, RpcResponse_9146C7E3Factory factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); + result.Value = value; + result._factory = factory; + return result; + } + + public override object Result { get => Value; set => Value = (string)value; } + public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } + + public override global::System.Type GetSimpleResultType() => typeof(string); + public override T GetResult() + { + if (typeof(T) == typeof(string)) + return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); + return (T)(object)Value; + } + + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) + throw new global::System.ObjectDisposedException(GetType().Name); + writer.WriteStartObject(0, null, typeof(string)); + if (Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, Value); + } + + writer.WriteEndObject(); + } + + public override void Dispose() + { + if (_factory is null) + return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; + private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; + public bool IsSupported { get; } + + internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec(); + provider.GetDeepCopier(); + provider.GetCodec>(); + provider.GetDeepCopier>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + } + + public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec() as global::Orleans.Serialization.Codecs.StringCodec; + _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; + var responseCodec = provider.GetCodec>(); + var responseCopier = provider.GetDeepCopier>(); + IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + } + + internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + return RpcResponse_9146C7E3.Rent(value, this); + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public RpcResponse_9146C7E3 DeepCopy(RpcResponse_9146C7E3 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_9146C7E3.Rent(input.Value, this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, string value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof(string)); + if (value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value); + } + + writer.WriteEndObject(); + } + + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = RpcResponse_9146C7E3.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, field); + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + + return result; + } + catch + { + result.Dispose(); + throw; + } + } + + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_9146C7E3 value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); + if (value.Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value.Value); + } + + writer.WriteEndObject(); + } + + public RpcResponse_9146C7E3 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase { diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs new file mode 100644 index 00000000000..ffb287d2631 --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs @@ -0,0 +1,1561 @@ +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] +#pragma warning disable +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IMyGrainWithGuidKey), "8F0FEC0E")] + public sealed class Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + { + global::TestProject.IMyGrainWithGuidKey _target; + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IMyGrainWithGuidKey).GetMethod("GetGuidValue", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, global::System.Type.EmptyTypes, null); + public override string GetMethodName() => "GetGuidValue"; + public override string GetInterfaceName() => "TestProject.IMyGrainWithGuidKey"; + public override string GetActivityName() => "IMyGrainWithGuidKey/GetGuidValue"; + public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IMyGrainWithGuidKey); + public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; + public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = (global::TestProject.IMyGrainWithGuidKey)holder.GetTarget(); + public override object GetTarget() => _target; + public override void Dispose() + { + _target = default; + } + + protected override global::System.Threading.Tasks.Task InvokeInner() => _target.GetGuidValue(); + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_5C3A711CFactory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + global::System.Guid value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Proxy_IMyGrainWithGuidKey : global::Orleans.Runtime.GrainReference, global::TestProject.IMyGrainWithGuidKey + { + public Proxy_IMyGrainWithGuidKey(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) + { + } + + global::System.Threading.Tasks.Task global::TestProject.IMyGrainWithGuidKey.GetGuidValue() + { + var request = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E(); + return base.InvokeAsync(request).AsTask(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IMyGrainWithStringKey), "43570316")] + public sealed class Invokable_IMyGrainWithStringKey_GrainReference_43570316 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + { + global::TestProject.IMyGrainWithStringKey _target; + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IMyGrainWithStringKey).GetMethod("GetStringKey", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, global::System.Type.EmptyTypes, null); + public override string GetMethodName() => "GetStringKey"; + public override string GetInterfaceName() => "TestProject.IMyGrainWithStringKey"; + public override string GetActivityName() => "IMyGrainWithStringKey/GetStringKey"; + public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IMyGrainWithStringKey); + public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; + public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = (global::TestProject.IMyGrainWithStringKey)holder.GetTarget(); + public override object GetTarget() => _target; + public override void Dispose() + { + _target = default; + } + + protected override global::System.Threading.Tasks.Task InvokeInner() => _target.GetStringKey(); + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + string value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Proxy_IMyGrainWithStringKey : global::Orleans.Runtime.GrainReference, global::TestProject.IMyGrainWithStringKey + { + public Proxy_IMyGrainWithStringKey(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) + { + } + + global::System.Threading.Tasks.Task global::TestProject.IMyGrainWithStringKey.GetStringKey() + { + var request = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316(); + return base.InvokeAsync(request).AsTask(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IMyGrainWithGuidCompoundKey), "A9FEF7AF")] + public sealed class Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF : global::Orleans.Runtime.TaskRequest>, global::Orleans.Serialization.Invocation.IResponseInvokable + { + global::TestProject.IMyGrainWithGuidCompoundKey _target; + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IMyGrainWithGuidCompoundKey).GetMethod("GetGuidAndStringKey", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, global::System.Type.EmptyTypes, null); + public override string GetMethodName() => "GetGuidAndStringKey"; + public override string GetInterfaceName() => "TestProject.IMyGrainWithGuidCompoundKey"; + public override string GetActivityName() => "IMyGrainWithGuidCompoundKey/GetGuidAndStringKey"; + public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IMyGrainWithGuidCompoundKey); + public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; + public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = (global::TestProject.IMyGrainWithGuidCompoundKey)holder.GetTarget(); + public override object GetTarget() => _target; + public override void Dispose() + { + _target = default; + } + + protected override global::System.Threading.Tasks.Task> InvokeInner() => _target.GetGuidAndStringKey(); + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_6A3EE8F4Factory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + global::System.Tuple value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Proxy_IMyGrainWithGuidCompoundKey : global::Orleans.Runtime.GrainReference, global::TestProject.IMyGrainWithGuidCompoundKey + { + public Proxy_IMyGrainWithGuidCompoundKey(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) + { + } + + global::System.Threading.Tasks.Task> global::TestProject.IMyGrainWithGuidCompoundKey.GetGuidAndStringKey() + { + var request = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF(); + return base.InvokeAsync>(request).AsTask(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IMyGrainWithIntegerCompoundKey), "9814021A")] + public sealed class Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A : global::Orleans.Runtime.TaskRequest>, global::Orleans.Serialization.Invocation.IResponseInvokable + { + global::TestProject.IMyGrainWithIntegerCompoundKey _target; + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IMyGrainWithIntegerCompoundKey).GetMethod("GetIntegerAndStringKey", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, global::System.Type.EmptyTypes, null); + public override string GetMethodName() => "GetIntegerAndStringKey"; + public override string GetInterfaceName() => "TestProject.IMyGrainWithIntegerCompoundKey"; + public override string GetActivityName() => "IMyGrainWithIntegerCompoundKey/GetIntegerAndStringKey"; + public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IMyGrainWithIntegerCompoundKey); + public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; + public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = (global::TestProject.IMyGrainWithIntegerCompoundKey)holder.GetTarget(); + public override object GetTarget() => _target; + public override void Dispose() + { + _target = default; + } + + protected override global::System.Threading.Tasks.Task> InvokeInner() => _target.GetIntegerAndStringKey(); + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_AFB713E4Factory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + global::System.Tuple value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Proxy_IMyGrainWithIntegerCompoundKey : global::Orleans.Runtime.GrainReference, global::TestProject.IMyGrainWithIntegerCompoundKey + { + public Proxy_IMyGrainWithIntegerCompoundKey(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) + { + } + + global::System.Threading.Tasks.Task> global::TestProject.IMyGrainWithIntegerCompoundKey.GetIntegerAndStringKey() + { + var request = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A(); + return base.InvokeAsync>(request).AsTask(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E : global::Orleans.Serialization.Codecs.IFieldCodec + { + private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E instance) + { + reader.ConsumeEndBaseOrEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null) + { + ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + var result = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E(); + ReferenceCodec.MarkValueField(reader.Session); + Deserialize(ref reader, result); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E : global::Orleans.Serialization.Cloning.IDeepCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E DeepCopy(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (original is null) + return null; + var result = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E(); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_GrainWithGuidKey : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GrainWithGuidKey); + private readonly global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer; + public Codec_GrainWithGuidKey(global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer) + { + this._baseTypeSerializer = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeSerializer); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.GrainWithGuidKey instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + _baseTypeSerializer.Serialize(ref writer, instance); + writer.WriteEndBase(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.GrainWithGuidKey instance) + { + _baseTypeSerializer.Deserialize(ref reader, instance); + reader.ConsumeEndBaseOrEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.GrainWithGuidKey @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::TestProject.GrainWithGuidKey)) + { + if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) + return; + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.GrainWithGuidKey ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = new global::TestProject.GrainWithGuidKey(); + ReferenceCodec.RecordObject(reader.Session, result); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_GrainWithGuidKey : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.GrainWithGuidKey DeepCopy(global::TestProject.GrainWithGuidKey original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context.TryGetCopy(original, out global::TestProject.GrainWithGuidKey existing)) + return existing; + if (original.GetType() != typeof(global::TestProject.GrainWithGuidKey)) + return context.DeepCopy(original); + var result = new global::TestProject.GrainWithGuidKey(); + context.RecordCopy(original, result); + DeepCopy(original, result, context); + return result; + } + + public Copier_GrainWithGuidKey(global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier) + { + this._baseTypeCopier = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeCopier); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::TestProject.GrainWithGuidKey input, global::TestProject.GrainWithGuidKey output, global::Orleans.Serialization.Cloning.CopyContext context) + { + _baseTypeCopier.DeepCopy(input, output, context); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Activator_GrainWithGuidKey : global::Orleans.Serialization.Activators.IActivator + { + public global::TestProject.GrainWithGuidKey Create() => new global::TestProject.GrainWithGuidKey(); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_Invokable_IMyGrainWithStringKey_GrainReference_43570316 : global::Orleans.Serialization.Codecs.IFieldCodec + { + private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316 instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316 instance) + { + reader.ConsumeEndBaseOrEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316 @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null) + { + ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + var result = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316(); + ReferenceCodec.MarkValueField(reader.Session); + Deserialize(ref reader, result); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_Invokable_IMyGrainWithStringKey_GrainReference_43570316 : global::Orleans.Serialization.Cloning.IDeepCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316 DeepCopy(OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316 original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (original is null) + return null; + var result = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316(); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_GrainWithStringKey : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GrainWithStringKey); + private readonly global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer; + public Codec_GrainWithStringKey(global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer) + { + this._baseTypeSerializer = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeSerializer); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.GrainWithStringKey instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + _baseTypeSerializer.Serialize(ref writer, instance); + writer.WriteEndBase(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.GrainWithStringKey instance) + { + _baseTypeSerializer.Deserialize(ref reader, instance); + reader.ConsumeEndBaseOrEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.GrainWithStringKey @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::TestProject.GrainWithStringKey)) + { + if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) + return; + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.GrainWithStringKey ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = new global::TestProject.GrainWithStringKey(); + ReferenceCodec.RecordObject(reader.Session, result); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_GrainWithStringKey : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.GrainWithStringKey DeepCopy(global::TestProject.GrainWithStringKey original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context.TryGetCopy(original, out global::TestProject.GrainWithStringKey existing)) + return existing; + if (original.GetType() != typeof(global::TestProject.GrainWithStringKey)) + return context.DeepCopy(original); + var result = new global::TestProject.GrainWithStringKey(); + context.RecordCopy(original, result); + DeepCopy(original, result, context); + return result; + } + + public Copier_GrainWithStringKey(global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier) + { + this._baseTypeCopier = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeCopier); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::TestProject.GrainWithStringKey input, global::TestProject.GrainWithStringKey output, global::Orleans.Serialization.Cloning.CopyContext context) + { + _baseTypeCopier.DeepCopy(input, output, context); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Activator_GrainWithStringKey : global::Orleans.Serialization.Activators.IActivator + { + public global::TestProject.GrainWithStringKey Create() => new global::TestProject.GrainWithStringKey(); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF : global::Orleans.Serialization.Codecs.IFieldCodec + { + private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF instance) + { + reader.ConsumeEndBaseOrEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null) + { + ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + var result = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF(); + ReferenceCodec.MarkValueField(reader.Session); + Deserialize(ref reader, result); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF : global::Orleans.Serialization.Cloning.IDeepCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF DeepCopy(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (original is null) + return null; + var result = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF(); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_GrainWithGuidCompoundKey : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GrainWithGuidCompoundKey); + private readonly global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer; + public Codec_GrainWithGuidCompoundKey(global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer) + { + this._baseTypeSerializer = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeSerializer); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.GrainWithGuidCompoundKey instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + _baseTypeSerializer.Serialize(ref writer, instance); + writer.WriteEndBase(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.GrainWithGuidCompoundKey instance) + { + _baseTypeSerializer.Deserialize(ref reader, instance); + reader.ConsumeEndBaseOrEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.GrainWithGuidCompoundKey @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::TestProject.GrainWithGuidCompoundKey)) + { + if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) + return; + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.GrainWithGuidCompoundKey ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = new global::TestProject.GrainWithGuidCompoundKey(); + ReferenceCodec.RecordObject(reader.Session, result); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_GrainWithGuidCompoundKey : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.GrainWithGuidCompoundKey DeepCopy(global::TestProject.GrainWithGuidCompoundKey original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context.TryGetCopy(original, out global::TestProject.GrainWithGuidCompoundKey existing)) + return existing; + if (original.GetType() != typeof(global::TestProject.GrainWithGuidCompoundKey)) + return context.DeepCopy(original); + var result = new global::TestProject.GrainWithGuidCompoundKey(); + context.RecordCopy(original, result); + DeepCopy(original, result, context); + return result; + } + + public Copier_GrainWithGuidCompoundKey(global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier) + { + this._baseTypeCopier = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeCopier); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::TestProject.GrainWithGuidCompoundKey input, global::TestProject.GrainWithGuidCompoundKey output, global::Orleans.Serialization.Cloning.CopyContext context) + { + _baseTypeCopier.DeepCopy(input, output, context); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Activator_GrainWithGuidCompoundKey : global::Orleans.Serialization.Activators.IActivator + { + public global::TestProject.GrainWithGuidCompoundKey Create() => new global::TestProject.GrainWithGuidCompoundKey(); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A : global::Orleans.Serialization.Codecs.IFieldCodec + { + private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A instance) + { + reader.ConsumeEndBaseOrEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null) + { + ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + var result = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A(); + ReferenceCodec.MarkValueField(reader.Session); + Deserialize(ref reader, result); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A : global::Orleans.Serialization.Cloning.IDeepCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A DeepCopy(OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (original is null) + return null; + var result = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A(); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_GrainWithIntegerCompoundKey : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GrainWithIntegerCompoundKey); + private readonly global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer; + public Codec_GrainWithIntegerCompoundKey(global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer) + { + this._baseTypeSerializer = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeSerializer); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.GrainWithIntegerCompoundKey instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + _baseTypeSerializer.Serialize(ref writer, instance); + writer.WriteEndBase(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.GrainWithIntegerCompoundKey instance) + { + _baseTypeSerializer.Deserialize(ref reader, instance); + reader.ConsumeEndBaseOrEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.GrainWithIntegerCompoundKey @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::TestProject.GrainWithIntegerCompoundKey)) + { + if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) + return; + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.GrainWithIntegerCompoundKey ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = new global::TestProject.GrainWithIntegerCompoundKey(); + ReferenceCodec.RecordObject(reader.Session, result); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_GrainWithIntegerCompoundKey : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.GrainWithIntegerCompoundKey DeepCopy(global::TestProject.GrainWithIntegerCompoundKey original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context.TryGetCopy(original, out global::TestProject.GrainWithIntegerCompoundKey existing)) + return existing; + if (original.GetType() != typeof(global::TestProject.GrainWithIntegerCompoundKey)) + return context.DeepCopy(original); + var result = new global::TestProject.GrainWithIntegerCompoundKey(); + context.RecordCopy(original, result); + DeepCopy(original, result, context); + return result; + } + + public Copier_GrainWithIntegerCompoundKey(global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier) + { + this._baseTypeCopier = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeCopier); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::TestProject.GrainWithIntegerCompoundKey input, global::TestProject.GrainWithIntegerCompoundKey output, global::Orleans.Serialization.Cloning.CopyContext context) + { + _baseTypeCopier.DeepCopy(input, output, context); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Activator_GrainWithIntegerCompoundKey : global::Orleans.Serialization.Activators.IActivator + { + public global::TestProject.GrainWithIntegerCompoundKey Create() => new global::TestProject.GrainWithIntegerCompoundKey(); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class RpcResponseFactories : global::Orleans.Serialization.SerializerContext + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) + { + options.AddDefaultSerializerService(static provider => new RpcResponse_5C3A711CFactory(provider)); + options.AddDefaultSerializer(static provider => RpcResponse_5C3A711CFactory.Resolve(provider), static provider => RpcResponse_5C3A711CFactory.Resolve(provider)); + options.AddRawResponseReader(static provider => RpcResponse_5C3A711CFactory.Resolve(provider)); + options.AddDefaultSerializerService(static provider => new RpcResponse_6A3EE8F4Factory(provider)); + options.AddDefaultSerializer(static provider => RpcResponse_6A3EE8F4Factory.Resolve(provider), static provider => RpcResponse_6A3EE8F4Factory.Resolve(provider)); + options.AddRawResponseReader>(static provider => RpcResponse_6A3EE8F4Factory.Resolve(provider)); + options.AddDefaultSerializerService(static provider => new RpcResponse_AFB713E4Factory(provider)); + options.AddDefaultSerializer(static provider => RpcResponse_AFB713E4Factory.Resolve(provider), static provider => RpcResponse_AFB713E4Factory.Resolve(provider)); + options.AddRawResponseReader>(static provider => RpcResponse_AFB713E4Factory.Resolve(provider)); + options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); + options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); + options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); +#if NET5_0_OR_GREATER + if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) + return; + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response>)); + options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response>)); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.GuidCodec()); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::System.Guid)); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::System.Tuple)); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::System.Tuple)); + options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.Int64Codec()); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(long)); + options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(string)); + options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); + options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); + options.AddDefaultSerializerService(static provider => new CompletedResponseActivator()); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); +#endif + } + + private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator + { + public CompletedResponseActivator() + { + } + + public global::Orleans.Serialization.Invocation.CompletedResponse Create() => global::Orleans.Serialization.Invocation.CompletedResponse.Instance; + } + + private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer + { + public ResponseFieldCodec() + { + } + } + + private sealed class ResponseFieldCopier : global::Orleans.Serialization.Cloning.IDeepCopier + { + public ResponseFieldCopier() + { + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public global::Orleans.Serialization.Invocation.Response DeepCopy(global::Orleans.Serialization.Invocation.Response input, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context is null) + throw new global::System.ArgumentNullException(nameof(context)); + if (input is global::Orleans.Serialization.Invocation.CompletedResponse or global::Orleans.Serialization.Invocation.ExceptionResponse) + return input; + return (global::Orleans.Serialization.Invocation.Response)global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context); + } + } + } + + internal sealed class RpcResponse_5C3A711C : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal global::System.Guid Value; + private RpcResponse_5C3A711CFactory _factory; + public RpcResponse_5C3A711C() + { + } + + internal static RpcResponse_5C3A711C Rent(global::System.Guid value, RpcResponse_5C3A711CFactory factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); + result.Value = value; + result._factory = factory; + return result; + } + + public override object Result { get => Value; set => Value = (global::System.Guid)value; } + public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } + + public override global::System.Type GetSimpleResultType() => typeof(global::System.Guid); + public override T GetResult() + { + if (typeof(T) == typeof(global::System.Guid)) + return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); + return (T)(object)Value; + } + + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) + throw new global::System.ObjectDisposedException(GetType().Name); + writer.WriteStartObject(0, null, typeof(global::System.Guid)); + global::Orleans.Serialization.Codecs.GuidCodec.WriteField(ref writer, 0, Value); + writer.WriteEndObject(); + } + + public override void Dispose() + { + if (_factory is null) + return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class RpcResponse_5C3A711CFactory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly global::Orleans.Serialization.Codecs.GuidCodec _codec; + private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; + public bool IsSupported { get; } + + internal static RpcResponse_5C3A711CFactory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec(); + provider.GetDeepCopier(); + provider.GetCodec>(); + provider.GetDeepCopier>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + } + + public RpcResponse_5C3A711CFactory(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec() as global::Orleans.Serialization.Codecs.GuidCodec; + _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; + var responseCodec = provider.GetCodec>(); + var responseCopier = provider.GetDeepCopier>(); + IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + } + + internal global::Orleans.Serialization.Invocation.Response RentCopied(global::System.Guid value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + return RpcResponse_5C3A711C.Rent(value, this); + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public RpcResponse_5C3A711C DeepCopy(RpcResponse_5C3A711C input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_5C3A711C.Rent(input.Value, this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, global::System.Guid value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof(global::System.Guid)); + global::Orleans.Serialization.Codecs.GuidCodec.WriteField(ref writer, 0, value); + writer.WriteEndObject(); + } + + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_5C3A711C)value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + private RpcResponse_5C3A711C ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = RpcResponse_5C3A711C.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = global::Orleans.Serialization.Codecs.GuidCodec.ReadValue(ref reader, field); + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + + return result; + } + catch + { + result.Dispose(); + throw; + } + } + + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_5C3A711C value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); + global::Orleans.Serialization.Codecs.GuidCodec.WriteField(ref writer, 0, value.Value); + writer.WriteEndObject(); + } + + public RpcResponse_5C3A711C ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + + internal sealed class RpcResponse_6A3EE8F4 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal global::System.Tuple Value; + private RpcResponse_6A3EE8F4Factory _factory; + public RpcResponse_6A3EE8F4() + { + } + + internal static RpcResponse_6A3EE8F4 Rent(global::System.Tuple value, RpcResponse_6A3EE8F4Factory factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); + result.Value = value; + result._factory = factory; + return result; + } + + public override object Result { get => Value; set => Value = (global::System.Tuple)value; } + public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } + + public override global::System.Type GetSimpleResultType() => typeof(global::System.Tuple); + public override T GetResult() + { + if (typeof(T) == typeof(global::System.Tuple)) + return global::System.Runtime.CompilerServices.Unsafe.As, T>(ref Value); + return (T)(object)Value; + } + + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) + throw new global::System.ObjectDisposedException(GetType().Name); + _factory.WriteResult(ref writer, Value); + } + + public override void Dispose() + { + if (_factory is null) + return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class RpcResponse_6A3EE8F4Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly global::Orleans.Serialization.Codecs.TupleCodec _codec; + private readonly global::Orleans.Serialization.Codecs.TupleCopier _copier; + public bool IsSupported { get; } + + internal static RpcResponse_6A3EE8F4Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec>(); + provider.GetDeepCopier>(); + provider.GetCodec>>(); + provider.GetDeepCopier>>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + } + + public RpcResponse_6A3EE8F4Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec>() as global::Orleans.Serialization.Codecs.TupleCodec; + _copier = provider.GetDeepCopier>() as global::Orleans.Serialization.Codecs.TupleCopier; + var responseCodec = provider.GetCodec>>(); + var responseCopier = provider.GetDeepCopier>>(); + IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec> || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec>>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Cloning.IDeepCopier>>); + } + + internal global::Orleans.Serialization.Invocation.Response RentCopied(global::System.Tuple value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + return RpcResponse_6A3EE8F4.Rent(value, this); + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public RpcResponse_6A3EE8F4 DeepCopy(RpcResponse_6A3EE8F4 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_6A3EE8F4.Rent(input.Value, this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, global::System.Tuple value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof(global::System.Tuple)); + if (value is not null) + { + _codec.WriteField(ref writer, 0, typeof(global::System.Tuple), value); + } + + writer.WriteEndObject(); + } + + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_6A3EE8F4)value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + private RpcResponse_6A3EE8F4 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = RpcResponse_6A3EE8F4.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = _codec.ReadValue(ref reader, field); + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + + return result; + } + catch + { + result.Dispose(); + throw; + } + } + + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_6A3EE8F4 value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response>)); + if (value.Value is not null) + { + _codec.WriteField(ref writer, 0, typeof(global::System.Tuple), value.Value); + } + + writer.WriteEndObject(); + } + + public RpcResponse_6A3EE8F4 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + + internal sealed class RpcResponse_AFB713E4 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal global::System.Tuple Value; + private RpcResponse_AFB713E4Factory _factory; + public RpcResponse_AFB713E4() + { + } + + internal static RpcResponse_AFB713E4 Rent(global::System.Tuple value, RpcResponse_AFB713E4Factory factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); + result.Value = value; + result._factory = factory; + return result; + } + + public override object Result { get => Value; set => Value = (global::System.Tuple)value; } + public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } + + public override global::System.Type GetSimpleResultType() => typeof(global::System.Tuple); + public override T GetResult() + { + if (typeof(T) == typeof(global::System.Tuple)) + return global::System.Runtime.CompilerServices.Unsafe.As, T>(ref Value); + return (T)(object)Value; + } + + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) + throw new global::System.ObjectDisposedException(GetType().Name); + _factory.WriteResult(ref writer, Value); + } + + public override void Dispose() + { + if (_factory is null) + return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class RpcResponse_AFB713E4Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly global::Orleans.Serialization.Codecs.TupleCodec _codec; + private readonly global::Orleans.Serialization.Codecs.TupleCopier _copier; + public bool IsSupported { get; } + + internal static RpcResponse_AFB713E4Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec>(); + provider.GetDeepCopier>(); + provider.GetCodec>>(); + provider.GetDeepCopier>>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + } + + public RpcResponse_AFB713E4Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec>() as global::Orleans.Serialization.Codecs.TupleCodec; + _copier = provider.GetDeepCopier>() as global::Orleans.Serialization.Codecs.TupleCopier; + var responseCodec = provider.GetCodec>>(); + var responseCopier = provider.GetDeepCopier>>(); + IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec> || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec>>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Cloning.IDeepCopier>>); + } + + internal global::Orleans.Serialization.Invocation.Response RentCopied(global::System.Tuple value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + return RpcResponse_AFB713E4.Rent(value, this); + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public RpcResponse_AFB713E4 DeepCopy(RpcResponse_AFB713E4 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_AFB713E4.Rent(input.Value, this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, global::System.Tuple value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof(global::System.Tuple)); + if (value is not null) + { + _codec.WriteField(ref writer, 0, typeof(global::System.Tuple), value); + } + + writer.WriteEndObject(); + } + + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_AFB713E4)value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + private RpcResponse_AFB713E4 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = RpcResponse_AFB713E4.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = _codec.ReadValue(ref reader, field); + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + + return result; + } + catch + { + result.Dispose(); + throw; + } + } + + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_AFB713E4 value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response>)); + if (value.Value is not null) + { + _codec.WriteField(ref writer, 0, typeof(global::System.Tuple), value.Value); + } + + writer.WriteEndObject(); + } + + public RpcResponse_AFB713E4 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + + internal sealed class RpcResponse_9146C7E3 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal string Value; + private RpcResponse_9146C7E3Factory _factory; + public RpcResponse_9146C7E3() + { + } + + internal static RpcResponse_9146C7E3 Rent(string value, RpcResponse_9146C7E3Factory factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); + result.Value = value; + result._factory = factory; + return result; + } + + public override object Result { get => Value; set => Value = (string)value; } + public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } + + public override global::System.Type GetSimpleResultType() => typeof(string); + public override T GetResult() + { + if (typeof(T) == typeof(string)) + return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); + return (T)(object)Value; + } + + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) + throw new global::System.ObjectDisposedException(GetType().Name); + writer.WriteStartObject(0, null, typeof(string)); + if (Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, Value); + } + + writer.WriteEndObject(); + } + + public override void Dispose() + { + if (_factory is null) + return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; + private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; + public bool IsSupported { get; } + + internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec(); + provider.GetDeepCopier(); + provider.GetCodec>(); + provider.GetDeepCopier>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + } + + public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec() as global::Orleans.Serialization.Codecs.StringCodec; + _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; + var responseCodec = provider.GetCodec>(); + var responseCopier = provider.GetDeepCopier>(); + IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + } + + internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + return RpcResponse_9146C7E3.Rent(value, this); + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public RpcResponse_9146C7E3 DeepCopy(RpcResponse_9146C7E3 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_9146C7E3.Rent(input.Value, this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, string value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof(string)); + if (value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value); + } + + writer.WriteEndObject(); + } + + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = RpcResponse_9146C7E3.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, field); + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + + return result; + } + catch + { + result.Dispose(); + throw; + } + } + + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_9146C7E3 value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); + if (value.Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value.Value); + } + + writer.WriteEndObject(); + } + + public RpcResponse_9146C7E3 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_GrainWithGuidKey)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IMyGrainWithStringKey_GrainReference_43570316)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_GrainWithStringKey)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_GrainWithGuidCompoundKey)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_GrainWithIntegerCompoundKey)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithGuidKey)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IMyGrainWithStringKey_GrainReference_43570316)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithStringKey)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithGuidCompoundKey)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithIntegerCompoundKey)); + config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IMyGrainWithGuidKey)); + config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IMyGrainWithStringKey)); + config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IMyGrainWithGuidCompoundKey)); + config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IMyGrainWithIntegerCompoundKey)); + config.AddInterface(typeof(global::TestProject.IMyGrainWithGuidKey)); + config.AddInterface(typeof(global::TestProject.IMyGrainWithStringKey)); + config.AddInterface(typeof(global::TestProject.IMyGrainWithGuidCompoundKey)); + config.AddInterface(typeof(global::TestProject.IMyGrainWithIntegerCompoundKey)); + config.AddInterfaceImplementation(typeof(global::TestProject.GrainWithGuidKey)); + config.AddInterfaceImplementation(typeof(global::TestProject.GrainWithStringKey)); + config.AddInterfaceImplementation(typeof(global::TestProject.GrainWithGuidCompoundKey)); + config.AddInterfaceImplementation(typeof(global::TestProject.GrainWithIntegerCompoundKey)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_GrainWithGuidKey)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_GrainWithStringKey)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_GrainWithGuidCompoundKey)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_GrainWithIntegerCompoundKey)); + var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); + var n2 = n1.GetOrAdd(typeof(global::Orleans.Runtime.GrainReference)); + var n3 = n2.GetOrAdd(typeof(global::TestProject.IMyGrainWithGuidKey)); + n3.Add("8F0FEC0E", typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E)); + var n5 = n2.GetOrAdd(typeof(global::TestProject.IMyGrainWithStringKey)); + n5.Add("43570316", typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316)); + var n7 = n2.GetOrAdd(typeof(global::TestProject.IMyGrainWithGuidCompoundKey)); + n7.Add("A9FEF7AF", typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF)); + var n9 = n2.GetOrAdd(typeof(global::TestProject.IMyGrainWithIntegerCompoundKey)); + n9.Add("9814021A", typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A)); + } + } +} +#pragma warning restore \ No newline at end of file diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs new file mode 100644 index 00000000000..b5f05540147 --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs @@ -0,0 +1,1565 @@ +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] +#pragma warning disable +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IMyGrainWithGuidKey), "8F0FEC0E")] + public sealed class Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + { + global::TestProject.IMyGrainWithGuidKey _target; + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IMyGrainWithGuidKey).GetMethod("GetGuidValue", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, global::System.Type.EmptyTypes, null); + public override string GetMethodName() => "GetGuidValue"; + public override string GetInterfaceName() => "TestProject.IMyGrainWithGuidKey"; + public override string GetActivityName() => "IMyGrainWithGuidKey/GetGuidValue"; + public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IMyGrainWithGuidKey); + public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; + public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = (global::TestProject.IMyGrainWithGuidKey)holder.GetTarget(); + public override object GetTarget() => _target; + public override void Dispose() + { + _target = default; + } + + protected override global::System.Threading.Tasks.Task InvokeInner() => _target.GetGuidValue(); + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_5C3A711CFactory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + global::System.Guid value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Proxy_IMyGrainWithGuidKey : global::Orleans.Runtime.GrainReference, global::TestProject.IMyGrainWithGuidKey + { + public Proxy_IMyGrainWithGuidKey(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) + { + } + + global::System.Threading.Tasks.Task global::TestProject.IMyGrainWithGuidKey.GetGuidValue() + { + var request = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E(); + return base.InvokeAsync(request).AsTask(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IMyGrainWithStringKey), "43570316")] + public sealed class Invokable_IMyGrainWithStringKey_GrainReference_43570316 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + { + global::TestProject.IMyGrainWithStringKey _target; + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IMyGrainWithStringKey).GetMethod("GetStringKey", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, global::System.Type.EmptyTypes, null); + public override string GetMethodName() => "GetStringKey"; + public override string GetInterfaceName() => "TestProject.IMyGrainWithStringKey"; + public override string GetActivityName() => "IMyGrainWithStringKey/GetStringKey"; + public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IMyGrainWithStringKey); + public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; + public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = (global::TestProject.IMyGrainWithStringKey)holder.GetTarget(); + public override object GetTarget() => _target; + public override void Dispose() + { + _target = default; + } + + protected override global::System.Threading.Tasks.Task InvokeInner() => _target.GetStringKey(); + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + string value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Proxy_IMyGrainWithStringKey : global::Orleans.Runtime.GrainReference, global::TestProject.IMyGrainWithStringKey + { + public Proxy_IMyGrainWithStringKey(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) + { + } + + global::System.Threading.Tasks.Task global::TestProject.IMyGrainWithStringKey.GetStringKey() + { + var request = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316(); + return base.InvokeAsync(request).AsTask(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IMyGrainWithGuidCompoundKey), "A9FEF7AF")] + public sealed class Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF : global::Orleans.Runtime.TaskRequest>, global::Orleans.Serialization.Invocation.IResponseInvokable + { + global::TestProject.IMyGrainWithGuidCompoundKey _target; + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IMyGrainWithGuidCompoundKey).GetMethod("GetGuidAndStringKey", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, global::System.Type.EmptyTypes, null); + public override string GetMethodName() => "GetGuidAndStringKey"; + public override string GetInterfaceName() => "TestProject.IMyGrainWithGuidCompoundKey"; + public override string GetActivityName() => "IMyGrainWithGuidCompoundKey/GetGuidAndStringKey"; + public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IMyGrainWithGuidCompoundKey); + public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; + public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = (global::TestProject.IMyGrainWithGuidCompoundKey)holder.GetTarget(); + public override object GetTarget() => _target; + public override void Dispose() + { + _target = default; + } + + protected override global::System.Threading.Tasks.Task> InvokeInner() => _target.GetGuidAndStringKey(); + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_6A3EE8F4Factory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + global::System.Tuple value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Proxy_IMyGrainWithGuidCompoundKey : global::Orleans.Runtime.GrainReference, global::TestProject.IMyGrainWithGuidCompoundKey + { + public Proxy_IMyGrainWithGuidCompoundKey(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) + { + } + + global::System.Threading.Tasks.Task> global::TestProject.IMyGrainWithGuidCompoundKey.GetGuidAndStringKey() + { + var request = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF(); + return base.InvokeAsync>(request).AsTask(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IMyGrainWithIntegerCompoundKey), "9814021A")] + public sealed class Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A : global::Orleans.Runtime.TaskRequest>, global::Orleans.Serialization.Invocation.IResponseInvokable + { + global::TestProject.IMyGrainWithIntegerCompoundKey _target; + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IMyGrainWithIntegerCompoundKey).GetMethod("GetIntegerAndStringKey", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, global::System.Type.EmptyTypes, null); + public override string GetMethodName() => "GetIntegerAndStringKey"; + public override string GetInterfaceName() => "TestProject.IMyGrainWithIntegerCompoundKey"; + public override string GetActivityName() => "IMyGrainWithIntegerCompoundKey/GetIntegerAndStringKey"; + public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IMyGrainWithIntegerCompoundKey); + public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; + public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = (global::TestProject.IMyGrainWithIntegerCompoundKey)holder.GetTarget(); + public override object GetTarget() => _target; + public override void Dispose() + { + _target = default; + } + + protected override global::System.Threading.Tasks.Task> InvokeInner() => _target.GetIntegerAndStringKey(); + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_AFB713E4Factory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + global::System.Tuple value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Proxy_IMyGrainWithIntegerCompoundKey : global::Orleans.Runtime.GrainReference, global::TestProject.IMyGrainWithIntegerCompoundKey + { + public Proxy_IMyGrainWithIntegerCompoundKey(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) + { + } + + global::System.Threading.Tasks.Task> global::TestProject.IMyGrainWithIntegerCompoundKey.GetIntegerAndStringKey() + { + var request = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A(); + return base.InvokeAsync>(request).AsTask(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E : global::Orleans.Serialization.Codecs.IFieldCodec + { + private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E instance) + { + reader.ConsumeEndBaseOrEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null) + { + ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + var result = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E(); + ReferenceCodec.MarkValueField(reader.Session); + Deserialize(ref reader, result); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E : global::Orleans.Serialization.Cloning.IDeepCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E DeepCopy(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (original is null) + return null; + var result = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E(); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_GrainWithGuidKey : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GrainWithGuidKey); + private readonly global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer; + public Codec_GrainWithGuidKey(global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer) + { + this._baseTypeSerializer = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeSerializer); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.GrainWithGuidKey instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + _baseTypeSerializer.Serialize(ref writer, instance); + writer.WriteEndBase(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.GrainWithGuidKey instance) + { + _baseTypeSerializer.Deserialize(ref reader, instance); + reader.ConsumeEndBaseOrEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.GrainWithGuidKey @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::TestProject.GrainWithGuidKey)) + { + if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) + return; + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.GrainWithGuidKey ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = new global::TestProject.GrainWithGuidKey(); + ReferenceCodec.RecordObject(reader.Session, result); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_GrainWithGuidKey : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.GrainWithGuidKey DeepCopy(global::TestProject.GrainWithGuidKey original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context.TryGetCopy(original, out global::TestProject.GrainWithGuidKey existing)) + return existing; + if (original.GetType() != typeof(global::TestProject.GrainWithGuidKey)) + return context.DeepCopy(original); + var result = new global::TestProject.GrainWithGuidKey(); + context.RecordCopy(original, result); + DeepCopy(original, result, context); + return result; + } + + public Copier_GrainWithGuidKey(global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier) + { + this._baseTypeCopier = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeCopier); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::TestProject.GrainWithGuidKey input, global::TestProject.GrainWithGuidKey output, global::Orleans.Serialization.Cloning.CopyContext context) + { + _baseTypeCopier.DeepCopy(input, output, context); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Activator_GrainWithGuidKey : global::Orleans.Serialization.Activators.IActivator + { + public global::TestProject.GrainWithGuidKey Create() => new global::TestProject.GrainWithGuidKey(); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_Invokable_IMyGrainWithStringKey_GrainReference_43570316 : global::Orleans.Serialization.Codecs.IFieldCodec + { + private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316 instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316 instance) + { + reader.ConsumeEndBaseOrEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316 @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null) + { + ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + var result = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316(); + ReferenceCodec.MarkValueField(reader.Session); + Deserialize(ref reader, result); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_Invokable_IMyGrainWithStringKey_GrainReference_43570316 : global::Orleans.Serialization.Cloning.IDeepCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316 DeepCopy(OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316 original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (original is null) + return null; + var result = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316(); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_GrainWithStringKey : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GrainWithStringKey); + private readonly global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer; + public Codec_GrainWithStringKey(global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer) + { + this._baseTypeSerializer = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeSerializer); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.GrainWithStringKey instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + _baseTypeSerializer.Serialize(ref writer, instance); + writer.WriteEndBase(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.GrainWithStringKey instance) + { + _baseTypeSerializer.Deserialize(ref reader, instance); + reader.ConsumeEndBaseOrEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.GrainWithStringKey @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::TestProject.GrainWithStringKey)) + { + if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) + return; + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.GrainWithStringKey ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = new global::TestProject.GrainWithStringKey(); + ReferenceCodec.RecordObject(reader.Session, result); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_GrainWithStringKey : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.GrainWithStringKey DeepCopy(global::TestProject.GrainWithStringKey original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context.TryGetCopy(original, out global::TestProject.GrainWithStringKey existing)) + return existing; + if (original.GetType() != typeof(global::TestProject.GrainWithStringKey)) + return context.DeepCopy(original); + var result = new global::TestProject.GrainWithStringKey(); + context.RecordCopy(original, result); + DeepCopy(original, result, context); + return result; + } + + public Copier_GrainWithStringKey(global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier) + { + this._baseTypeCopier = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeCopier); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::TestProject.GrainWithStringKey input, global::TestProject.GrainWithStringKey output, global::Orleans.Serialization.Cloning.CopyContext context) + { + _baseTypeCopier.DeepCopy(input, output, context); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Activator_GrainWithStringKey : global::Orleans.Serialization.Activators.IActivator + { + public global::TestProject.GrainWithStringKey Create() => new global::TestProject.GrainWithStringKey(); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF : global::Orleans.Serialization.Codecs.IFieldCodec + { + private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF instance) + { + reader.ConsumeEndBaseOrEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null) + { + ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + var result = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF(); + ReferenceCodec.MarkValueField(reader.Session); + Deserialize(ref reader, result); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF : global::Orleans.Serialization.Cloning.IDeepCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF DeepCopy(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (original is null) + return null; + var result = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF(); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_GrainWithGuidCompoundKey : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GrainWithGuidCompoundKey); + private readonly global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer; + public Codec_GrainWithGuidCompoundKey(global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer) + { + this._baseTypeSerializer = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeSerializer); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.GrainWithGuidCompoundKey instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + _baseTypeSerializer.Serialize(ref writer, instance); + writer.WriteEndBase(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.GrainWithGuidCompoundKey instance) + { + _baseTypeSerializer.Deserialize(ref reader, instance); + reader.ConsumeEndBaseOrEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.GrainWithGuidCompoundKey @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::TestProject.GrainWithGuidCompoundKey)) + { + if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) + return; + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.GrainWithGuidCompoundKey ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = new global::TestProject.GrainWithGuidCompoundKey(); + ReferenceCodec.RecordObject(reader.Session, result); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_GrainWithGuidCompoundKey : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.GrainWithGuidCompoundKey DeepCopy(global::TestProject.GrainWithGuidCompoundKey original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context.TryGetCopy(original, out global::TestProject.GrainWithGuidCompoundKey existing)) + return existing; + if (original.GetType() != typeof(global::TestProject.GrainWithGuidCompoundKey)) + return context.DeepCopy(original); + var result = new global::TestProject.GrainWithGuidCompoundKey(); + context.RecordCopy(original, result); + DeepCopy(original, result, context); + return result; + } + + public Copier_GrainWithGuidCompoundKey(global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier) + { + this._baseTypeCopier = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeCopier); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::TestProject.GrainWithGuidCompoundKey input, global::TestProject.GrainWithGuidCompoundKey output, global::Orleans.Serialization.Cloning.CopyContext context) + { + _baseTypeCopier.DeepCopy(input, output, context); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Activator_GrainWithGuidCompoundKey : global::Orleans.Serialization.Activators.IActivator + { + public global::TestProject.GrainWithGuidCompoundKey Create() => new global::TestProject.GrainWithGuidCompoundKey(); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A : global::Orleans.Serialization.Codecs.IFieldCodec + { + private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A instance) + { + reader.ConsumeEndBaseOrEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null) + { + ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + var result = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A(); + ReferenceCodec.MarkValueField(reader.Session); + Deserialize(ref reader, result); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A : global::Orleans.Serialization.Cloning.IDeepCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A DeepCopy(OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (original is null) + return null; + var result = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A(); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_GrainWithIntegerCompoundKey : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GrainWithIntegerCompoundKey); + private readonly global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer; + public Codec_GrainWithIntegerCompoundKey(global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer) + { + this._baseTypeSerializer = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeSerializer); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.GrainWithIntegerCompoundKey instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + _baseTypeSerializer.Serialize(ref writer, instance); + writer.WriteEndBase(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.GrainWithIntegerCompoundKey instance) + { + _baseTypeSerializer.Deserialize(ref reader, instance); + reader.ConsumeEndBaseOrEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.GrainWithIntegerCompoundKey @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::TestProject.GrainWithIntegerCompoundKey)) + { + if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) + return; + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.GrainWithIntegerCompoundKey ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = new global::TestProject.GrainWithIntegerCompoundKey(); + ReferenceCodec.RecordObject(reader.Session, result); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_GrainWithIntegerCompoundKey : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.GrainWithIntegerCompoundKey DeepCopy(global::TestProject.GrainWithIntegerCompoundKey original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context.TryGetCopy(original, out global::TestProject.GrainWithIntegerCompoundKey existing)) + return existing; + if (original.GetType() != typeof(global::TestProject.GrainWithIntegerCompoundKey)) + return context.DeepCopy(original); + var result = new global::TestProject.GrainWithIntegerCompoundKey(); + context.RecordCopy(original, result); + DeepCopy(original, result, context); + return result; + } + + public Copier_GrainWithIntegerCompoundKey(global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier) + { + this._baseTypeCopier = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeCopier); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::TestProject.GrainWithIntegerCompoundKey input, global::TestProject.GrainWithIntegerCompoundKey output, global::Orleans.Serialization.Cloning.CopyContext context) + { + _baseTypeCopier.DeepCopy(input, output, context); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Activator_GrainWithIntegerCompoundKey : global::Orleans.Serialization.Activators.IActivator + { + public global::TestProject.GrainWithIntegerCompoundKey Create() => new global::TestProject.GrainWithIntegerCompoundKey(); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class RpcResponseFactories : global::Orleans.Serialization.SerializerContext + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) + { + options.AddDefaultSerializerService(static provider => new RpcResponse_5C3A711CFactory(provider)); + options.AddDefaultSerializer(static provider => RpcResponse_5C3A711CFactory.Resolve(provider), static provider => RpcResponse_5C3A711CFactory.Resolve(provider)); + options.AddRawResponseReader(static provider => RpcResponse_5C3A711CFactory.Resolve(provider)); + options.AddDefaultSerializerService(static provider => new RpcResponse_6A3EE8F4Factory(provider)); + options.AddDefaultSerializer(static provider => RpcResponse_6A3EE8F4Factory.Resolve(provider), static provider => RpcResponse_6A3EE8F4Factory.Resolve(provider)); + options.AddRawResponseReader>(static provider => RpcResponse_6A3EE8F4Factory.Resolve(provider)); + options.AddDefaultSerializerService(static provider => new RpcResponse_AFB713E4Factory(provider)); + options.AddDefaultSerializer(static provider => RpcResponse_AFB713E4Factory.Resolve(provider), static provider => RpcResponse_AFB713E4Factory.Resolve(provider)); + options.AddRawResponseReader>(static provider => RpcResponse_AFB713E4Factory.Resolve(provider)); + options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); + options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); + options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); +#if NET5_0_OR_GREATER + if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) + return; + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response>)); + options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response>)); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.GuidCodec()); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::System.Guid)); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::System.Tuple)); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::System.Tuple)); + options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.Int64Codec()); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(long)); + options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(string)); + options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); + options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); + options.AddDefaultSerializerService(static provider => new CompletedResponseActivator()); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); +#endif + } + + private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator + { + public CompletedResponseActivator() + { + } + + public global::Orleans.Serialization.Invocation.CompletedResponse Create() => global::Orleans.Serialization.Invocation.CompletedResponse.Instance; + } + + private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer + { + public ResponseFieldCodec() + { + } + } + + private sealed class ResponseFieldCopier : global::Orleans.Serialization.Cloning.IDeepCopier + { + public ResponseFieldCopier() + { + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public global::Orleans.Serialization.Invocation.Response DeepCopy(global::Orleans.Serialization.Invocation.Response input, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context is null) + throw new global::System.ArgumentNullException(nameof(context)); + if (input is global::Orleans.Serialization.Invocation.CompletedResponse or global::Orleans.Serialization.Invocation.ExceptionResponse) + return input; + return (global::Orleans.Serialization.Invocation.Response)global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context); + } + } + } + + internal sealed class RpcResponse_5C3A711C : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal global::System.Guid Value; + private RpcResponse_5C3A711CFactory _factory; + public RpcResponse_5C3A711C() + { + } + + internal static RpcResponse_5C3A711C Rent(global::System.Guid value, RpcResponse_5C3A711CFactory factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); + result.Value = value; + result._factory = factory; + return result; + } + + public override object Result { get => Value; set => Value = (global::System.Guid)value; } + + public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } + + public override global::System.Type GetSimpleResultType() => typeof(global::System.Guid); + public override T GetResult() + { + if (typeof(T) == typeof(global::System.Guid)) + return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); + return (T)(object)Value; + } + + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) + throw new global::System.ObjectDisposedException(GetType().Name); + writer.WriteStartObject(0, null, typeof(global::System.Guid)); + global::Orleans.Serialization.Codecs.GuidCodec.WriteField(ref writer, 0, Value); + writer.WriteEndObject(); + } + + public override void Dispose() + { + if (_factory is null) + return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class RpcResponse_5C3A711CFactory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly global::Orleans.Serialization.Codecs.GuidCodec _codec; + private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; + public bool IsSupported { get; } + + internal static RpcResponse_5C3A711CFactory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec(); + provider.GetDeepCopier(); + provider.GetCodec>(); + provider.GetDeepCopier>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + } + + public RpcResponse_5C3A711CFactory(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec() as global::Orleans.Serialization.Codecs.GuidCodec; + _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; + var responseCodec = provider.GetCodec>(); + var responseCopier = provider.GetDeepCopier>(); + IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + } + + internal global::Orleans.Serialization.Invocation.Response RentCopied(global::System.Guid value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + return RpcResponse_5C3A711C.Rent(value, this); + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public RpcResponse_5C3A711C DeepCopy(RpcResponse_5C3A711C input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_5C3A711C.Rent(input.Value, this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, global::System.Guid value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof(global::System.Guid)); + global::Orleans.Serialization.Codecs.GuidCodec.WriteField(ref writer, 0, value); + writer.WriteEndObject(); + } + + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_5C3A711C)value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + private RpcResponse_5C3A711C ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = RpcResponse_5C3A711C.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = global::Orleans.Serialization.Codecs.GuidCodec.ReadValue(ref reader, field); + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + + return result; + } + catch + { + result.Dispose(); + throw; + } + } + + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_5C3A711C value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); + global::Orleans.Serialization.Codecs.GuidCodec.WriteField(ref writer, 0, value.Value); + writer.WriteEndObject(); + } + + public RpcResponse_5C3A711C ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + + internal sealed class RpcResponse_6A3EE8F4 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal global::System.Tuple Value; + private RpcResponse_6A3EE8F4Factory _factory; + public RpcResponse_6A3EE8F4() + { + } + + internal static RpcResponse_6A3EE8F4 Rent(global::System.Tuple value, RpcResponse_6A3EE8F4Factory factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); + result.Value = value; + result._factory = factory; + return result; + } + + public override object Result { get => Value; set => Value = (global::System.Tuple)value; } + + public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } + + public override global::System.Type GetSimpleResultType() => typeof(global::System.Tuple); + public override T GetResult() + { + if (typeof(T) == typeof(global::System.Tuple)) + return global::System.Runtime.CompilerServices.Unsafe.As, T>(ref Value); + return (T)(object)Value; + } + + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) + throw new global::System.ObjectDisposedException(GetType().Name); + _factory.WriteResult(ref writer, Value); + } + + public override void Dispose() + { + if (_factory is null) + return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class RpcResponse_6A3EE8F4Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly global::Orleans.Serialization.Codecs.TupleCodec _codec; + private readonly global::Orleans.Serialization.Codecs.TupleCopier _copier; + public bool IsSupported { get; } + + internal static RpcResponse_6A3EE8F4Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec>(); + provider.GetDeepCopier>(); + provider.GetCodec>>(); + provider.GetDeepCopier>>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + } + + public RpcResponse_6A3EE8F4Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec>() as global::Orleans.Serialization.Codecs.TupleCodec; + _copier = provider.GetDeepCopier>() as global::Orleans.Serialization.Codecs.TupleCopier; + var responseCodec = provider.GetCodec>>(); + var responseCopier = provider.GetDeepCopier>>(); + IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec> || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec>>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Cloning.IDeepCopier>>); + } + + internal global::Orleans.Serialization.Invocation.Response RentCopied(global::System.Tuple value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + return RpcResponse_6A3EE8F4.Rent(value, this); + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public RpcResponse_6A3EE8F4 DeepCopy(RpcResponse_6A3EE8F4 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_6A3EE8F4.Rent(input.Value, this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, global::System.Tuple value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof(global::System.Tuple)); + if (value is not null) + { + _codec.WriteField(ref writer, 0, typeof(global::System.Tuple), value); + } + + writer.WriteEndObject(); + } + + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_6A3EE8F4)value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + private RpcResponse_6A3EE8F4 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = RpcResponse_6A3EE8F4.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = _codec.ReadValue(ref reader, field); + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + + return result; + } + catch + { + result.Dispose(); + throw; + } + } + + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_6A3EE8F4 value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response>)); + if (value.Value is not null) + { + _codec.WriteField(ref writer, 0, typeof(global::System.Tuple), value.Value); + } + + writer.WriteEndObject(); + } + + public RpcResponse_6A3EE8F4 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + + internal sealed class RpcResponse_AFB713E4 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal global::System.Tuple Value; + private RpcResponse_AFB713E4Factory _factory; + public RpcResponse_AFB713E4() + { + } + + internal static RpcResponse_AFB713E4 Rent(global::System.Tuple value, RpcResponse_AFB713E4Factory factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); + result.Value = value; + result._factory = factory; + return result; + } + + public override object Result { get => Value; set => Value = (global::System.Tuple)value; } + + public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } + + public override global::System.Type GetSimpleResultType() => typeof(global::System.Tuple); + public override T GetResult() + { + if (typeof(T) == typeof(global::System.Tuple)) + return global::System.Runtime.CompilerServices.Unsafe.As, T>(ref Value); + return (T)(object)Value; + } + + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) + throw new global::System.ObjectDisposedException(GetType().Name); + _factory.WriteResult(ref writer, Value); + } + + public override void Dispose() + { + if (_factory is null) + return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class RpcResponse_AFB713E4Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly global::Orleans.Serialization.Codecs.TupleCodec _codec; + private readonly global::Orleans.Serialization.Codecs.TupleCopier _copier; + public bool IsSupported { get; } + + internal static RpcResponse_AFB713E4Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec>(); + provider.GetDeepCopier>(); + provider.GetCodec>>(); + provider.GetDeepCopier>>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + } + + public RpcResponse_AFB713E4Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec>() as global::Orleans.Serialization.Codecs.TupleCodec; + _copier = provider.GetDeepCopier>() as global::Orleans.Serialization.Codecs.TupleCopier; + var responseCodec = provider.GetCodec>>(); + var responseCopier = provider.GetDeepCopier>>(); + IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec> || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec>>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Cloning.IDeepCopier>>); + } + + internal global::Orleans.Serialization.Invocation.Response RentCopied(global::System.Tuple value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + return RpcResponse_AFB713E4.Rent(value, this); + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public RpcResponse_AFB713E4 DeepCopy(RpcResponse_AFB713E4 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_AFB713E4.Rent(input.Value, this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, global::System.Tuple value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof(global::System.Tuple)); + if (value is not null) + { + _codec.WriteField(ref writer, 0, typeof(global::System.Tuple), value); + } + + writer.WriteEndObject(); + } + + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_AFB713E4)value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + private RpcResponse_AFB713E4 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = RpcResponse_AFB713E4.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = _codec.ReadValue(ref reader, field); + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + + return result; + } + catch + { + result.Dispose(); + throw; + } + } + + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_AFB713E4 value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response>)); + if (value.Value is not null) + { + _codec.WriteField(ref writer, 0, typeof(global::System.Tuple), value.Value); + } + + writer.WriteEndObject(); + } + + public RpcResponse_AFB713E4 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + + internal sealed class RpcResponse_9146C7E3 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal string Value; + private RpcResponse_9146C7E3Factory _factory; + public RpcResponse_9146C7E3() + { + } + + internal static RpcResponse_9146C7E3 Rent(string value, RpcResponse_9146C7E3Factory factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); + result.Value = value; + result._factory = factory; + return result; + } + + public override object Result { get => Value; set => Value = (string)value; } + + public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } + + public override global::System.Type GetSimpleResultType() => typeof(string); + public override T GetResult() + { + if (typeof(T) == typeof(string)) + return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); + return (T)(object)Value; + } + + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) + throw new global::System.ObjectDisposedException(GetType().Name); + writer.WriteStartObject(0, null, typeof(string)); + if (Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, Value); + } + + writer.WriteEndObject(); + } + + public override void Dispose() + { + if (_factory is null) + return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; + private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; + public bool IsSupported { get; } + + internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec(); + provider.GetDeepCopier(); + provider.GetCodec>(); + provider.GetDeepCopier>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + } + + public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec() as global::Orleans.Serialization.Codecs.StringCodec; + _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; + var responseCodec = provider.GetCodec>(); + var responseCopier = provider.GetDeepCopier>(); + IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + } + + internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + return RpcResponse_9146C7E3.Rent(value, this); + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public RpcResponse_9146C7E3 DeepCopy(RpcResponse_9146C7E3 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_9146C7E3.Rent(input.Value, this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, string value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof(string)); + if (value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value); + } + + writer.WriteEndObject(); + } + + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = RpcResponse_9146C7E3.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, field); + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + + return result; + } + catch + { + result.Dispose(); + throw; + } + } + + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_9146C7E3 value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); + if (value.Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value.Value); + } + + writer.WriteEndObject(); + } + + public RpcResponse_9146C7E3 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_GrainWithGuidKey)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IMyGrainWithStringKey_GrainReference_43570316)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_GrainWithStringKey)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_GrainWithGuidCompoundKey)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_GrainWithIntegerCompoundKey)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithGuidKey)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IMyGrainWithStringKey_GrainReference_43570316)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithStringKey)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithGuidCompoundKey)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithIntegerCompoundKey)); + config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IMyGrainWithGuidKey)); + config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IMyGrainWithStringKey)); + config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IMyGrainWithGuidCompoundKey)); + config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IMyGrainWithIntegerCompoundKey)); + config.AddInterface(typeof(global::TestProject.IMyGrainWithGuidKey)); + config.AddInterface(typeof(global::TestProject.IMyGrainWithStringKey)); + config.AddInterface(typeof(global::TestProject.IMyGrainWithGuidCompoundKey)); + config.AddInterface(typeof(global::TestProject.IMyGrainWithIntegerCompoundKey)); + config.AddInterfaceImplementation(typeof(global::TestProject.GrainWithGuidKey)); + config.AddInterfaceImplementation(typeof(global::TestProject.GrainWithStringKey)); + config.AddInterfaceImplementation(typeof(global::TestProject.GrainWithGuidCompoundKey)); + config.AddInterfaceImplementation(typeof(global::TestProject.GrainWithIntegerCompoundKey)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_GrainWithGuidKey)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_GrainWithStringKey)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_GrainWithGuidCompoundKey)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_GrainWithIntegerCompoundKey)); + var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); + var n2 = n1.GetOrAdd(typeof(global::Orleans.Runtime.GrainReference)); + var n3 = n2.GetOrAdd(typeof(global::TestProject.IMyGrainWithGuidKey)); + n3.Add("8F0FEC0E", typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E)); + var n5 = n2.GetOrAdd(typeof(global::TestProject.IMyGrainWithStringKey)); + n5.Add("43570316", typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316)); + var n7 = n2.GetOrAdd(typeof(global::TestProject.IMyGrainWithGuidCompoundKey)); + n7.Add("A9FEF7AF", typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF)); + var n9 = n2.GetOrAdd(typeof(global::TestProject.IMyGrainWithIntegerCompoundKey)); + n9.Add("9814021A", typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A)); + } + } +} +#pragma warning restore \ No newline at end of file diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.verified.cs index 944b687f9cd..661b675c7f5 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.verified.cs @@ -1,6 +1,4 @@ -// -#nullable disable -[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] #pragma warning disable [assembly: global::Orleans.ApplicationPartAttribute("TestProject")] [assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] @@ -15,10 +13,10 @@ namespace OrleansCodeGen.TestProject [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IMyGrainWithGuidKey), "8F0FEC0E")] - public sealed class Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E : global::Orleans.Runtime.TaskRequest + public sealed class Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable { global::TestProject.IMyGrainWithGuidKey _target; - private static readonly global::System.Reflection.MethodInfo MethodBackingField = OrleansGeneratedCodeHelper.GetMethodInfoOrDefault(typeof(global::TestProject.IMyGrainWithGuidKey), "GetGuidValue", null, null); + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IMyGrainWithGuidKey).GetMethod("GetGuidValue", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, global::System.Type.EmptyTypes, null); public override string GetMethodName() => "GetGuidValue"; public override string GetInterfaceName() => "TestProject.IMyGrainWithGuidKey"; public override string GetActivityName() => "IMyGrainWithGuidKey/GetGuidValue"; @@ -32,6 +30,21 @@ public override void Dispose() } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.GetGuidValue(); + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_5C3A711CFactory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + global::System.Guid value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] @@ -50,10 +63,10 @@ public Proxy_IMyGrainWithGuidKey(global::Orleans.Runtime.GrainReferenceShared ar [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IMyGrainWithStringKey), "43570316")] - public sealed class Invokable_IMyGrainWithStringKey_GrainReference_43570316 : global::Orleans.Runtime.TaskRequest + public sealed class Invokable_IMyGrainWithStringKey_GrainReference_43570316 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable { global::TestProject.IMyGrainWithStringKey _target; - private static readonly global::System.Reflection.MethodInfo MethodBackingField = OrleansGeneratedCodeHelper.GetMethodInfoOrDefault(typeof(global::TestProject.IMyGrainWithStringKey), "GetStringKey", null, null); + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IMyGrainWithStringKey).GetMethod("GetStringKey", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, global::System.Type.EmptyTypes, null); public override string GetMethodName() => "GetStringKey"; public override string GetInterfaceName() => "TestProject.IMyGrainWithStringKey"; public override string GetActivityName() => "IMyGrainWithStringKey/GetStringKey"; @@ -67,6 +80,21 @@ public override void Dispose() } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.GetStringKey(); + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + string value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] @@ -85,10 +113,10 @@ public Proxy_IMyGrainWithStringKey(global::Orleans.Runtime.GrainReferenceShared [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IMyGrainWithGuidCompoundKey), "A9FEF7AF")] - public sealed class Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF : global::Orleans.Runtime.TaskRequest> + public sealed class Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF : global::Orleans.Runtime.TaskRequest>, global::Orleans.Serialization.Invocation.IResponseInvokable { global::TestProject.IMyGrainWithGuidCompoundKey _target; - private static readonly global::System.Reflection.MethodInfo MethodBackingField = OrleansGeneratedCodeHelper.GetMethodInfoOrDefault(typeof(global::TestProject.IMyGrainWithGuidCompoundKey), "GetGuidAndStringKey", null, null); + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IMyGrainWithGuidCompoundKey).GetMethod("GetGuidAndStringKey", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, global::System.Type.EmptyTypes, null); public override string GetMethodName() => "GetGuidAndStringKey"; public override string GetInterfaceName() => "TestProject.IMyGrainWithGuidCompoundKey"; public override string GetActivityName() => "IMyGrainWithGuidCompoundKey/GetGuidAndStringKey"; @@ -102,6 +130,21 @@ public override void Dispose() } protected override global::System.Threading.Tasks.Task> InvokeInner() => _target.GetGuidAndStringKey(); + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_6A3EE8F4Factory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + global::System.Tuple value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] @@ -120,10 +163,10 @@ public Proxy_IMyGrainWithGuidCompoundKey(global::Orleans.Runtime.GrainReferenceS [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IMyGrainWithIntegerCompoundKey), "9814021A")] - public sealed class Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A : global::Orleans.Runtime.TaskRequest> + public sealed class Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A : global::Orleans.Runtime.TaskRequest>, global::Orleans.Serialization.Invocation.IResponseInvokable { global::TestProject.IMyGrainWithIntegerCompoundKey _target; - private static readonly global::System.Reflection.MethodInfo MethodBackingField = OrleansGeneratedCodeHelper.GetMethodInfoOrDefault(typeof(global::TestProject.IMyGrainWithIntegerCompoundKey), "GetIntegerAndStringKey", null, null); + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IMyGrainWithIntegerCompoundKey).GetMethod("GetIntegerAndStringKey", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, global::System.Type.EmptyTypes, null); public override string GetMethodName() => "GetIntegerAndStringKey"; public override string GetInterfaceName() => "TestProject.IMyGrainWithIntegerCompoundKey"; public override string GetActivityName() => "IMyGrainWithIntegerCompoundKey/GetIntegerAndStringKey"; @@ -137,6 +180,21 @@ public override void Dispose() } protected override global::System.Threading.Tasks.Task> InvokeInner() => _target.GetIntegerAndStringKey(); + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_AFB713E4Factory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + global::System.Tuple value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] @@ -154,6 +212,7 @@ public Proxy_IMyGrainWithIntegerCompoundKey(global::Orleans.Runtime.GrainReferen } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E); @@ -199,6 +258,7 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8 } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -212,6 +272,7 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8 } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_GrainWithGuidKey : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GrainWithGuidKey); @@ -272,6 +333,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_GrainWithGuidKey : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; @@ -307,6 +369,7 @@ internal sealed class Activator_GrainWithGuidKey : global::Orleans.Serialization } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IMyGrainWithStringKey_GrainReference_43570316 : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316); @@ -352,6 +415,7 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IMyGrainWithStringKey_GrainReference_43570316 : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -365,6 +429,7 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_GrainWithStringKey : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GrainWithStringKey); @@ -425,6 +490,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_GrainWithStringKey : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; @@ -460,6 +526,7 @@ internal sealed class Activator_GrainWithStringKey : global::Orleans.Serializati } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF); @@ -505,6 +572,7 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainRef } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -518,6 +586,7 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainRef } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_GrainWithGuidCompoundKey : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GrainWithGuidCompoundKey); @@ -578,6 +647,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_GrainWithGuidCompoundKey : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; @@ -613,6 +683,7 @@ internal sealed class Activator_GrainWithGuidCompoundKey : global::Orleans.Seria } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A); @@ -658,6 +729,7 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_Grain } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -671,6 +743,7 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_Grain } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_GrainWithIntegerCompoundKey : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GrainWithIntegerCompoundKey); @@ -731,6 +804,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_GrainWithIntegerCompoundKey : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; @@ -770,6 +844,18 @@ internal sealed class RpcResponseFactories : global::Orleans.Serialization.Seria { protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) { + options.AddDefaultSerializerService(static provider => new RpcResponse_5C3A711CFactory(provider)); + options.AddDefaultSerializer(static provider => RpcResponse_5C3A711CFactory.Resolve(provider), static provider => RpcResponse_5C3A711CFactory.Resolve(provider)); + options.AddRawResponseReader(static provider => RpcResponse_5C3A711CFactory.Resolve(provider)); + options.AddDefaultSerializerService(static provider => new RpcResponse_6A3EE8F4Factory(provider)); + options.AddDefaultSerializer(static provider => RpcResponse_6A3EE8F4Factory.Resolve(provider), static provider => RpcResponse_6A3EE8F4Factory.Resolve(provider)); + options.AddRawResponseReader>(static provider => RpcResponse_6A3EE8F4Factory.Resolve(provider)); + options.AddDefaultSerializerService(static provider => new RpcResponse_AFB713E4Factory(provider)); + options.AddDefaultSerializer(static provider => RpcResponse_AFB713E4Factory.Resolve(provider), static provider => RpcResponse_AFB713E4Factory.Resolve(provider)); + options.AddRawResponseReader>(static provider => RpcResponse_AFB713E4Factory.Resolve(provider)); + options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); + options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); + options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); #if NET5_0_OR_GREATER if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) return; @@ -854,6 +940,574 @@ public ResponseFieldCopier() } } + internal sealed class RpcResponse_5C3A711C : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal global::System.Guid Value; + private RpcResponse_5C3A711CFactory _factory; + public RpcResponse_5C3A711C() + { + } + + internal static RpcResponse_5C3A711C Rent(global::System.Guid value, RpcResponse_5C3A711CFactory factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); + result.Value = value; + result._factory = factory; + return result; + } + + public override object Result { get => Value; set => Value = (global::System.Guid)value; } + public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } + + public override global::System.Type GetSimpleResultType() => typeof(global::System.Guid); + public override T GetResult() + { + if (typeof(T) == typeof(global::System.Guid)) + return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); + return (T)(object)Value; + } + + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) + throw new global::System.ObjectDisposedException(GetType().Name); + writer.WriteStartObject(0, null, typeof(global::System.Guid)); + global::Orleans.Serialization.Codecs.GuidCodec.WriteField(ref writer, 0, Value); + writer.WriteEndObject(); + } + + public override void Dispose() + { + if (_factory is null) + return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class RpcResponse_5C3A711CFactory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly global::Orleans.Serialization.Codecs.GuidCodec _codec; + private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; + public bool IsSupported { get; } + + internal static RpcResponse_5C3A711CFactory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec(); + provider.GetDeepCopier(); + provider.GetCodec>(); + provider.GetDeepCopier>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + } + + public RpcResponse_5C3A711CFactory(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec() as global::Orleans.Serialization.Codecs.GuidCodec; + _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; + var responseCodec = provider.GetCodec>(); + var responseCopier = provider.GetDeepCopier>(); + IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + } + + internal global::Orleans.Serialization.Invocation.Response RentCopied(global::System.Guid value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + return RpcResponse_5C3A711C.Rent(value, this); + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public RpcResponse_5C3A711C DeepCopy(RpcResponse_5C3A711C input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_5C3A711C.Rent(input.Value, this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, global::System.Guid value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof(global::System.Guid)); + global::Orleans.Serialization.Codecs.GuidCodec.WriteField(ref writer, 0, value); + writer.WriteEndObject(); + } + + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_5C3A711C)value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + private RpcResponse_5C3A711C ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = RpcResponse_5C3A711C.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = global::Orleans.Serialization.Codecs.GuidCodec.ReadValue(ref reader, field); + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + + return result; + } + catch + { + result.Dispose(); + throw; + } + } + + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_5C3A711C value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); + global::Orleans.Serialization.Codecs.GuidCodec.WriteField(ref writer, 0, value.Value); + writer.WriteEndObject(); + } + + public RpcResponse_5C3A711C ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + + internal sealed class RpcResponse_6A3EE8F4 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal global::System.Tuple Value; + private RpcResponse_6A3EE8F4Factory _factory; + public RpcResponse_6A3EE8F4() + { + } + + internal static RpcResponse_6A3EE8F4 Rent(global::System.Tuple value, RpcResponse_6A3EE8F4Factory factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); + result.Value = value; + result._factory = factory; + return result; + } + + public override object Result { get => Value; set => Value = (global::System.Tuple)value; } + public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } + + public override global::System.Type GetSimpleResultType() => typeof(global::System.Tuple); + public override T GetResult() + { + if (typeof(T) == typeof(global::System.Tuple)) + return global::System.Runtime.CompilerServices.Unsafe.As, T>(ref Value); + return (T)(object)Value; + } + + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) + throw new global::System.ObjectDisposedException(GetType().Name); + _factory.WriteResult(ref writer, Value); + } + + public override void Dispose() + { + if (_factory is null) + return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class RpcResponse_6A3EE8F4Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly global::Orleans.Serialization.Codecs.TupleCodec _codec; + private readonly global::Orleans.Serialization.Codecs.TupleCopier _copier; + public bool IsSupported { get; } + + internal static RpcResponse_6A3EE8F4Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec>(); + provider.GetDeepCopier>(); + provider.GetCodec>>(); + provider.GetDeepCopier>>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + } + + public RpcResponse_6A3EE8F4Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec>() as global::Orleans.Serialization.Codecs.TupleCodec; + _copier = provider.GetDeepCopier>() as global::Orleans.Serialization.Codecs.TupleCopier; + var responseCodec = provider.GetCodec>>(); + var responseCopier = provider.GetDeepCopier>>(); + IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec> || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec>>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Cloning.IDeepCopier>>); + } + + internal global::Orleans.Serialization.Invocation.Response RentCopied(global::System.Tuple value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + return RpcResponse_6A3EE8F4.Rent(value, this); + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public RpcResponse_6A3EE8F4 DeepCopy(RpcResponse_6A3EE8F4 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_6A3EE8F4.Rent(input.Value, this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, global::System.Tuple value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof(global::System.Tuple)); + if (value is not null) + { + _codec.WriteField(ref writer, 0, typeof(global::System.Tuple), value); + } + + writer.WriteEndObject(); + } + + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_6A3EE8F4)value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + private RpcResponse_6A3EE8F4 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = RpcResponse_6A3EE8F4.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = _codec.ReadValue(ref reader, field); + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + + return result; + } + catch + { + result.Dispose(); + throw; + } + } + + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_6A3EE8F4 value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response>)); + if (value.Value is not null) + { + _codec.WriteField(ref writer, 0, typeof(global::System.Tuple), value.Value); + } + + writer.WriteEndObject(); + } + + public RpcResponse_6A3EE8F4 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + + internal sealed class RpcResponse_AFB713E4 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal global::System.Tuple Value; + private RpcResponse_AFB713E4Factory _factory; + public RpcResponse_AFB713E4() + { + } + + internal static RpcResponse_AFB713E4 Rent(global::System.Tuple value, RpcResponse_AFB713E4Factory factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); + result.Value = value; + result._factory = factory; + return result; + } + + public override object Result { get => Value; set => Value = (global::System.Tuple)value; } + public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } + + public override global::System.Type GetSimpleResultType() => typeof(global::System.Tuple); + public override T GetResult() + { + if (typeof(T) == typeof(global::System.Tuple)) + return global::System.Runtime.CompilerServices.Unsafe.As, T>(ref Value); + return (T)(object)Value; + } + + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) + throw new global::System.ObjectDisposedException(GetType().Name); + _factory.WriteResult(ref writer, Value); + } + + public override void Dispose() + { + if (_factory is null) + return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class RpcResponse_AFB713E4Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly global::Orleans.Serialization.Codecs.TupleCodec _codec; + private readonly global::Orleans.Serialization.Codecs.TupleCopier _copier; + public bool IsSupported { get; } + + internal static RpcResponse_AFB713E4Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec>(); + provider.GetDeepCopier>(); + provider.GetCodec>>(); + provider.GetDeepCopier>>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + } + + public RpcResponse_AFB713E4Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec>() as global::Orleans.Serialization.Codecs.TupleCodec; + _copier = provider.GetDeepCopier>() as global::Orleans.Serialization.Codecs.TupleCopier; + var responseCodec = provider.GetCodec>>(); + var responseCopier = provider.GetDeepCopier>>(); + IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec> || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec>>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Cloning.IDeepCopier>>); + } + + internal global::Orleans.Serialization.Invocation.Response RentCopied(global::System.Tuple value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + return RpcResponse_AFB713E4.Rent(value, this); + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public RpcResponse_AFB713E4 DeepCopy(RpcResponse_AFB713E4 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_AFB713E4.Rent(input.Value, this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, global::System.Tuple value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof(global::System.Tuple)); + if (value is not null) + { + _codec.WriteField(ref writer, 0, typeof(global::System.Tuple), value); + } + + writer.WriteEndObject(); + } + + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_AFB713E4)value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + private RpcResponse_AFB713E4 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = RpcResponse_AFB713E4.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = _codec.ReadValue(ref reader, field); + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + + return result; + } + catch + { + result.Dispose(); + throw; + } + } + + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_AFB713E4 value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response>)); + if (value.Value is not null) + { + _codec.WriteField(ref writer, 0, typeof(global::System.Tuple), value.Value); + } + + writer.WriteEndObject(); + } + + public RpcResponse_AFB713E4 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + + internal sealed class RpcResponse_9146C7E3 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal string Value; + private RpcResponse_9146C7E3Factory _factory; + public RpcResponse_9146C7E3() + { + } + + internal static RpcResponse_9146C7E3 Rent(string value, RpcResponse_9146C7E3Factory factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); + result.Value = value; + result._factory = factory; + return result; + } + + public override object Result { get => Value; set => Value = (string)value; } + public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } + + public override global::System.Type GetSimpleResultType() => typeof(string); + public override T GetResult() + { + if (typeof(T) == typeof(string)) + return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); + return (T)(object)Value; + } + + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) + throw new global::System.ObjectDisposedException(GetType().Name); + writer.WriteStartObject(0, null, typeof(string)); + if (Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, Value); + } + + writer.WriteEndObject(); + } + + public override void Dispose() + { + if (_factory is null) + return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; + private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; + public bool IsSupported { get; } + + internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec(); + provider.GetDeepCopier(); + provider.GetCodec>(); + provider.GetDeepCopier>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + } + + public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec() as global::Orleans.Serialization.Codecs.StringCodec; + _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; + var responseCodec = provider.GetCodec>(); + var responseCopier = provider.GetDeepCopier>(); + IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + } + + internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + return RpcResponse_9146C7E3.Rent(value, this); + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public RpcResponse_9146C7E3 DeepCopy(RpcResponse_9146C7E3 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_9146C7E3.Rent(input.Value, this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, string value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof(string)); + if (value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value); + } + + writer.WriteEndObject(); + } + + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = RpcResponse_9146C7E3.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, field); + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + + return result; + } + catch + { + result.Dispose(); + throw; + } + } + + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_9146C7E3 value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); + if (value.Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value.Value); + } + + writer.WriteEndObject(); + } + + public RpcResponse_9146C7E3 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase { diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs new file mode 100644 index 00000000000..c601281d9ee --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs @@ -0,0 +1,561 @@ +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] +#pragma warning disable +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IGrainA), "11405B98")] + public sealed class Invokable_IGrainA_GrainReference_11405B98 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + { + public string arg0; + global::TestProject.IGrainA _target; + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IGrainA).GetMethod("MethodA", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new[] { typeof(string) }, null); + public override int GetArgumentCount() => 1; + public override string GetMethodName() => "MethodA"; + public override string GetInterfaceName() => "TestProject.IGrainA"; + public override string GetActivityName() => "IGrainA/MethodA"; + public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IGrainA); + public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; + public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = (global::TestProject.IGrainA)holder.GetTarget(); + public override object GetTarget() => _target; + public override void Dispose() + { + arg0 = default; + _target = default; + } + + public override object GetArgument(int index) + { + switch (index) + { + case 0: + return arg0; + default: + return OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + } + } + + public override void SetArgument(int index, object value) + { + switch (index) + { + case 0: + arg0 = (string)value; + return; + default: + OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + return; + } + } + + protected override global::System.Threading.Tasks.Task InvokeInner() => _target.MethodA(arg0); + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + string value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Proxy_IGrainA : global::Orleans.Runtime.GrainReference, global::TestProject.IGrainA + { + public Proxy_IGrainA(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) + { + } + + global::System.Threading.Tasks.Task global::TestProject.IGrainA.MethodA(string arg0) + { + var request = new OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98(); + request.arg0 = arg0; + return base.InvokeAsync(request).AsTask(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IGrainB), "6B5D7809")] + public sealed class Invokable_IGrainB_GrainReference_6B5D7809 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + { + public string arg0; + global::TestProject.IGrainB _target; + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IGrainB).GetMethod("MethodB", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new[] { typeof(string) }, null); + public override int GetArgumentCount() => 1; + public override string GetMethodName() => "MethodB"; + public override string GetInterfaceName() => "TestProject.IGrainB"; + public override string GetActivityName() => "IGrainB/MethodB"; + public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IGrainB); + public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; + public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = (global::TestProject.IGrainB)holder.GetTarget(); + public override object GetTarget() => _target; + public override void Dispose() + { + arg0 = default; + _target = default; + } + + public override object GetArgument(int index) + { + switch (index) + { + case 0: + return arg0; + default: + return OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + } + } + + public override void SetArgument(int index, object value) + { + switch (index) + { + case 0: + arg0 = (string)value; + return; + default: + OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + return; + } + } + + protected override global::System.Threading.Tasks.Task InvokeInner() => _target.MethodB(arg0); + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + string value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Proxy_IGrainB : global::Orleans.Runtime.GrainReference, global::TestProject.IGrainB + { + public Proxy_IGrainB(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) + { + } + + global::System.Threading.Tasks.Task global::TestProject.IGrainB.MethodB(string arg0) + { + var request = new OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809(); + request.arg0 = arg0; + return base.InvokeAsync(request).AsTask(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_Invokable_IGrainA_GrainReference_11405B98 : global::Orleans.Serialization.Codecs.IFieldCodec + { + private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.arg0); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + instance.arg0 = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null) + { + ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + var result = new OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98(); + ReferenceCodec.MarkValueField(reader.Session); + Deserialize(ref reader, result); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_Invokable_IGrainA_GrainReference_11405B98 : global::Orleans.Serialization.Cloning.IDeepCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 DeepCopy(OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (original is null) + return null; + var result = new OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98(); + result.arg0 = original.arg0; + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_Invokable_IGrainB_GrainReference_6B5D7809 : global::Orleans.Serialization.Codecs.IFieldCodec + { + private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809 instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.arg0); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809 instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + instance.arg0 = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809 @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null) + { + ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + var result = new OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809(); + ReferenceCodec.MarkValueField(reader.Session); + Deserialize(ref reader, result); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_Invokable_IGrainB_GrainReference_6B5D7809 : global::Orleans.Serialization.Cloning.IDeepCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809 DeepCopy(OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809 original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (original is null) + return null; + var result = new OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809(); + result.arg0 = original.arg0; + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class RpcResponseFactories : global::Orleans.Serialization.SerializerContext + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) + { + options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); + options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); + options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); +#if NET5_0_OR_GREATER + if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) + return; + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(string)); + options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); + options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); + options.AddDefaultSerializerService(static provider => new CompletedResponseActivator()); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); +#endif + } + + private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator + { + public CompletedResponseActivator() + { + } + + public global::Orleans.Serialization.Invocation.CompletedResponse Create() => global::Orleans.Serialization.Invocation.CompletedResponse.Instance; + } + + private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer + { + public ResponseFieldCodec() + { + } + } + + private sealed class ResponseFieldCopier : global::Orleans.Serialization.Cloning.IDeepCopier + { + public ResponseFieldCopier() + { + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public global::Orleans.Serialization.Invocation.Response DeepCopy(global::Orleans.Serialization.Invocation.Response input, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context is null) + throw new global::System.ArgumentNullException(nameof(context)); + if (input is global::Orleans.Serialization.Invocation.CompletedResponse or global::Orleans.Serialization.Invocation.ExceptionResponse) + return input; + return (global::Orleans.Serialization.Invocation.Response)global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context); + } + } + } + + internal sealed class RpcResponse_9146C7E3 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal string Value; + private RpcResponse_9146C7E3Factory _factory; + public RpcResponse_9146C7E3() + { + } + + internal static RpcResponse_9146C7E3 Rent(string value, RpcResponse_9146C7E3Factory factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); + result.Value = value; + result._factory = factory; + return result; + } + + public override object Result { get => Value; set => Value = (string)value; } + public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } + + public override global::System.Type GetSimpleResultType() => typeof(string); + public override T GetResult() + { + if (typeof(T) == typeof(string)) + return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); + return (T)(object)Value; + } + + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) + throw new global::System.ObjectDisposedException(GetType().Name); + writer.WriteStartObject(0, null, typeof(string)); + if (Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, Value); + } + + writer.WriteEndObject(); + } + + public override void Dispose() + { + if (_factory is null) + return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; + private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; + public bool IsSupported { get; } + + internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec(); + provider.GetDeepCopier(); + provider.GetCodec>(); + provider.GetDeepCopier>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + } + + public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec() as global::Orleans.Serialization.Codecs.StringCodec; + _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; + var responseCodec = provider.GetCodec>(); + var responseCopier = provider.GetDeepCopier>(); + IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + } + + internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + return RpcResponse_9146C7E3.Rent(value, this); + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public RpcResponse_9146C7E3 DeepCopy(RpcResponse_9146C7E3 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_9146C7E3.Rent(input.Value, this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, string value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof(string)); + if (value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value); + } + + writer.WriteEndObject(); + } + + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = RpcResponse_9146C7E3.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, field); + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + + return result; + } + catch + { + result.Dispose(); + throw; + } + } + + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_9146C7E3 value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); + if (value.Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value.Value); + } + + writer.WriteEndObject(); + } + + public RpcResponse_9146C7E3 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IGrainA_GrainReference_11405B98)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IGrainB_GrainReference_6B5D7809)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IGrainA_GrainReference_11405B98)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IGrainB_GrainReference_6B5D7809)); + config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IGrainA)); + config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IGrainB)); + config.AddInterface(typeof(global::TestProject.IGrainA)); + config.AddInterface(typeof(global::TestProject.IGrainB)); + config.AddInterfaceImplementation(typeof(global::TestProject.RealGrain)); + var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); + var n2 = n1.GetOrAdd(typeof(global::Orleans.Runtime.GrainReference)); + var n3 = n2.GetOrAdd(typeof(global::TestProject.IGrainA)); + n3.Add("11405B98", typeof(OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98)); + var n5 = n2.GetOrAdd(typeof(global::TestProject.IGrainB)); + n5.Add("6B5D7809", typeof(OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809)); + } + } +} +#pragma warning restore \ No newline at end of file diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs new file mode 100644 index 00000000000..91ce58e8d1c --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs @@ -0,0 +1,562 @@ +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] +#pragma warning disable +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IGrainA), "11405B98")] + public sealed class Invokable_IGrainA_GrainReference_11405B98 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + { + public string arg0; + global::TestProject.IGrainA _target; + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IGrainA).GetMethod("MethodA", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new[] { typeof(string) }, null); + public override int GetArgumentCount() => 1; + public override string GetMethodName() => "MethodA"; + public override string GetInterfaceName() => "TestProject.IGrainA"; + public override string GetActivityName() => "IGrainA/MethodA"; + public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IGrainA); + public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; + public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = (global::TestProject.IGrainA)holder.GetTarget(); + public override object GetTarget() => _target; + public override void Dispose() + { + arg0 = default; + _target = default; + } + + public override object GetArgument(int index) + { + switch (index) + { + case 0: + return arg0; + default: + return OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + } + } + + public override void SetArgument(int index, object value) + { + switch (index) + { + case 0: + arg0 = (string)value; + return; + default: + OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + return; + } + } + + protected override global::System.Threading.Tasks.Task InvokeInner() => _target.MethodA(arg0); + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + string value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Proxy_IGrainA : global::Orleans.Runtime.GrainReference, global::TestProject.IGrainA + { + public Proxy_IGrainA(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) + { + } + + global::System.Threading.Tasks.Task global::TestProject.IGrainA.MethodA(string arg0) + { + var request = new OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98(); + request.arg0 = arg0; + return base.InvokeAsync(request).AsTask(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IGrainB), "6B5D7809")] + public sealed class Invokable_IGrainB_GrainReference_6B5D7809 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + { + public string arg0; + global::TestProject.IGrainB _target; + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IGrainB).GetMethod("MethodB", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new[] { typeof(string) }, null); + public override int GetArgumentCount() => 1; + public override string GetMethodName() => "MethodB"; + public override string GetInterfaceName() => "TestProject.IGrainB"; + public override string GetActivityName() => "IGrainB/MethodB"; + public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IGrainB); + public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; + public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = (global::TestProject.IGrainB)holder.GetTarget(); + public override object GetTarget() => _target; + public override void Dispose() + { + arg0 = default; + _target = default; + } + + public override object GetArgument(int index) + { + switch (index) + { + case 0: + return arg0; + default: + return OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + } + } + + public override void SetArgument(int index, object value) + { + switch (index) + { + case 0: + arg0 = (string)value; + return; + default: + OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + return; + } + } + + protected override global::System.Threading.Tasks.Task InvokeInner() => _target.MethodB(arg0); + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + string value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Proxy_IGrainB : global::Orleans.Runtime.GrainReference, global::TestProject.IGrainB + { + public Proxy_IGrainB(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) + { + } + + global::System.Threading.Tasks.Task global::TestProject.IGrainB.MethodB(string arg0) + { + var request = new OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809(); + request.arg0 = arg0; + return base.InvokeAsync(request).AsTask(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_Invokable_IGrainA_GrainReference_11405B98 : global::Orleans.Serialization.Codecs.IFieldCodec + { + private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.arg0); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + instance.arg0 = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null) + { + ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + var result = new OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98(); + ReferenceCodec.MarkValueField(reader.Session); + Deserialize(ref reader, result); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_Invokable_IGrainA_GrainReference_11405B98 : global::Orleans.Serialization.Cloning.IDeepCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 DeepCopy(OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (original is null) + return null; + var result = new OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98(); + result.arg0 = original.arg0; + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Codec_Invokable_IGrainB_GrainReference_6B5D7809 : global::Orleans.Serialization.Codecs.IFieldCodec + { + private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809 instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.arg0); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809 instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + instance.arg0 = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809 @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null) + { + ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + var result = new OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809(); + ReferenceCodec.MarkValueField(reader.Session); + Deserialize(ref reader, result); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] + public sealed class Copier_Invokable_IGrainB_GrainReference_6B5D7809 : global::Orleans.Serialization.Cloning.IDeepCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809 DeepCopy(OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809 original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (original is null) + return null; + var result = new OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809(); + result.arg0 = original.arg0; + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class RpcResponseFactories : global::Orleans.Serialization.SerializerContext + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) + { + options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); + options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); + options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); +#if NET5_0_OR_GREATER + if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) + return; + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(string)); + options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); + options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); + options.AddDefaultSerializerService(static provider => new CompletedResponseActivator()); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); +#endif + } + + private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator + { + public CompletedResponseActivator() + { + } + + public global::Orleans.Serialization.Invocation.CompletedResponse Create() => global::Orleans.Serialization.Invocation.CompletedResponse.Instance; + } + + private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer + { + public ResponseFieldCodec() + { + } + } + + private sealed class ResponseFieldCopier : global::Orleans.Serialization.Cloning.IDeepCopier + { + public ResponseFieldCopier() + { + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public global::Orleans.Serialization.Invocation.Response DeepCopy(global::Orleans.Serialization.Invocation.Response input, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context is null) + throw new global::System.ArgumentNullException(nameof(context)); + if (input is global::Orleans.Serialization.Invocation.CompletedResponse or global::Orleans.Serialization.Invocation.ExceptionResponse) + return input; + return (global::Orleans.Serialization.Invocation.Response)global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context); + } + } + } + + internal sealed class RpcResponse_9146C7E3 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal string Value; + private RpcResponse_9146C7E3Factory _factory; + public RpcResponse_9146C7E3() + { + } + + internal static RpcResponse_9146C7E3 Rent(string value, RpcResponse_9146C7E3Factory factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); + result.Value = value; + result._factory = factory; + return result; + } + + public override object Result { get => Value; set => Value = (string)value; } + + public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } + + public override global::System.Type GetSimpleResultType() => typeof(string); + public override T GetResult() + { + if (typeof(T) == typeof(string)) + return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); + return (T)(object)Value; + } + + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) + throw new global::System.ObjectDisposedException(GetType().Name); + writer.WriteStartObject(0, null, typeof(string)); + if (Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, Value); + } + + writer.WriteEndObject(); + } + + public override void Dispose() + { + if (_factory is null) + return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; + private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; + public bool IsSupported { get; } + + internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec(); + provider.GetDeepCopier(); + provider.GetCodec>(); + provider.GetDeepCopier>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + } + + public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec() as global::Orleans.Serialization.Codecs.StringCodec; + _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; + var responseCodec = provider.GetCodec>(); + var responseCopier = provider.GetDeepCopier>(); + IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + } + + internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + return RpcResponse_9146C7E3.Rent(value, this); + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public RpcResponse_9146C7E3 DeepCopy(RpcResponse_9146C7E3 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_9146C7E3.Rent(input.Value, this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, string value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof(string)); + if (value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value); + } + + writer.WriteEndObject(); + } + + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = RpcResponse_9146C7E3.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, field); + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + + return result; + } + catch + { + result.Dispose(); + throw; + } + } + + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_9146C7E3 value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); + if (value.Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value.Value); + } + + writer.WriteEndObject(); + } + + public RpcResponse_9146C7E3 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IGrainA_GrainReference_11405B98)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IGrainB_GrainReference_6B5D7809)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IGrainA_GrainReference_11405B98)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IGrainB_GrainReference_6B5D7809)); + config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IGrainA)); + config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IGrainB)); + config.AddInterface(typeof(global::TestProject.IGrainA)); + config.AddInterface(typeof(global::TestProject.IGrainB)); + config.AddInterfaceImplementation(typeof(global::TestProject.RealGrain)); + var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); + var n2 = n1.GetOrAdd(typeof(global::Orleans.Runtime.GrainReference)); + var n3 = n2.GetOrAdd(typeof(global::TestProject.IGrainA)); + n3.Add("11405B98", typeof(OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98)); + var n5 = n2.GetOrAdd(typeof(global::TestProject.IGrainB)); + n5.Add("6B5D7809", typeof(OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809)); + } + } +} +#pragma warning restore \ No newline at end of file diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.verified.cs index c2bdee693fa..67c7eb78509 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.verified.cs @@ -1,6 +1,4 @@ -// -#nullable disable -[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] #pragma warning disable [assembly: global::Orleans.ApplicationPartAttribute("TestProject")] [assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] @@ -15,11 +13,11 @@ namespace OrleansCodeGen.TestProject [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IGrainA), "11405B98")] - public sealed class Invokable_IGrainA_GrainReference_11405B98 : global::Orleans.Runtime.TaskRequest + public sealed class Invokable_IGrainA_GrainReference_11405B98 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable { public string arg0; global::TestProject.IGrainA _target; - private static readonly global::System.Reflection.MethodInfo MethodBackingField = OrleansGeneratedCodeHelper.GetMethodInfoOrDefault(typeof(global::TestProject.IGrainA), "MethodA", null, new[] { typeof(string) }); + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IGrainA).GetMethod("MethodA", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new[] { typeof(string) }, null); public override int GetArgumentCount() => 1; public override string GetMethodName() => "MethodA"; public override string GetInterfaceName() => "TestProject.IGrainA"; @@ -59,6 +57,21 @@ public override void SetArgument(int index, object value) } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.MethodA(arg0); + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + string value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] @@ -78,11 +91,11 @@ public Proxy_IGrainA(global::Orleans.Runtime.GrainReferenceShared arg0, global:: [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IGrainB), "6B5D7809")] - public sealed class Invokable_IGrainB_GrainReference_6B5D7809 : global::Orleans.Runtime.TaskRequest + public sealed class Invokable_IGrainB_GrainReference_6B5D7809 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable { public string arg0; global::TestProject.IGrainB _target; - private static readonly global::System.Reflection.MethodInfo MethodBackingField = OrleansGeneratedCodeHelper.GetMethodInfoOrDefault(typeof(global::TestProject.IGrainB), "MethodB", null, new[] { typeof(string) }); + private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IGrainB).GetMethod("MethodB", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new[] { typeof(string) }, null); public override int GetArgumentCount() => 1; public override string GetMethodName() => "MethodB"; public override string GetInterfaceName() => "TestProject.IGrainB"; @@ -122,6 +135,21 @@ public override void SetArgument(int index, object value) } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.MethodB(arg0); + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + { + try + { + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + if (!factory.IsSupported) + return responseCopier.Copy(await Invoke()); + string value = await InvokeInner(); + return factory.RentCopied(value, contexts); + } + catch (global::System.Exception exception) + { + return global::Orleans.Serialization.Invocation.Response.FromException(exception); + } + } } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] @@ -140,6 +168,7 @@ public Proxy_IGrainB(global::Orleans.Runtime.GrainReferenceShared arg0, global:: } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IGrainA_GrainReference_11405B98 : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98); @@ -202,6 +231,7 @@ public OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 Read } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IGrainA_GrainReference_11405B98 : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -216,6 +246,7 @@ public OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 Deep } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IGrainB_GrainReference_6B5D7809 : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809); @@ -278,6 +309,7 @@ public OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809 Read } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IGrainB_GrainReference_6B5D7809 : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -296,6 +328,9 @@ internal sealed class RpcResponseFactories : global::Orleans.Serialization.Seria { protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) { + options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); + options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); + options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); #if NET5_0_OR_GREATER if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) return; @@ -352,6 +387,154 @@ public ResponseFieldCopier() } } + internal sealed class RpcResponse_9146C7E3 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter + { + internal string Value; + private RpcResponse_9146C7E3Factory _factory; + public RpcResponse_9146C7E3() + { + } + + internal static RpcResponse_9146C7E3 Rent(string value, RpcResponse_9146C7E3Factory factory) + { + var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); + result.Value = value; + result._factory = factory; + return result; + } + + public override object Result { get => Value; set => Value = (string)value; } + public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } + + public override global::System.Type GetSimpleResultType() => typeof(string); + public override T GetResult() + { + if (typeof(T) == typeof(string)) + return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); + return (T)(object)Value; + } + + public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (_factory is null) + throw new global::System.ObjectDisposedException(GetType().Name); + writer.WriteStartObject(0, null, typeof(string)); + if (Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, Value); + } + + writer.WriteEndObject(); + } + + public override void Dispose() + { + if (_factory is null) + return; + Value = default; + _factory = null; + global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); + } + } + + internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + { + private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; + private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; + public bool IsSupported { get; } + + internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + provider.GetCodec(); + provider.GetDeepCopier(); + provider.GetCodec>(); + provider.GetDeepCopier>(); + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); + } + + public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) + { + _codec = provider.GetCodec() as global::Orleans.Serialization.Codecs.StringCodec; + _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; + var responseCodec = provider.GetCodec>(); + var responseCopier = provider.GetDeepCopier>(); + IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + } + + internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + return RpcResponse_9146C7E3.Rent(value, this); + } + + [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] + public RpcResponse_9146C7E3 DeepCopy(RpcResponse_9146C7E3 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_9146C7E3.Rent(input.Value, this); + internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, string value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + writer.WriteStartObject(0, null, typeof(string)); + if (value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value); + } + + writer.WriteEndObject(); + } + + public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); + public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); + private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) + { + field.EnsureWireTypeTagDelimited(); + var result = RpcResponse_9146C7E3.Rent(default, this); + try + { + reader.ReadFieldHeader(ref field); + if (!field.IsEndBaseOrEndObject) + { + result.Value = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, field); + reader.ReadFieldHeader(ref field); + reader.ConsumeEndBaseOrEndObject(ref field); + } + + return result; + } + catch + { + result.Dispose(); + throw; + } + } + + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_9146C7E3 value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (value is null) + { + global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); + if (value.Value is not null) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value.Value); + } + + writer.WriteEndObject(); + } + + public RpcResponse_9146C7E3 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); + global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); + return ReadResult(ref reader, ref field); + } + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase { diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestRecords.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestRecords.verified.cs index 24924825d88..1332f74b94f 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestRecords.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestRecords.verified.cs @@ -11,6 +11,7 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_DemoDataRecordStruct : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IValueSerializer { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DemoDataRecordStruct); @@ -73,6 +74,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_DemoDataRecordClass : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DemoDataRecordClass); @@ -157,6 +159,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_DemoDataRecordClass : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Activators.IActivator _activator; @@ -188,6 +191,7 @@ public void DeepCopy(global::TestProject.DemoDataRecordClass input, global::Test } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_DemoDataRecord : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DemoDataRecord); @@ -272,6 +276,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_DemoDataRecord : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Activators.IActivator _activator; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestRecordsWithParameterIdAttributes.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestRecordsWithParameterIdAttributes.verified.cs index 99103ab1742..8da887d8ee4 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestRecordsWithParameterIdAttributes.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestRecordsWithParameterIdAttributes.verified.cs @@ -11,6 +11,7 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_SimpleRecord : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.SimpleRecord); @@ -109,6 +110,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_SimpleRecord : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Activators.IActivator _activator; @@ -143,6 +145,7 @@ public void DeepCopy(global::TestProject.SimpleRecord input, global::TestProject } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_RecordWithExtraProperty : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.RecordWithExtraProperty); @@ -257,6 +260,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_RecordWithExtraProperty : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Activators.IActivator _activator; @@ -294,6 +298,7 @@ public void DeepCopy(global::TestProject.RecordWithExtraProperty input, global:: } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_RecordStructWithParameterId : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IValueSerializer { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.RecordStructWithParameterId); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithOmitDefaultMemberValuesAnnotation.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithOmitDefaultMemberValuesAnnotation.verified.cs index 98cad6db203..5acee83695c 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithOmitDefaultMemberValuesAnnotation.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithOmitDefaultMemberValuesAnnotation.verified.cs @@ -11,6 +11,7 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_DemoClass : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DemoClass); @@ -84,6 +85,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_DemoClass : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithSuppressReferenceTrackingAttribute.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithSuppressReferenceTrackingAttribute.verified.cs index 319f7322c72..3afe0ce1cac 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithSuppressReferenceTrackingAttribute.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithSuppressReferenceTrackingAttribute.verified.cs @@ -11,6 +11,7 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_DemoClass : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DemoClass); @@ -84,6 +85,7 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_DemoClass : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] diff --git a/test/Orleans.Core.Tests/Serialization/SelfWritingResponseFilterTests.cs b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseFilterTests.cs new file mode 100644 index 00000000000..99ba36f6f56 --- /dev/null +++ b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseFilterTests.cs @@ -0,0 +1,302 @@ +using System.Diagnostics.CodeAnalysis; +using System.Reflection; +using Microsoft.Extensions.DependencyInjection; +using NSubstitute; +using Orleans; +using Orleans.Runtime; +using Orleans.Serialization; +using Orleans.Serialization.Cloning; +using Orleans.Serialization.Invocation; +using Orleans.Serialization.Serializers; +using Xunit; + +namespace UnitTests.Serialization; + +[TestSuite("BVT")] +[TestProvider("None")] +[TestArea("Serialization")] +[TestCategory("BVT"), TestCategory("Serialization")] +public sealed class SelfWritingResponseFilterTests +{ + [Fact] + public async Task Invoke_DirectResponse_IsCopiedBeforeIncomingFilterResumesWithoutLegacyCopy() + { + using var services = CreateServices(); + var payload = new List { 17, 23, 41 }; + var request = new DirectInvocation(payload); + var legacyCopier = new CountingResponseCopier(); + var codecProvider = services.GetRequiredService(); + var copyContexts = services.GetRequiredService(); + var responseCopier = new DeepCopier(legacyCopier, copyContexts); + var filterCalls = 0; + var filter = new CallbackFilter(async context => + { + filterCalls++; + await context.Invoke(); + + var result = Assert.IsType>(context.Result); + Assert.NotSame(payload, result); + Assert.Equal(new[] { 17, 23, 41 }, result); + Assert.Equal(1, request.CopyCalls); + Assert.Equal(0, legacyCopier.CopyCalls); + + // Mutating grain-owned state here proves isolation precedes filter continuation. + payload[0] = 99; + payload.Add(73); + Assert.Equal(new[] { 17, 23, 41 }, result); + Assert.Same(result, context.Result); + }); + var invoker = CreateInvoker(request, payload, filter, responseCopier, codecProvider, copyContexts); + + await invoker.Invoke(); + + Assert.Equal(1, filterCalls); + Assert.Equal(1, request.DirectCalls); + Assert.Equal(1, request.CopyCalls); + Assert.Equal(0, request.InvokeCalls); + Assert.Equal(0, legacyCopier.CopyCalls); + Assert.Same(codecProvider, request.CodecProvider); + Assert.Same(copyContexts, request.CopyContexts); + Assert.Same(responseCopier, request.ResponseCopier); + Assert.Same(request.ReturnedResponse, invoker.Response); + Assert.Equal(new[] { 17, 23, 41 }, Assert.IsType>(invoker.Result)); + Assert.Equal(new[] { 99, 23, 41, 73 }, payload); + } + + [Fact] + public async Task Invoke_LegacyResponse_IsTransformedExactlyOnceBeforeIncomingFilterResumes() + { + using var services = CreateServices(); + var payload = new List { 17, 23, 41 }; + using var originalResponse = new PayloadResponse(payload); + var request = new LegacyInvocation(originalResponse, payload); + var legacyCopier = new CountingResponseCopier(input => + { + Assert.Same(originalResponse, input); + return new PayloadResponse(Assert.IsType>(input.Result).Select(value => value + 100).ToList()); + }); + var copyContexts = services.GetRequiredService(); + var filterCalls = 0; + var filter = new CallbackFilter(async context => + { + filterCalls++; + await context.Invoke(); + + Assert.Equal(1, request.InvokeCalls); + Assert.Equal(1, legacyCopier.CopyCalls); + var result = Assert.IsType>(context.Result); + Assert.NotSame(payload, result); + Assert.Equal(new[] { 117, 123, 141 }, result); + payload[1] = -23; + payload.Clear(); + Assert.Equal(new[] { 117, 123, 141 }, result); + }); + var invoker = CreateInvoker( + request, payload, filter, new DeepCopier(legacyCopier, copyContexts), + services.GetRequiredService(), copyContexts); + + await invoker.Invoke(); + + Assert.Equal(1, filterCalls); + Assert.Equal(1, request.InvokeCalls); + Assert.Equal(1, legacyCopier.CopyCalls); + Assert.Same(originalResponse, legacyCopier.LastInput); + Assert.NotSame(originalResponse, invoker.Response); + Assert.Equal(new[] { 117, 123, 141 }, Assert.IsType>(invoker.Result)); + Assert.Empty(payload); + } + + [Fact] + public async Task Invoke_DirectExceptionResponse_PropagatesOriginalExceptionThroughIncomingFilter() + { + using var services = CreateServices(); + var payload = new List { 17, 23, 41 }; + var failure = new InvalidOperationException("grain invocation failed"); + var request = new DirectInvocation(payload, failure); + var legacyCopier = new CountingResponseCopier(); + var copyContexts = services.GetRequiredService(); + var filterCalls = 0; + var filter = new CallbackFilter(async context => + { + filterCalls++; + var caught = await Assert.ThrowsAsync(context.Invoke); + Assert.Same(failure, caught); + Assert.Same(failure, Assert.IsType(context.Response).Exception); + Assert.Null(context.Result); + throw caught; + }); + var invoker = CreateInvoker( + request, payload, filter, new DeepCopier(legacyCopier, copyContexts), + services.GetRequiredService(), copyContexts); + + var thrown = await Assert.ThrowsAsync(invoker.Invoke); + + Assert.Same(failure, thrown); + Assert.Equal("grain invocation failed", thrown.Message); + Assert.Same(request.ReturnedResponse, invoker.Response); + Assert.Same(failure, Assert.IsType(invoker.Response).Exception); + Assert.Null(invoker.Result); + Assert.Equal(1, filterCalls); + Assert.Equal(1, request.DirectCalls); + Assert.Equal(0, request.CopyCalls); + Assert.Equal(0, request.InvokeCalls); + Assert.Equal(0, legacyCopier.CopyCalls); + Assert.Equal(new[] { 17, 23, 41 }, payload); + } + + [Fact] + public async Task Invoke_FilterSuppliesResponse_DoesNotInvokeOrCopyRequest() + { + using var services = CreateServices(); + var payload = new List { 17, 23, 41 }; + var request = new DirectInvocation(payload); + using var suppliedResponse = new PayloadResponse(new List { 5, 8, 13 }); + var legacyCopier = new CountingResponseCopier(); + var copyContexts = services.GetRequiredService(); + var filterCalls = 0; + var filter = new CallbackFilter(context => + { + filterCalls++; + context.Response = suppliedResponse; + return Task.CompletedTask; + }); + var invoker = CreateInvoker( + request, payload, filter, new DeepCopier(legacyCopier, copyContexts), + services.GetRequiredService(), copyContexts); + + await invoker.Invoke(); + + Assert.Same(suppliedResponse, invoker.Response); + Assert.Equal(new[] { 5, 8, 13 }, Assert.IsType>(invoker.Result)); + Assert.Equal(1, filterCalls); + Assert.Equal(0, request.DirectCalls); + Assert.Equal(0, request.CopyCalls); + Assert.Equal(0, request.InvokeCalls); + Assert.Equal(0, legacyCopier.CopyCalls); + Assert.Null(request.ReturnedResponse); + Assert.Equal(new[] { 17, 23, 41 }, payload); + } + + private static ServiceProvider CreateServices() + { + var services = new ServiceCollection(); + services.AddSerializer(); + return services.BuildServiceProvider(); + } + + private static GrainMethodInvoker CreateInvoker( + IInvokable request, + object grain, + IIncomingGrainCallFilter filter, + DeepCopier responseCopier, + ICodecProvider codecProvider, + CopyContextPool copyContexts) + { + var grainContext = Substitute.For(); + grainContext.GrainInstance.Returns(grain); + grainContext.GrainId.Returns(GrainId.Create("filter-test", "target")); + var message = new Message + { + Direction = Message.Directions.Request, + BodyObject = request, + SendingGrain = GrainId.Create("filter-test", "sender"), + TargetGrain = grainContext.GrainId + }; + return new GrainMethodInvoker( + message, grainContext, request, [filter], new InterfaceToImplementationMappingCache(), + responseCopier, codecProvider, copyContexts); + } + + private sealed class CallbackFilter(Func callback) : IIncomingGrainCallFilter + { + public Task Invoke(IIncomingGrainCallContext context) => callback(context); + } + + private class LegacyInvocation(Response response, object target) : IInvokable + { + public int InvokeCalls { get; protected set; } + + public virtual ValueTask Invoke() + { + InvokeCalls++; + return ValueTask.FromResult(response); + } + + public object GetTarget() => target; + public void SetTarget(ITargetHolder holder) => throw new NotSupportedException(); + public int GetArgumentCount() => 0; + public object? GetArgument(int index) => throw new ArgumentOutOfRangeException(nameof(index)); + public void SetArgument(int index, object value) => throw new ArgumentOutOfRangeException(nameof(index)); + public string GetMethodName() => nameof(ToString); + public string GetInterfaceName() => nameof(IInvokable); + public string GetActivityName() => $"{GetInterfaceName()}.{GetMethodName()}"; + public MethodInfo GetMethod() => typeof(object).GetMethod(nameof(ToString), Type.EmptyTypes)!; + public Type GetInterfaceType() => typeof(IInvokable); + public void Dispose() { } + } + + private sealed class DirectInvocation(List payload, Exception? failure = null) + : LegacyInvocation(new PayloadResponse(payload), payload), IResponseInvokable + { + public int DirectCalls { get; private set; } + public int CopyCalls { get; private set; } + public ICodecProvider? CodecProvider { get; private set; } + public CopyContextPool? CopyContexts { get; private set; } + public DeepCopier? ResponseCopier { get; private set; } + public Response? ReturnedResponse { get; private set; } + + public override ValueTask Invoke() + { + InvokeCalls++; + throw new InvalidOperationException("Direct invocations must not use the legacy Invoke path."); + } + + public ValueTask InvokeAndCopy( + ICodecProvider codecProvider, CopyContextPool copyContextPool, DeepCopier responseCopier) + { + DirectCalls++; + CodecProvider = codecProvider; + CopyContexts = copyContextPool; + ResponseCopier = responseCopier; + if (failure is not null) + { + ReturnedResponse = Response.FromException(failure); + } + else + { + CopyCalls++; + ReturnedResponse = new PayloadResponse(new List(payload)); + } + + return ValueTask.FromResult(ReturnedResponse); + } + } + + // These fakes intentionally have no serialization or grain-interface generation attributes. + private sealed class PayloadResponse(List payload) : Response + { + public override object? Result { get; set; } = payload; + public override Exception? Exception { get => null; set => throw new NotSupportedException(); } + public override T GetResult() => (T)Result!; + public override void Dispose() { } + } + + private sealed class CountingResponseCopier(Func? transform = null) : IDeepCopier + { + public int CopyCalls { get; private set; } + public Response? LastInput { get; private set; } + + [return: NotNullIfNotNull(nameof(input))] + public Response? DeepCopy(Response? input, CopyContext context) + { + CopyCalls++; + LastInput = input; + if (transform is null) + { + throw new InvalidOperationException("The direct response path must not invoke the legacy response copier."); + } + + return input is null ? null : transform(input); + } + } +} diff --git a/test/Orleans.Core.Tests/Serialization/SelfWritingResponseMessageTests.cs b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseMessageTests.cs new file mode 100644 index 00000000000..60f2fe6e1db --- /dev/null +++ b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseMessageTests.cs @@ -0,0 +1,476 @@ +using System.Buffers; +using System.Buffers.Binary; +using System.Collections.Generic; +using System.IO.Pipelines; +using System.Net; +using Microsoft.Extensions.DependencyInjection; +using Orleans.Networking.Shared; +using Orleans.Configuration; +using Orleans.Runtime; +using Orleans.Runtime.Messaging; +using Orleans.Serialization; +using Orleans.Serialization.Buffers; +using Orleans.Serialization.Cloning; +using Orleans.Serialization.Codecs; +using Orleans.Serialization.Configuration; +using Orleans.Serialization.Invocation; +using Orleans.Serialization.Serializers; +using Orleans.Serialization.Session; +using Orleans.Serialization.WireProtocol; +using Xunit; + +namespace UnitTests.Serialization; + +[TestSuite("BVT")] +[TestProvider("None")] +[TestArea("Serialization")] +[TestCategory("BVT"), TestCategory("Serialization")] +public sealed class SelfWritingResponseMessageTests +{ + [Theory] + [InlineData(false)] + [InlineData(true)] + public void Write_BooleanHolderWithoutCodec_MatchesLegacyFrameAndRoundTrips(bool value) + => AssertCompatibleFrame(new BooleanResponse(value), value, new BoolCodec()); + + [Theory] + [InlineData(0)] + [InlineData(-1)] + [InlineData(42)] + [InlineData(127)] + [InlineData(128)] + [InlineData(int.MinValue)] + [InlineData(int.MaxValue)] + public void Write_Int32HolderWithoutCodec_MatchesLegacyFrameAndRoundTrips(int value) + => AssertCompatibleFrame(new Int32Response(value), value, new Int32Codec()); + + [Theory] + [InlineData(null)] + [InlineData("")] + [InlineData("shared reference payload \u03bb")] + public void Write_StringHolderWithoutCodec_MatchesLegacyFrameAndRoundTrips(string? value) + => AssertCompatibleFrame(new StringResponse(value), value!, new StringCodec()); + + [Fact] + public void Write_UnregisteredHolder_InvokesRawWriterWithoutRuntimeCodecLookup() + { + // Arrange: querying the holder codec really does fail, independently of message serialization. + using var environment = new SerializationEnvironment(); + var holder = new Int32Response(314159); + var message = CreateMessage(holder); + Assert.Throws(() => environment.CodecProvider.GetCodec(holder.GetType())); + + // Act + var frame = WriteFrame(environment.Serializer, message); + + // Assert + Assert.Equal(1, holder.WriteCount); + AssertFrame(frame, message, typeof(int)); + var received = ReadFrame(environment.Serializer, frame); + using var response = Assert.IsAssignableFrom(received.BodyObject); + Assert.Equal(314159, response.GetResult()); + AssertHeaders(message, received); + } + + [Fact] + public void Read_RegisteredReader_IsCachedBeforeLegacyResponseCodecLookup() + { + // Arrange: any legacy Response codec resolution is a failing sentinel. + var reader = new CountingRawReader(new Int32Codec()); + var counts = new LookupCounts(); + using var sender = new SerializationEnvironment(); + using var receiver = new SerializationEnvironment(options => RegisterReader(options, reader, counts)); + using var firstResponse = Response.FromResult(42); + using var secondResponse = Response.FromResult(-17); + var firstMessage = CreateMessage(firstResponse); + var secondMessage = CreateMessage(secondResponse); + var firstFrame = WriteFrame(sender.Serializer, firstMessage); + var secondFrame = WriteFrame(sender.Serializer, secondMessage); + + // Act: legacy-produced frames are accepted using the statically registered reader. + var first = ReadFrame(receiver.Serializer, firstFrame); + var second = ReadFrame(receiver.Serializer, secondFrame); + + // Assert + using var firstResult = Assert.IsType>(first.BodyObject); + using var secondResult = Assert.IsType>(second.BodyObject); + Assert.Equal(42, firstResult.TypedResult); + Assert.Equal(-17, secondResult.TypedResult); + Assert.Equal(1, counts.ReaderFactoryCalls); + Assert.Equal(2, reader.ReadCount); + Assert.Equal(0, counts.LegacyCodecLookups); + AssertHeaders(firstMessage, first); + AssertHeaders(secondMessage, second); + } + + [Theory] + [InlineData((int)Message.ResponseTypes.Success)] + [InlineData((int)Message.ResponseTypes.Error)] + [InlineData((int)Message.ResponseTypes.Rejection)] + [InlineData((int)Message.ResponseTypes.Status)] + public void Write_NonNoneResponseType_DoesNotInvokeRawWriter(int responseTypeValue) + { + // Arrange + using var environment = new SerializationEnvironment(); + var responseType = (Message.ResponseTypes)responseTypeValue; + var holder = new Int32Response(42); + var message = CreateMessage(holder); + message.Result = responseType; + var pipe = new Pipe(new PipeOptions(pauseWriterThreshold: 0)); + + try + { + // Act + Assert.Throws(() => environment.Serializer.Write(pipe.Writer, message)); + + // Assert + Assert.Equal(0, holder.WriteCount); + Assert.Equal(responseType, message.Result); + } + finally + { + pipe.Writer.Complete(); + pipe.Reader.Complete(); + } + } + + [Fact] + public void Write_OversizedRawBody_EnforcesLimitAndSerializerCanBeReused() + { + // Arrange + using var environment = new SerializationEnvironment( + messagingOptions: new SiloMessagingOptions { MaxMessageBodySize = 32 }); + var oversized = new StringResponse(new string('x', 128)); + var pipe = new Pipe(new PipeOptions(pauseWriterThreshold: 0)); + + try + { + // Act + var exception = Assert.Throws( + () => environment.Serializer.Write(pipe.Writer, CreateMessage(oversized))); + + // Assert + Assert.Contains("Invalid body size:", exception.Message); + Assert.Contains(nameof(MessagingOptions.MaxMessageBodySize), exception.Message); + Assert.Equal(1, oversized.WriteCount); + } + finally + { + pipe.Writer.Complete(); + pipe.Reader.Complete(); + } + + AssertSuccessfulReuse(environment); + } + + [Fact] + public void Write_RawWriterThrows_PropagatesExceptionAndSerializerCanBeReused() + { + // Arrange + using var environment = new SerializationEnvironment(); + var holder = new ThrowingResponse(); + var pipe = new Pipe(new PipeOptions(pauseWriterThreshold: 0)); + + try + { + // Act + var exception = Assert.Throws( + () => environment.Serializer.Write(pipe.Writer, CreateMessage(holder))); + + // Assert + Assert.Same(holder.Failure, exception); + Assert.Equal(1, holder.WriteCount); + } + finally + { + pipe.Writer.Complete(); + pipe.Reader.Complete(); + } + + AssertSuccessfulReuse(environment); + } + + private static void AssertCompatibleFrame(TestResponse holder, TResult value, TCodec codec) + where TCodec : class, IFieldCodec + { + // Arrange: isolated providers, no holder codec, and a poisoned legacy reader fallback. + var rawReader = new CountingRawReader(codec); + var counts = new LookupCounts(); + using var sender = new SerializationEnvironment(); + using var receiver = new SerializationEnvironment(options => RegisterReader(options, rawReader, counts)); + using var legacyResponse = Response.FromResult(value); + var message = CreateMessage(holder); + if (value is string referenceValue) + { + // The body also appears in the header, exercising the header/body partial session reset. + message.RequestContextData!["payload"] = referenceValue; + } + + Assert.Throws(() => sender.CodecProvider.GetCodec(holder.GetType())); + + // Act: use the same stable headers, explicitly resetting the raw response flag for each write. + message.Result = Message.ResponseTypes.None; + var directFrame = WriteFrame(sender.Serializer, message); + message.BodyObject = legacyResponse; + message.Result = Message.ResponseTypes.None; + var legacyFrame = WriteFrame(sender.Serializer, message); + var received = ReadFrame(receiver.Serializer, directFrame); + + // Assert: compare the entire frame, not just the serialized payload. + Assert.Equal(legacyFrame.HeaderLength, directFrame.HeaderLength); + Assert.Equal(legacyFrame.BodyLength, directFrame.BodyLength); + Assert.Equal(legacyFrame.Bytes, directFrame.Bytes); + Assert.Equal(1, holder.WriteCount); + AssertFrame(directFrame, message, typeof(TResult)); + using var response = Assert.IsType>(received.BodyObject); + Assert.Equal(value, response.TypedResult); + Assert.Null(response.Exception); + Assert.Equal(1, counts.ReaderFactoryCalls); + Assert.Equal(1, rawReader.ReadCount); + Assert.Equal(0, counts.LegacyCodecLookups); + AssertHeaders(message, received); + } + + private static void RegisterReader( + TypeManifestOptions options, CountingRawReader reader, LookupCounts counts) + where TCodec : class, IFieldCodec + { + options.AddRawResponseReader(_ => + { + counts.ReaderFactoryCalls++; + return reader; + }); + options.AddSerializer>(_ => + { + counts.LegacyCodecLookups++; + throw new InvalidOperationException("The registered raw reader must precede legacy Response codec lookup."); + }, _ => new ShallowCopier>()); + } + + private static Message CreateMessage(Response body) + { + var shared = new byte[] { 3, 1, 4 }; + return new Message + { + BodyObject = body, + Direction = Message.Directions.Response, + Result = Message.ResponseTypes.None, + Id = new CorrelationId(123456), + SendingGrain = GrainId.Create("sender", "fixed"), + TargetGrain = GrainId.Create("target", "fixed"), + SendingSilo = SiloAddress.New(new IPEndPoint(IPAddress.Loopback, 11111), 7), + TargetSilo = SiloAddress.New(new IPEndPoint(IPAddress.Loopback, 22222), 9), + IsReadOnly = true, + IsAlwaysInterleave = true, + InterfaceVersion = 2, + ForwardCount = 1, + RequestContextData = new Dictionary + { + ["first"] = shared, + ["second"] = shared, + ["number"] = 73 + } + }; + } + + private static (byte[] Bytes, int HeaderLength, int BodyLength) WriteFrame(MessageSerializer serializer, Message message) + { + var pipe = new Pipe(new PipeOptions(pauseWriterThreshold: 0)); + try + { + var (headerLength, bodyLength) = serializer.Write(pipe.Writer, message); + pipe.Writer.FlushAsync().GetAwaiter().GetResult(); + Assert.True(pipe.Reader.TryRead(out var result)); + var bytes = result.Buffer.ToArray(); + pipe.Reader.AdvanceTo(result.Buffer.End); + return (bytes, headerLength, bodyLength); + } + finally + { + pipe.Writer.Complete(); + pipe.Reader.Complete(); + } + } + + private static Message ReadFrame(MessageSerializer serializer, (byte[] Bytes, int HeaderLength, int BodyLength) frame) + { + var input = new ReadOnlySequence(frame.Bytes); + var (requiredBytes, headerLength, bodyLength) = serializer.TryRead(ref input, out var message); + Assert.Equal(0, requiredBytes); + Assert.Equal(frame.HeaderLength, headerLength); + Assert.Equal(frame.BodyLength, bodyLength); + Assert.True(input.IsEmpty); + return Assert.IsType(message); + } + + private static void AssertFrame( + (byte[] Bytes, int HeaderLength, int BodyLength) frame, Message message, Type resultType) + { + Assert.Equal(frame.HeaderLength, BinaryPrimitives.ReadInt32LittleEndian(frame.Bytes)); + Assert.Equal(frame.BodyLength, BinaryPrimitives.ReadInt32LittleEndian(frame.Bytes.AsSpan(4))); + Assert.Equal(Message.LENGTH_HEADER_SIZE + frame.HeaderLength + frame.BodyLength, frame.Bytes.Length); + Assert.True(frame.BodyLength > 0); + var expectedHeaders = message.Headers; + expectedHeaders.ResponseType = Message.ResponseTypes.Success; + Assert.Equal((uint)expectedHeaders, BinaryPrimitives.ReadUInt32LittleEndian(frame.Bytes.AsSpan(Message.LENGTH_HEADER_SIZE))); + + using var environment = new SerializationEnvironment(); + using var session = environment.Services.GetRequiredService().GetSession(); + var reader = Reader.Create(frame.Bytes.AsSpan(Message.LENGTH_HEADER_SIZE + frame.HeaderLength), session); + var field = reader.ReadFieldHeader(); + Assert.Equal(resultType, field.FieldType); + Assert.Equal(WireType.TagDelimited, field.WireType); + } + + private static void AssertHeaders(Message source, Message received) + { + // The transport-only Success flag must not escape into the reconstructed message. + var expected = source.Headers; + expected.ResponseType = Message.ResponseTypes.None; + Assert.Equal((uint)expected, (uint)received.Headers); + Assert.Equal(source.Id, received.Id); + Assert.Equal(source.SendingGrain, received.SendingGrain); + Assert.Equal(source.TargetGrain, received.TargetGrain); + Assert.Equal(source.SendingSilo, received.SendingSilo); + Assert.Equal(source.TargetSilo, received.TargetSilo); + Assert.Equal(source.InterfaceVersion, received.InterfaceVersion); + var context = Assert.IsType>(received.RequestContextData); + Assert.Equal(source.RequestContextData!.Count, context.Count); + Assert.Equal(new byte[] { 3, 1, 4 }, Assert.IsType(context["first"])); + Assert.Same(context["first"], context["second"]); + Assert.Equal(73, Assert.IsType(context["number"])); + if (source.RequestContextData.TryGetValue("payload", out var payload)) + { + Assert.Equal(payload, context["payload"]); + } + } + + private static void AssertSuccessfulReuse(SerializationEnvironment environment) + { + var holder = new Int32Response(42); + var message = CreateMessage(holder); + var frame = WriteFrame(environment.Serializer, message); + var received = ReadFrame(environment.Serializer, frame); + using var response = Assert.IsAssignableFrom(received.BodyObject); + Assert.Equal(42, response.GetResult()); + Assert.Equal(1, holder.WriteCount); + AssertHeaders(message, received); + } + + private sealed class SerializationEnvironment : IDisposable + { + private readonly SharedMemoryPool _memoryPool = new(); + + public SerializationEnvironment(Action? configure = null, MessagingOptions? messagingOptions = null) + { + var services = new ServiceCollection(); + // Raw reader registration is first-wins: install the test reader before assembly manifests. + if (configure is not null) services.Configure(configure); + services.AddSerializer(builder => + { + // Include both header codec dependencies, without starting a client or silo. + builder.AddAssembly(typeof(MessageSerializer).Assembly); + builder.AddAssembly(typeof(GrainAddressCacheUpdate).Assembly); + }); + Services = services.BuildServiceProvider(); + CodecProvider = Services.GetRequiredService(); + Serializer = new MessageSerializer( + Services.GetRequiredService(), _memoryPool, messagingOptions ?? new SiloMessagingOptions()); + } + + public ServiceProvider Services { get; } + public CodecProvider CodecProvider { get; } + public MessageSerializer Serializer { get; } + + public void Dispose() + { + Serializer.Dispose(); + Services.Dispose(); + _memoryPool.Pool.Dispose(); + } + } + + private sealed class LookupCounts + { + public int ReaderFactoryCalls; + public int LegacyCodecLookups; + } + + private sealed class CountingRawReader(TCodec codec) : IRawResponseReader + where TCodec : class, IFieldCodec + { + private readonly PooledResponseCodec _codec = new(codec); + public int ReadCount { get; private set; } + public bool IsSupported => true; + + public Response ReadRaw(ref Reader reader, scoped ref Field field) + { + ReadCount++; + Assert.Equal(typeof(TResult), field.FieldType); + return (Response)_codec.ReadRaw(ref reader, ref field); + } + } + + // Deliberately concrete, non-generic holders with no GenerateSerializer or registered field codec. + private abstract class TestResponse : Response, IRawResponseWriter + { + public int WriteCount { get; protected set; } + public override object? Result { get; set; } + public override Exception? Exception { get => null; set => throw new NotSupportedException(); } + public override T GetResult() => (T)Result!; + public override void Dispose() { } + public abstract void WriteRaw(ref Writer writer) where TBufferWriter : IBufferWriter; + } + + private sealed class BooleanResponse : TestResponse + { + public BooleanResponse(bool value) => Result = value; + + public override void WriteRaw(ref Writer writer) + { + WriteCount++; + writer.WriteStartObject(0, null!, typeof(bool)); + BoolCodec.WriteField(ref writer, 0, (bool)Result!); + writer.WriteEndObject(); + } + } + + private sealed class Int32Response : TestResponse + { + public Int32Response(int value) => Result = value; + + public override void WriteRaw(ref Writer writer) + { + WriteCount++; + writer.WriteStartObject(0, null!, typeof(int)); + Int32Codec.WriteField(ref writer, 0, (int)Result!); + writer.WriteEndObject(); + } + } + + private sealed class StringResponse : TestResponse + { + public StringResponse(string? value) => Result = value; + + public override void WriteRaw(ref Writer writer) + { + WriteCount++; + writer.WriteStartObject(0, null!, typeof(string)); + if (Result is string value) StringCodec.WriteField(ref writer, 0, value); + writer.WriteEndObject(); + } + } + + private sealed class ThrowingResponse : TestResponse + { + public InvalidOperationException Failure { get; } = new("Raw writer failure"); + + public override void WriteRaw(ref Writer writer) + { + WriteCount++; + writer.WriteStartObject(0, null!, typeof(int)); + Int32Codec.WriteField(ref writer, 0, 99); + throw Failure; + } + } +} diff --git a/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs b/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs index 2f339d91618..54bda4d6890 100644 --- a/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs +++ b/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs @@ -14,6 +14,69 @@ namespace Orleans.NativeAotSmoke; public static class RpcResponseContracts { + public static async System.Threading.Tasks.Task GeneratedInvokablesWriteCopiedResponses() + { +#if NATIVE_AOT_SMOKE + using var services = CreateServices(); + var provider = services.GetRequiredService(); + var contexts = services.GetRequiredService(); + var target = new SelfWritingTarget(); + IRpcSelfWriting proxy = new global::OrleansCodeGen.Orleans.NativeAotSmoke.Proxy_IRpcSelfWriting(provider, contexts); + _ = proxy.Boolean(); + await Check(((RpcTupleProxyBase)proxy).Captured!, true); + _ = proxy.Integer(); + await Check(((RpcTupleProxyBase)proxy).Captured!, 42); + _ = proxy.Payload(); + using var request = ((RpcTupleProxyBase)proxy).Captured!; + request.SetTarget(target); + using var response = await ((IResponseInvokable)request).InvokeAndCopy(provider, contexts, + new DeepCopier(provider.GetDeepCopier(), contexts)); + Ensure(response is IRawResponseWriter && !response.GetType().IsGenericType, + "The actual generated invokable creates a non-generic self-writing holder."); + var value = response.GetResult(); + Ensure(value is not null && !ReferenceEquals(value, target.Result) && ReferenceEquals(value, value.Left), + "Generated result creation copies the mutable cyclic payload before returning."); + var buffer = new ArrayBufferWriter(); + using (var session = services.GetRequiredService().GetSession()) + { + var writer = Writer.Create(buffer, session); + ((IRawResponseWriter)response).WriteRaw(ref writer); + writer.Commit(); + } + Ensure(provider.TryGetRawResponseReader(typeof(RpcResponsePayload), out var registered), "The result reader is statically registered."); + using var readerSession = services.GetRequiredService().GetSession(); + var reader = Reader.Create(buffer.WrittenMemory, readerSession); + var field = reader.ReadFieldHeader(); + using var reconstructed = registered.ReadRaw(ref reader, ref field); + var decoded = reconstructed.GetResult(); + Ensure(decoded is not null && ReferenceEquals(decoded, decoded.Left), "The static reader reconstructs the self-writing cyclic holder."); + + async System.Threading.Tasks.Task Check(IInvokable invocation, T expected) + { + using var request = invocation; + request.SetTarget(target); + using var result = await ((IResponseInvokable)request).InvokeAndCopy(provider, contexts, + new DeepCopier(provider.GetDeepCopier(), contexts)); + Ensure(result is IRawResponseWriter && Equals(expected, result.GetResult()), "Generated primitive responses bind direct writers."); + } +#else + await System.Threading.Tasks.Task.CompletedTask; +#endif + } + +#if NATIVE_AOT_SMOKE + private sealed class SelfWritingTarget : IRpcSelfWriting, ITargetHolder + { + public RpcResponsePayload Result { get; } = new() { Value = 47 }; + public SelfWritingTarget() => Result.Left = Result; + public object GetTarget() => this; + public object? GetComponent(Type type) => type.IsInstanceOfType(this) ? this : null; + public System.Threading.Tasks.Task Boolean() => System.Threading.Tasks.Task.FromResult(true); + public System.Threading.Tasks.ValueTask Integer() => new(42); + public System.Threading.Tasks.Task Payload() => System.Threading.Tasks.Task.FromResult(Result); + } +#endif + public static void ConstructTupleArgumentProxyBeforeInvocation() { using var services = CreateServices(); diff --git a/test/Orleans.NativeAotSmoke/RpcResponses.cs b/test/Orleans.NativeAotSmoke/RpcResponses.cs index a2fa17216bc..fd9475706a8 100644 --- a/test/Orleans.NativeAotSmoke/RpcResponses.cs +++ b/test/Orleans.NativeAotSmoke/RpcResponses.cs @@ -2,6 +2,7 @@ using Orleans.NativeAotSmoke; RpcResponseContracts.PrimitiveResponses(); +await RpcResponseContracts.GeneratedInvokablesWriteCopiedResponses(); RpcResponseContracts.CanonicalValueAndArrayServices(); RpcResponseContracts.ConstructTupleArgumentProxyBeforeInvocation(); RpcResponseContracts.ReferenceResponsePreservesCycles(); diff --git a/test/Orleans.NativeAotSmoke/RpcResponsesModels.cs b/test/Orleans.NativeAotSmoke/RpcResponsesModels.cs index acb6b21ac65..89f14a2b666 100644 --- a/test/Orleans.NativeAotSmoke/RpcResponsesModels.cs +++ b/test/Orleans.NativeAotSmoke/RpcResponsesModels.cs @@ -47,6 +47,7 @@ public sealed class RpcTupleReference } [DefaultInvokableBaseType(typeof(Task<>), typeof(TaskRequest<>))] +[DefaultInvokableBaseType(typeof(ValueTask<>), typeof(Request<>))] public abstract class RpcTupleProxyBase { protected RpcTupleProxyBase(ICodecProvider provider, CopyContextPool pool) @@ -57,8 +58,13 @@ protected RpcTupleProxyBase(ICodecProvider provider, CopyContextPool pool) protected ICodecProvider CodecProvider { get; } protected CopyContextPool CopyContextPool { get; } + public IInvokable? Captured { get; private set; } protected T GetInvokable() where T : class, IInvokable, new() => new T(); - protected ValueTask InvokeAsync(IInvokable body) => default; + protected ValueTask InvokeAsync(IInvokable body) + { + Captured = body; + return default; + } protected ValueTask InvokeAsync(IInvokable body) => default; protected void Invoke(IInvokable body) { } } @@ -69,6 +75,14 @@ public interface IRpcTupleArguments Task Accept(System.Collections.Generic.List> input); } +[GenerateMethodSerializers(typeof(RpcTupleProxyBase))] +public interface IRpcSelfWriting +{ + Task Boolean(); + ValueTask Integer(); + Task Payload(); +} + [GenerateSerializer] public sealed class RpcResponsePayload { diff --git a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs index 3782545c94a..f28729cdec1 100644 --- a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs +++ b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs @@ -12,6 +12,7 @@ using Orleans.Serialization.Invocation; using Orleans.Serialization.Serializers; using Orleans.Serialization.Session; +using Orleans.Serialization.WireProtocol; namespace Orleans.Serialization.UnitTests; @@ -351,6 +352,275 @@ private static IInvokable CreateInvokable(string methodName) return result; } + [Theory] + [InlineData("Boolean")] + [InlineData("Integer")] + [InlineData("Payload")] + public async Task GeneratedResponseHoldersCopyAndWriteDirectly(string methodName) + { + var target = new RpcResponseTarget(); + using var invokable = CreateInvokable(methodName); + invokable.SetTarget(new TargetHolder(target)); + var direct = Assert.IsAssignableFrom(invokable); + var provider = _services.GetRequiredService(); + var contexts = _services.GetRequiredService(); + var compatibility = new CountingResponseCopier(); + using var response = await direct.InvokeAndCopy(provider, contexts, new DeepCopier(compatibility, contexts)); + var writer = Assert.IsAssignableFrom(response); + Assert.False(response.GetType().IsGenericType); + Assert.Equal(0, compatibility.Copies); + if (methodName == "Payload") + { + var value = response.GetResult(); + Assert.NotNull(value); + Assert.NotSame(target.Result, value); + Assert.Equal(17, value.Value); + target.Result.Value = 91; + Assert.Equal(17, value.Value); + } + + Assert.NotNull(response.GetSimpleResultType()); + var expected = response.GetSimpleResultType()!; + Assert.True(provider.TryGetRawResponseReader(expected, out var registered)); + var output = new ArrayBufferWriter(); + using (var session = _services.GetRequiredService().GetSession()) + { + var body = Writer.Create(output, session); + writer.WriteRaw(ref body); + body.Commit(); + } + + using var readerSession = _services.GetRequiredService().GetSession(); + var reader = Reader.Create(output.WrittenMemory, readerSession); + var field = reader.ReadFieldHeader(); + Assert.Equal(expected, field.FieldType); + using var decoded = registered!.ReadRaw(ref reader, ref field); + Assert.IsAssignableFrom(decoded); + if (methodName == "Payload") Assert.Equal(17, decoded.GetResult()!.Value); + else Assert.Equal(response.Result, decoded.Result); + } + + [Fact] + public async Task GeneratedResponseHolderPreservesRawWireBytesAndPoolReset() + { + using var invokable = CreateInvokable("Integer"); + invokable.SetTarget(new TargetHolder(new RpcResponseTarget())); + var provider = _services.GetRequiredService(); + var contexts = _services.GetRequiredService(); + var direct = Assert.IsAssignableFrom(invokable); + var response = await direct.InvokeAndCopy(provider, contexts, _services.GetRequiredService().GetCopier()); + var body = new ArrayBufferWriter(); + var legacy = new ArrayBufferWriter(); + var sessions = _services.GetRequiredService(); + using (var session = sessions.GetSession()) + { + var writer = Writer.Create(body, session); + Assert.IsAssignableFrom(response).WriteRaw(ref writer); + writer.Commit(); + } + using (var session = sessions.GetSession()) + { + using var original = Response.FromResult(42); + var writer = Writer.Create(legacy, session); + ((ResponseCodec)provider.GetCodec(original.GetType())).WriteRaw(ref writer, original); + writer.Commit(); + } + Assert.Equal(legacy.WrittenSpan.ToArray(), body.WrittenSpan.ToArray()); + response.Dispose(); + Assert.Equal(0, response.GetResult()); + var factory = response.GetType().GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic) + .Single(static field => field.Name == "_factory"); + Assert.Null(factory.GetValue(response)); + using var reused = await direct.InvokeAndCopy(provider, contexts, _services.GetRequiredService().GetCopier()); + Assert.Same(response, reused); + Assert.Equal(42, reused.GetResult()); + } + + [Fact] + public async Task GeneratedResponseHolderKeepsExceptionBehavior() + { + using var invokable = CreateInvokable("Boolean"); + invokable.SetTarget(new TargetHolder(new RpcResponseTarget { Fail = true })); + var contexts = _services.GetRequiredService(); + var compatibility = new CountingResponseCopier(); + using var response = await Assert.IsAssignableFrom(invokable).InvokeAndCopy( + _services.GetRequiredService(), contexts, new DeepCopier(compatibility, contexts)); + Assert.IsType(response); + Assert.Equal("response failure", response.Exception!.Message); + Assert.Equal(0, compatibility.Copies); + } + + [Fact] + public async Task GeneratedResponseHolderPreservesCyclesAndNullPayloads() + { + var target = new RpcResponseTarget(); + target.Result.Left = target.Result; + target.Result.Right = target.Result; + using var invokable = CreateInvokable("Payload"); + invokable.SetTarget(new TargetHolder(target)); + var provider = _services.GetRequiredService(); + var contexts = _services.GetRequiredService(); + using var response = await Assert.IsAssignableFrom(invokable).InvokeAndCopy( + provider, contexts, _services.GetRequiredService().GetCopier()); + var value = response.GetResult(); + Assert.NotNull(value); + Assert.NotSame(target.Result, value); + Assert.Same(value, value.Left); + Assert.Same(value.Left, value.Right); + Assert.True(provider.TryGetRawResponseReader(typeof(NativeAotSmoke.RpcResponsePayload), out var registered)); + var buffer = new ArrayBufferWriter(); + using (var session = _services.GetRequiredService().GetSession()) + { + var writer = Writer.Create(buffer, session); + ((IRawResponseWriter)response).WriteRaw(ref writer); + writer.Commit(); + } + using var readerSession = _services.GetRequiredService().GetSession(); + var reader = Reader.Create(buffer.WrittenMemory, readerSession); + var field = reader.ReadFieldHeader(); + using var result = registered!.ReadRaw(ref reader, ref field); + var copied = result.GetResult(); + Assert.NotNull(copied); + Assert.Same(copied, copied.Left); + Assert.Same(copied.Left, copied.Right); + + invokable.SetTarget(new TargetHolder(new NullPayloadTarget())); + using var empty = await ((IResponseInvokable)invokable).InvokeAndCopy(provider, contexts, _services.GetRequiredService().GetCopier()); + Assert.IsAssignableFrom(empty); + Assert.Null(empty.GetResult()); + } + + [Fact] + public async Task GeneratedResponseHolderHonorsCustomPayloadCopier() + { + using var services = new ServiceCollection().AddSerializer(builder => + builder.Configure(options => options.AddCopier(typeof(CustomPayloadCopier)))).BuildServiceProvider(); + var provider = services.GetRequiredService(); + var contexts = services.GetRequiredService(); + var target = new RpcResponseTarget(); + using var invokable = CreateInvokable("Payload"); + invokable.SetTarget(new TargetHolder(target)); + using var result = await Assert.IsAssignableFrom(invokable).InvokeAndCopy( + provider, contexts, services.GetRequiredService().GetCopier()); + Assert.IsType>(result); + Assert.Same(target.Result, result.GetResult()); + Assert.False(provider.TryGetRawResponseReader(typeof(NativeAotSmoke.RpcResponsePayload), out _)); + } + + [Theory] + [InlineData("PayloadCodec")] + [InlineData("ResponseCodec")] + [InlineData("ResponseCopier")] + public async Task GeneratedResponseHolderHonorsCustomResultAndResponseServices(string service) + { + var payloadCodec = new DelegatingCodec(new Int32Codec()); + var responseCodec = new DelegatingCodec>(new PooledResponseCodec(new Int32Codec())); + var responseCopier = new TransformingResponseCopier(); + using var services = new ServiceCollection().AddSerializer(builder => builder.Configure(options => + { + if (service == "PayloadCodec") + options.AddSerializer(_ => payloadCodec, _ => new ShallowCopier()); + else if (service == "ResponseCodec") + options.AddSerializer>(_ => responseCodec, _ => new PooledResponseCopier>(new ShallowCopier())); + else + options.AddSerializer>(_ => new PooledResponseCodec(new Int32Codec()), _ => responseCopier); + })).BuildServiceProvider(); + var provider = services.GetRequiredService(); + var contexts = services.GetRequiredService(); + using var invokable = CreateInvokable("Integer"); + invokable.SetTarget(new TargetHolder(new RpcResponseTarget())); + using var result = await Assert.IsAssignableFrom(invokable).InvokeAndCopy( + provider, contexts, services.GetRequiredService().GetCopier()); + + Assert.IsType>(result); + Assert.Equal(service == "ResponseCopier" ? 43 : 42, result.GetResult()); + Assert.Equal(service == "ResponseCopier" ? 1 : 0, responseCopier.Copies); + Assert.False(provider.TryGetRawResponseReader(typeof(int), out _)); + if (service == "PayloadCodec") Assert.Same(payloadCodec, provider.GetCodec()); + if (service == "ResponseCodec") Assert.Same(responseCodec, provider.GetCodec>()); + if (service == "ResponseCopier") Assert.Same(responseCopier, provider.GetDeepCopier>()); + } + + [Fact] + public async Task GeneratedResponseReaderReturnsHolderAfterMalformedPayload() + { + using var invokable = CreateInvokable("Integer"); + invokable.SetTarget(new TargetHolder(new RpcResponseTarget())); + var provider = _services.GetRequiredService(); + var contexts = _services.GetRequiredService(); + var direct = Assert.IsAssignableFrom(invokable); + var copier = _services.GetRequiredService().GetCopier(); + var original = await direct.InvokeAndCopy(provider, contexts, copier); + original.Dispose(); + Assert.True(provider.TryGetRawResponseReader(typeof(int), out var registered)); + var sessions = _services.GetRequiredService(); + var malformed = new ArrayBufferWriter(); + using (var session = sessions.GetSession()) + { + var writer = Writer.Create(malformed, session); + writer.WriteStartObject(0, null!, typeof(int)); + writer.WriteFieldHeaderExpected(0, WireType.TagDelimited); + writer.WriteEndObject(); + writer.WriteEndObject(); + writer.Commit(); + } + + var error = Assert.Throws(() => + { + using var session = sessions.GetSession(); + var reader = Reader.Create(malformed.WrittenMemory, session); + var field = reader.ReadFieldHeader(); + registered!.ReadRaw(ref reader, ref field); + }); + Assert.Equal("wireType", error.ParamName); + Assert.Equal(0, original.GetResult()); + Assert.Null(original.GetType().GetField("_factory", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!.GetValue(original)); + using var reused = await direct.InvokeAndCopy(provider, contexts, copier); + Assert.Same(original, reused); + Assert.Equal(42, reused.GetResult()); + } + + private sealed class DelegatingCodec(IFieldCodec codec) : IFieldCodec + { + public void WriteField(ref Writer writer, uint fieldIdDelta, + [System.Diagnostics.CodeAnalysis.AllowNull] Type expectedType, [System.Diagnostics.CodeAnalysis.AllowNull] T value) + where TBufferWriter : IBufferWriter => codec.WriteField(ref writer, fieldIdDelta, expectedType, value); + [return: System.Diagnostics.CodeAnalysis.MaybeNull] + public T ReadValue(ref Reader reader, Field field) => codec.ReadValue(ref reader, field); + } + + private sealed class TransformingResponseCopier : IDeepCopier> + { + public int Copies { get; private set; } + [return: System.Diagnostics.CodeAnalysis.NotNullIfNotNull(nameof(input))] + public Response? DeepCopy(Response? input, CopyContext context) + { + if (input is null) return null; + Copies++; + return (Response)Response.FromResult(input.TypedResult + 1); + } + } + + private sealed class NullPayloadTarget : NativeAotSmoke.IRpcResponses + { + public Task Boolean() => Task.FromResult(true); + public ValueTask Integer() => new(42); + public Task Payload() => Task.FromResult(null!); + public Task> Value() => Task.FromResult(new NativeAotSmoke.RpcGeneratedValue()); + public Task> Bytes() => Task.FromResult(new NativeAotSmoke.RpcResponseBox { Value = [7, 9] }); + } + + private sealed class CountingResponseCopier : IDeepCopier + { + public int Copies { get; private set; } + [return: System.Diagnostics.CodeAnalysis.NotNullIfNotNull(nameof(input))] + public Response? DeepCopy(Response? input, CopyContext context) + { + Copies++; + return input; + } + } + private sealed class TargetHolder(object target) : ITargetHolder { public object GetTarget() => target; From 782777fabe8305fea1fb52e4a05990617dd1a117 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Fri, 2 Oct 2026 09:34:14 -0700 Subject: [PATCH 16/54] test(nativeaot): round-trip self-writing primitive responses --- .../RpcResponses.Contracts.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs b/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs index 54bda4d6890..2760ebec0f4 100644 --- a/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs +++ b/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs @@ -58,6 +58,20 @@ async System.Threading.Tasks.Task Check(IInvokable invocation, T expected) using var result = await ((IResponseInvokable)request).InvokeAndCopy(provider, contexts, new DeepCopier(provider.GetDeepCopier(), contexts)); Ensure(result is IRawResponseWriter && Equals(expected, result.GetResult()), "Generated primitive responses bind direct writers."); + var output = new ArrayBufferWriter(); + using (var session = services.GetRequiredService().GetSession()) + { + var writer = Writer.Create(output, session); + ((IRawResponseWriter)result).WriteRaw(ref writer); + writer.Commit(); + } + Ensure(provider.TryGetRawResponseReader(typeof(T), out var registered), "The primitive result reader is statically registered."); + using var readerSession = services.GetRequiredService().GetSession(); + var reader = Reader.Create(output.WrittenMemory, readerSession); + var field = reader.ReadFieldHeader(); + using var decoded = registered.ReadRaw(ref reader, ref field); + Ensure(decoded is IRawResponseWriter && Equals(expected, decoded.GetResult()), + "Generated primitive writers and readers round-trip through the native message session."); } #else await System.Threading.Tasks.Task.CompletedTask; From 42b494ec274d095974092da97458e6d063cae670 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Fri, 2 Oct 2026 12:20:32 -0700 Subject: [PATCH 17/54] fix(rpc): preserve custom selection for generated default graphs --- .../docs/implementation/serialization.md | 10 +- .../RpcResponseGenerator.cs | 1 - .../SerializerFactoryGenerator.cs | 50 +++++++--- .../Configuration/TypeManifestOptions.cs | 86 +++++++++++++++++ .../Serializers/CodecProvider.cs | 69 ++++++++++++-- .../OrleansSourceGeneratorTests.cs | 13 ++- .../RpcResponseTests.cs | 94 ++++++++++++++++--- 7 files changed, 280 insertions(+), 43 deletions(-) diff --git a/docs/site/src/content/docs/implementation/serialization.md b/docs/site/src/content/docs/implementation/serialization.md index 3d50984d7b5..36b8024ed4c 100644 --- a/docs/site/src/content/docs/implementation/serialization.md +++ b/docs/site/src/content/docs/implementation/serialization.md @@ -139,17 +139,17 @@ Generated holders implement using the result type from the wire header. Generated registrations reconstruct a bound holder directly. Compatibility paths retain ordinary response codecs for custom response/payload implementations, custom invokable bases, and unresolved generic contracts. Generated direct factories activate only when the selected result and response codecs/copiers match the canonical implementations, so explicit application behavior retains precedence. -For concrete `Task` and `ValueTask` method results, generated metadata supplies a closed response codec and copier graph for NativeAOT execution. The graph uses the concrete result implementations in and . Recursive result dependencies resolve with a construction caller after the response implementation has been allocated. Reference payload codecs and copiers preserve payload cycles and shared references, and the pooled response envelope retains the existing field and raw-message encoding. +For concrete `Task` and `ValueTask` method results, generated metadata supplies a closed response codec and copier graph in JIT and NativeAOT execution. The graph uses the concrete result implementations in and . Recursive result dependencies resolve with a construction caller after the response implementation has been allocated. Reference payload codecs and copiers preserve payload cycles and shared references, and the pooled response envelope retains the existing field and raw-message encoding. The graph also registers polymorphic codec and copier dispatch for the non-generic boundary used by the runtime client. That dispatch selects the closed implementation for the actual response type and preserves the identity of immutable completed and exception responses. The native smoke uses with `Response`, matching the runtime's response-copy boundary. Completed response transport uses the existing generated codec and its canonical singleton activator, restoring after a round-trip. Interfaces containing only non-generic `Task` or `ValueTask` methods also generate this shared response/completion graph. -The finite strict response graph supplies successful typed results and completed-response transport, plus immutable exception-envelope copying. Exception transport in an explicit context requires an codec and the declared exception and `Data` value type graph. Lookup reports that registration contract when it is missing. Ordinary metadata mode retains the existing exception codecs and their serialization-constructor support. +The finite response graph supplies successful typed results and completed-response transport, plus immutable exception-envelope copying. Exception transport uses the selected codec and the exception and `Data` value dependencies. Closed factories provide statically compiled implementations; registered metadata and the existing exception codecs provide the remaining supported serialization contracts. -These supplemental registrations are defaults: explicit closed factory registrations take precedence in either configuration order. The native closed dependency graph activates when runtime code generation is unavailable. Direct-holder factories and raw-reader registrations bind the selected provider implementations in both JIT and native execution. Custom application codec/copier selection uses the compatibility invocation and serialization path. Explicit factory and context registration also works in JIT execution. +These supplemental registrations are defaults: explicit closed factory registrations take precedence in either configuration order. Generated factories and registered metadata use one resolution pipeline, with closed services selected first. Direct-holder factories and raw-reader registrations bind the selected provider implementations in both JIT and native execution. Custom application codec/copier selection uses the compatibility invocation and serialization path. -Ordinary metadata mode also supplies static response factories for non-generic generated result models. These factories construct the model's canonical generated codec and copier using their generated constructor signatures. Construction dependencies include the selected activator and declared codec/copier service contracts; source-known finite dependencies use closed factories, while interface contracts use ordinary metadata dispatch. This keeps construction within the provider's publication boundary and preserves canonical service identity and rollback. Default activation uses the existing reference- or value-type activator implementation, and custom activation retains its declared contract. Explicit context mode uses the complete finite dependency graph and validates each declared member shape. +Generated metadata also supplies static response factories for non-generic generated result models. These factories construct the model's canonical generated codec and copier using their generated constructor signatures. Construction dependencies include the selected activator and declared codec/copier service contracts; source-known finite dependencies use closed factories, while interface contracts use registered metadata dispatch. This keeps construction within the provider's publication boundary and preserves canonical service identity and rollback. Default activation uses the existing reference- or value-type activator implementation, and custom activation retains its declared contract. Serializer contexts contribute their complete finite dependency graphs and validate each declared member shape. The same collector closes source-known argument construction dependencies selected by generated proxy constructors. Tuple arguments and tuple members use the existing closed `TupleCodec` and `TupleCopier` implementations with their declared element services. Parameter-only one-way contracts register the required construction services while completion and result contracts also register their response graphs. Static interface helpers contribute no RPC construction roots. @@ -157,7 +157,7 @@ The same collector closes source-known argument construction dependencies select Dictionary results and dictionary members require an explicit closed registration which preserves the application's comparer contract. A dictionary's comparer is selected per value, so the method's declared result type alone supplies the key/value shape while the registration supplies comparer serialization and copying. -The focused native smoke exercises the generated response graph for boolean, integer, and reference results, including recursive factory dependencies and payload identity. Full silo startup and RPC execution additionally require the native support for activation, request serialization, grain references, and runtime metadata. +The focused .NET 10 NativeAOT smoke exercises the generated response graph for boolean, integer, and reference results, including recursive factory dependencies and payload identity. Full silo startup and RPC execution additionally require the native support for activation, request serialization, grain references, and runtime metadata. Managed .NET 8 tests exercise JIT compatibility and compiled-reference contracts. Source: [RPC response factory generation](https://github.com/dotnet/orleans/blob/main/src/Orleans.CodeGenerator/RpcResponseGenerator.cs), [closed serializer factory graphs](https://github.com/dotnet/orleans/blob/main/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs), and [native response smoke](https://github.com/dotnet/orleans/blob/main/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs). diff --git a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs index f7695ed6474..c9d97991df4 100644 --- a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs +++ b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs @@ -216,7 +216,6 @@ internal static ImmutableArray Generate( source.AppendLine($"options.AddRawResponseReader<{type}>(static provider => {resolve});"); } source.AppendLine("#if NET5_0_OR_GREATER"); - source.AppendLine("if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) return;"); if (graph is not null) { source.AppendLine(graph.ConfigurationStatements); diff --git a/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs b/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs index 4aa47d6d937..d43f9a1c9fd 100644 --- a/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs +++ b/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs @@ -124,7 +124,7 @@ internal sealed record Failure(ITypeSymbol Type, string Reason); var activatorName = $"global::{constructionModel.GeneratedNamespace}.{ActivatorGenerator.GetSimpleClassName(constructionModel)}"; var activator = new ActivatorGenerator(services).GenerateActivator(constructionModel); result.Append("options.AddDefaultSerializerService>(static provider => ") + .Append(Name(type)).Append(">, ").Append(activatorName).Append(">(static provider => ") .Append(ConstructGenerated(activatorName, activator)).AppendLine(");"); } else if (requiresActivator && !type.HasAttribute(services.LibraryTypes.UseActivatorAttribute) @@ -132,7 +132,8 @@ internal sealed record Failure(ITypeSymbol Type, string Reason); { var factory = type.IsValueType ? "CreateDefaultValueTypeActivator" : "CreateDefaultReferenceTypeActivator"; result.Append("options.AddDefaultSerializerService>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.") + .Append(Name(type)).Append(">, global::Orleans.Serialization.Activators.IActivator<").Append(Name(type)) + .Append(">>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.") .Append(factory).Append('<').Append(Name(type)).AppendLine(">());"); } @@ -140,6 +141,12 @@ internal sealed record Failure(ITypeSymbol Type, string Reason); .Append(registration.CodecConstruction).AppendLine(");"); result.Append("options.AddDefaultSerializerService<").Append(registration.Copier).Append(">(static provider => ") .Append(registration.CopierConstruction).AppendLine(");"); + result.Append("options.AddDefaultSerializerService, ").Append(registration.Codec).Append(">(static provider => ") + .Append(Resolve(registration.Codec)).AppendLine(");"); + result.Append("options.AddDefaultSerializerService, ").Append(registration.Copier).Append(">(static provider => ") + .Append(Resolve(registration.Copier)).AppendLine(");"); if (!includeResponse) { return new Graph(new Dictionary(SymbolEqualityComparer.Default) { [type] = registration }, result.ToString()); @@ -149,8 +156,10 @@ internal sealed record Failure(ITypeSymbol Type, string Reason); .Append(codec).Append("(caller => ").Append(Resolve(registration.Codec, "caller")).AppendLine("));"); result.Append("options.AddDefaultSerializerService<").Append(copier).Append(">(static provider => new ") .Append(copier).Append("(caller => ").Append(Resolve(registration.Copier, "caller")).AppendLine("));"); - result.Append("options.AddDefaultSerializer<").Append(Name(responseType)).Append(">(static provider => ") - .Append(Resolve(codec)).Append(", static provider => ").Append(Resolve(copier)).AppendLine(");"); + result.Append("options.AddDefaultSerializer<").Append(Name(responseType)).Append(", ").Append(codec).Append(", ").Append(copier).Append(">(static provider => ") + .Append(Resolve(codec)).Append(", static provider => ").Append(Resolve(copier)) + .Append(", codecDependencies: ").Append(DefaultDependencyServices([type], codec: true)) + .Append(", copierDependencies: ").Append(DefaultDependencyServices([type], codec: false)).AppendLine(");"); result.Append("options.AddAllowedType(typeof(").Append(Name(responseType)).AppendLine("));"); return new Graph(new Dictionary(SymbolEqualityComparer.Default) { [type] = registration }, result.ToString()); @@ -201,8 +210,10 @@ private static void AppendConstructionDependency(IGeneratorServices services, IT .Append(ConstructReferenced(Name(tupleCodec), tupleCodec)).AppendLine(");"); result.Append("options.AddDefaultSerializerService<").Append(Name(tupleCopier)).Append(">(static provider => ") .Append(ConstructReferenced(Name(tupleCopier), tupleCopier)).AppendLine(");"); - result.Append("options.AddDefaultSerializer<").Append(Name(tupleType)).Append(">(static provider => ") - .Append(Resolve(Name(tupleCodec))).Append(", static provider => ").Append(Resolve(Name(tupleCopier))).AppendLine(");"); + result.Append("options.AddDefaultSerializer<").Append(Name(tupleType)).Append(", ").Append(Name(tupleCodec)).Append(", ").Append(Name(tupleCopier)).Append(">(static provider => ") + .Append(Resolve(Name(tupleCodec))).Append(", static provider => ").Append(Resolve(Name(tupleCopier))) + .Append(", codecDependencies: ").Append(DefaultDependencyServices(tupleType.TypeArguments, codec: true)) + .Append(", copierDependencies: ").Append(DefaultDependencyServices(tupleType.TypeArguments, codec: false)).AppendLine(");"); return; } @@ -224,8 +235,10 @@ private static void AppendConstructionDependency(IGeneratorServices services, IT .Append(ConstructReferenced(Name(codec), codec, preferCompleteConstructor: true)).AppendLine(");"); result.Append("options.AddDefaultSerializerService<").Append(Name(copier)).Append(">(static provider => ") .Append(ConstructReferenced(Name(copier), copier)).AppendLine(");"); - result.Append("options.AddDefaultSerializer<").Append(Name(collection)).Append(">(static provider => ") - .Append(Resolve(Name(codec))).Append(", static provider => ").Append(Resolve(Name(copier))).AppendLine(");"); + result.Append("options.AddDefaultSerializer<").Append(Name(collection)).Append(", ").Append(Name(codec)).Append(", ").Append(Name(copier)).Append(">(static provider => ") + .Append(Resolve(Name(codec))).Append(", static provider => ").Append(Resolve(Name(copier))) + .Append(", codecDependencies: ").Append(DefaultDependencyServices(collection.TypeArguments, codec: true)) + .Append(", copierDependencies: ").Append(DefaultDependencyServices(collection.TypeArguments, codec: false)).AppendLine(");"); return; } @@ -364,12 +377,23 @@ internal static bool TryCreate( .Append(registration.CodecConstruction).AppendLine(");"); result.Append("options.").Append(addService).Append('<').Append(registration.Copier).Append(">(static provider => ") .Append(registration.CopierConstruction).AppendLine(");"); - result.Append("options.").Append(addSerializer).Append('<').Append(typeName).Append(">(static provider => ") - .Append(Resolve(registration.Codec)).Append(", static provider => ").Append(Resolve(registration.Copier)).AppendLine(");"); + result.Append("options.").Append(addSerializer).Append('<').Append(typeName); + if (useDefaultFactories) + result.Append(", ").Append(registration.Codec).Append(", ").Append(registration.Copier); + result.Append(">(static provider => ") + .Append(Resolve(registration.Codec)).Append(", static provider => ").Append(Resolve(registration.Copier)); + if (useDefaultFactories && registration.Dependencies.Count > 0) + { + result.Append(", codecDependencies: ").Append(DefaultDependencyServices(registration.Dependencies, codec: true)) + .Append(", copierDependencies: ").Append(DefaultDependencyServices(registration.Dependencies, codec: false)); + } + result.AppendLine(");"); if (registration.Model is { IsValueType: true, IsEnumType: false }) { result.Append("options.").Append(addService).Append(">(static provider => ").Append(Resolve(registration.Codec)).AppendLine(");"); + .Append(typeName).Append('>'); + if (useDefaultFactories) result.Append(", ").Append(registration.Codec); + result.Append(">(static provider => ").Append(Resolve(registration.Codec)).AppendLine(");"); } if (hasBaseCodec) { @@ -424,6 +448,10 @@ void ResolveResponseImplementations(Registration registration) } } + private static string DefaultDependencyServices(IEnumerable dependencies, bool codec) + => "new global::System.Type[] { " + string.Join(", ", dependencies.Select(dependency => + $"typeof(global::Orleans.Serialization.{(codec ? "Codecs.IFieldCodec" : "Cloning.IDeepCopier")}<{Name(dependency)}>)")) + " }"; + private static string? Describe(Registration registration, IGeneratorServices services, Compilation implementationCompilation, CancellationToken cancellationToken) { var type = registration.Type; diff --git a/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs b/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs index a860081f3fa..8367ff9bb6d 100644 --- a/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs +++ b/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs @@ -48,6 +48,9 @@ public sealed class TypeManifestOptions internal Dictionary> CodecFactories { get; } = new(); internal Dictionary> CopierFactories { get; } = new(); internal Dictionary> SerializerServiceFactories { get; } = new(); + internal Dictionary DefaultSerializerContracts { get; } = new(); + internal Dictionary DefaultCodecFactoryContracts { get; } = new(); + internal Dictionary DefaultCopierFactoryContracts { get; } = new(); internal Dictionary> RawResponseReaderFactories { get; } = new(); /// @@ -91,6 +94,46 @@ public void AddDefaultSerializer( Func> copierFactory) => RegisterSerializerFactories(codecFactory, copierFactory, isDefault: true); + /// + /// Registers inferred closed factories with their canonical implementations and construction dependencies. + /// + /// The serialized type. + /// The canonical field codec. + /// The canonical deep copier. + /// The field codec factory. + /// The deep copier factory. + /// An equivalent metadata codec implementation. + /// An equivalent metadata copier implementation. + /// The canonical codec's serialization service dependencies. + /// The canonical copier's serialization service dependencies. + /// Inferred factories yield to the selected custom metadata implementation and explicit factories. + public void AddDefaultSerializer( + Func> codecFactory, + Func> copierFactory, + Type? compatibleCodecType = null, + Type? compatibleCopierType = null, + Type[]? codecDependencies = null, + Type[]? copierDependencies = null) + where TCodec : class, IFieldCodec + where TCopier : class, IDeepCopier + { + codecDependencies = CopyDefaultDependencies(codecDependencies); + copierDependencies = CopyDefaultDependencies(copierDependencies); + var registerCodec = !SerializerServiceFactories.ContainsKey(typeof(IFieldCodec)); + var registerCopier = !SerializerServiceFactories.ContainsKey(typeof(IDeepCopier)); + RegisterSerializerFactories(codecFactory, copierFactory, isDefault: true); + if (registerCodec) + { + RegisterDefaultContract(typeof(IFieldCodec), typeof(TCodec), compatibleCodecType, codecDependencies); + DefaultCodecFactoryContracts.Add(typeof(T), DefaultSerializerContracts[typeof(IFieldCodec)]); + } + if (registerCopier) + { + RegisterDefaultContract(typeof(IDeepCopier), typeof(TCopier), compatibleCopierType, copierDependencies); + DefaultCopierFactoryContracts.Add(typeof(T), DefaultSerializerContracts[typeof(IDeepCopier)]); + } + } + private void RegisterSerializerFactories( Func> codecFactory, Func> copierFactory, @@ -141,6 +184,49 @@ public void AddDefaultSerializerService(Func AddSerializerServiceFactory(typeof(TService), factory, isDefault: true); } + /// + /// Registers an inferred service factory with its canonical implementation identity. + /// + /// The serialization service contract. + /// The canonical implementation. + /// The service factory. + /// An equivalent metadata implementation. + /// The canonical implementation's serialization service dependencies. + public void AddDefaultSerializerService( + Func factory, + Type? compatibleImplementationType = null, + Type[]? dependencies = null) + where TService : class + where TImplementation : class, TService + { + dependencies = CopyDefaultDependencies(dependencies); + var register = !SerializerServiceFactories.ContainsKey(typeof(TService)); + AddDefaultSerializerService(factory); + if (register) RegisterDefaultContract(typeof(TService), typeof(TImplementation), compatibleImplementationType, dependencies); + } + + internal bool IsDefaultSerializerService(Type type) => _defaultSerializerServices.Contains(type); + + private void RegisterDefaultContract(Type service, Type implementation, Type? compatible, Type[]? dependencies) + { + if (!_defaultSerializerServices.Contains(service) || DefaultSerializerContracts.ContainsKey(service)) return; + var copiedDependencies = dependencies ?? Type.EmptyTypes; + DefaultSerializerContracts.Add(service, new(service, implementation, compatible, copiedDependencies)); + DefaultSerializerContracts.TryAdd(implementation, new(service, implementation, compatible, copiedDependencies)); + } + + private static Type[] CopyDefaultDependencies(Type[]? dependencies) + { + var result = dependencies is null ? Type.EmptyTypes : (Type[])dependencies.Clone(); + foreach (var dependency in result) + { + if (dependency is null) throw new ArgumentException("Serialization service dependencies must be non-null.", nameof(dependencies)); + } + return result; + } + + internal sealed record DefaultSerializerContract(Type Service, Type Implementation, Type? CompatibleImplementation, Type[] Dependencies); + private void AddSerializerServiceFactory(Type type, Func factory, bool isDefault) { if (!isDefault && _defaultSerializerServices.Remove(type)) diff --git a/src/Orleans.Serialization/Serializers/CodecProvider.cs b/src/Orleans.Serialization/Serializers/CodecProvider.cs index 6525a78821d..a9479450231 100644 --- a/src/Orleans.Serialization/Serializers/CodecProvider.cs +++ b/src/Orleans.Serialization/Serializers/CodecProvider.cs @@ -252,7 +252,7 @@ void AddFromMetadata( public IFieldCodec? TryGetCodec() { var fieldType = typeof(TField); - if (_manifest.CodecFactories.TryGetValue(fieldType, out var factory)) return (IFieldCodec)factory(this); + if (_manifest.CodecFactories.TryGetValue(fieldType, out var factory) && IsDefaultCodecEligible(fieldType)) return (IFieldCodec)factory(this); if (TryGetCached(_typedCodecs, fieldType, out var existing)) return (IFieldCodec)existing; @@ -280,7 +280,7 @@ public IFieldCodec GetCodec(Type fieldType) /// public IFieldCodec? TryGetCodec(Type fieldType) { - if (fieldType is not null && _manifest.CodecFactories.TryGetValue(fieldType, out var factory)) return factory(this); + if (fieldType is not null && _manifest.CodecFactories.TryGetValue(fieldType, out var factory) && IsDefaultCodecEligible(fieldType)) return factory(this); // If the field type is unavailable, return the void codec which can at least handle references. return fieldType is null ? _voidCodec : TryGetCached(_untypedCodecs, fieldType, out var existing) ? existing @@ -295,7 +295,7 @@ public IFieldCodec GetCodec(Type fieldType) private IFieldCodec? TryCreateCodecInner(Type fieldType) { - if (_manifest.CodecFactories.TryGetValue(fieldType, out var factory)) return factory(this); + if (_manifest.CodecFactories.TryGetValue(fieldType, out var factory) && IsDefaultCodecEligible(fieldType)) return factory(this); if (!_initialized) Initialize(); ThrowIfUnsupportedType(fieldType); @@ -437,7 +437,7 @@ public IDeepCopier GetDeepCopier() public IDeepCopier? TryGetDeepCopier() { var type = typeof(T); - if (_manifest.CopierFactories.TryGetValue(type, out var factory)) return (IDeepCopier)factory(this); + if (_manifest.CopierFactories.TryGetValue(type, out var factory) && IsDefaultCopierEligible(type)) return (IDeepCopier)factory(this); if (TryGetCached(_typedCopiers, type, out var existing)) return (IDeepCopier)existing; @@ -465,7 +465,7 @@ public IDeepCopier GetDeepCopier(Type fieldType) /// public IDeepCopier? TryGetDeepCopier(Type fieldType) { - if (fieldType is not null && _manifest.CopierFactories.TryGetValue(fieldType, out var factory)) return factory(this); + if (fieldType is not null && _manifest.CopierFactories.TryGetValue(fieldType, out var factory) && IsDefaultCopierEligible(fieldType)) return factory(this); // If the field type is unavailable, return the void copier which can at least handle references. return fieldType is null ? _voidCopier : TryGetCached(_untypedCopiers, fieldType, out var existing) ? existing @@ -481,7 +481,7 @@ public IDeepCopier GetDeepCopier(Type fieldType) private IDeepCopier? TryCreateCopierInner(Type fieldType) { - if (_manifest.CopierFactories.TryGetValue(fieldType, out var factory)) return factory(this); + if (_manifest.CopierFactories.TryGetValue(fieldType, out var factory) && IsDefaultCopierEligible(fieldType)) return factory(this); if (!_initialized) Initialize(); ThrowIfUnsupportedType(fieldType); @@ -666,9 +666,62 @@ private object ActivateService(Type type, object[]? constructorArguments) return result; } + private bool IsDefaultCodecEligible(Type type) + => !_manifest.DefaultCodecFactoryContracts.TryGetValue(type, out var contract) + || IsDefaultContractEligible(contract, []); + + private bool IsDefaultCopierEligible(Type type) + => !_manifest.DefaultCopierFactoryContracts.TryGetValue(type, out var contract) + || IsDefaultContractEligible(contract, []); + + private bool IsDefaultServiceEligible(Type service) + => !_manifest.DefaultSerializerContracts.TryGetValue(service, out var contract) + || IsDefaultContractEligible(contract, []); + + private bool IsDefaultContractEligible(TypeManifestOptions.DefaultSerializerContract contract, HashSet visited) + { + if (!_manifest.IsDefaultSerializerService(contract.Service) || !visited.Add(contract.Service)) return true; + var role = contract.Service.IsConstructedGenericType ? contract.Service.GetGenericTypeDefinition() : null; + var target = role is null ? contract.Service : contract.Service.GenericTypeArguments[0]; + var implementations = role == typeof(IFieldCodec<>) ? _fieldCodecs + : role == typeof(IDeepCopier<>) ? _copiers + : role == typeof(IBaseCodec<>) ? _baseCodecs + : role == typeof(IValueSerializer<>) ? _valueSerializers + : role == typeof(IBaseCopier<>) ? _baseCopiers + : role == typeof(IActivator<>) ? _activators + : null; + if (implementations is not null && (implementations.TryGetValue(target, out var selected) + || target.IsConstructedGenericType && implementations.TryGetValue(target.GetGenericTypeDefinition(), out selected)) + && !MatchesDefaultImplementation(selected, contract.Implementation, contract.CompatibleImplementation, target)) + return false; + foreach (var dependency in contract.Dependencies) + { + if (_manifest.DefaultSerializerContracts.TryGetValue(dependency, out var required) + && !IsDefaultContractEligible(required, visited)) + return false; + } + return true; + } + + private static bool MatchesDefaultImplementation(Type selected, Type expected, Type? compatible, Type target) + { + if (selected == expected || selected == compatible) return true; + if (!selected.IsGenericTypeDefinition) return false; + if (expected.IsConstructedGenericType && selected == expected.GetGenericTypeDefinition()) return true; + if (compatible is { IsConstructedGenericType: true } && selected == compatible.GetGenericTypeDefinition()) return true; + if (target.IsConstructedGenericType && target.GetGenericTypeDefinition() == typeof(Invocation.Response<>) + && expected.IsConstructedGenericType && expected.GenericTypeArguments[0] == target.GenericTypeArguments[0]) + { + var definition = expected.GetGenericTypeDefinition(); + return selected == typeof(Invocation.PooledResponseCodec<>) && definition == typeof(Invocation.PooledResponseCodec<,>) + || selected == typeof(Invocation.PooledResponseCopier<>) && definition == typeof(Invocation.PooledResponseCopier<,>); + } + return false; + } + internal bool TryGetSerializerService(Type type, [NotNullWhen(true)] out object? result) { - if (!_manifest.SerializerServiceFactories.TryGetValue(type, out var factory)) + if (!_manifest.SerializerServiceFactories.TryGetValue(type, out var factory) || !IsDefaultServiceEligible(type)) { result = null; return false; @@ -1021,7 +1074,7 @@ public bool IsService(Type serviceType) || serviceType == typeof(IServiceProvider) || serviceType == typeof(IServiceProviderIsService) || serviceType == typeof(IServiceProviderIsKeyedService) && owner._serviceProvider is IKeyedServiceProvider - || owner._manifest.SerializerServiceFactories.ContainsKey(serviceType) + || owner._manifest.SerializerServiceFactories.ContainsKey(serviceType) && owner.IsDefaultServiceEligible(serviceType) || owner.IsRegisteredImplementation(serviceType) || ServiceCollectionExtensions.GetServiceHolderType(serviceType) is not null; } diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index d1ad3bcc1e6..cc5e523534c 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -2272,8 +2272,10 @@ public sealed class Payload Assert.Contains("new global::OrleansCodeGen.TestProject.Codec_Payload(provider)", source); Assert.Contains("caller => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(caller, provider)", source); Assert.Contains("caller => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(caller, provider)", source); - Assert.Equal(1, CountOccurrences(source, "options.AddDefaultSerializer>")); - Assert.Contains("RuntimeFeature.IsDynamicCodeSupported", source); + Assert.Equal(1, CountOccurrences(source, "options.AddDefaultSerializer,")); + Assert.DoesNotContain("RuntimeFeature.IsDynamicCodeSupported", source); + Assert.Contains("codecDependencies: new global::System.Type[]", source); + Assert.Contains("copierDependencies: new global::System.Type[]", source); Assert.DoesNotContain("GetService Get(); } [Fact] - public async Task RpcResponseFactoriesRootCanonicalModelsInMetadataMode() + public async Task RpcResponseFactoriesRootCanonicalModelsInCommonPipeline() { var compilation = await CreateCompilation(""" using Orleans; @@ -2352,11 +2354,12 @@ public sealed class Payload var result = RunSourceGenerator(compilation); Assert.Empty(result.Diagnostics); var source = Assert.Single(result.GeneratedSources, static source => source.HintName.EndsWith(".orleans.rpcresponses.g.cs", StringComparison.Ordinal)).SourceText.ToString(); - Assert.Contains("if (!options.RequireExplicitTypeRegistration)", source); + Assert.DoesNotContain("RequireExplicitTypeRegistration", source); + Assert.DoesNotContain("RuntimeFeature.IsDynamicCodeSupported", source); Assert.Contains("new global::OrleansCodeGen.TestProject.Codec_Payload(", source); Assert.Contains("new global::OrleansCodeGen.TestProject.Copier_Payload(", source); Assert.Contains("PooledResponseCodec", source); - Assert.Contains("AddDefaultSerializerService>", source); + Assert.Contains("AddDefaultSerializerService,", source); Assert.Contains("OrleansGeneratedCodeHelper.CreateDefaultReferenceTypeActivator()", source); Assert.DoesNotContain("MakeGenericType", source); var output = compilation.AddReferences(MetadataReference.CreateFromFile(typeof(Microsoft.Extensions.Options.IConfigureOptions<>).Assembly.Location)) diff --git a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs index f28729cdec1..c00246b494b 100644 --- a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs +++ b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs @@ -135,13 +135,10 @@ public void CanonicalTupleArgumentConstructionPreservesIdentity() => NativeAotSmoke.RpcResponseContracts.ConstructTupleArgumentProxyBeforeInvocation(); [Fact] - public void ExplicitExceptionTransportRequiresDeclaredDependencyGraph() + public void ContextRegistrationPreservesExistingExceptionMetadata() { - using var services = new ServiceCollection().AddSerializerContext(new EmptyContext()).BuildServiceProvider(); - var error = Assert.Throws(() => services.GetRequiredService().GetCodec()); - Assert.Contains("ExceptionResponse", error.Message); - Assert.Contains("exception and Data value types", error.Message); - Assert.Contains("serializer context", error.Message); + using var services = new ServiceCollection().AddSerializer().AddSerializerContext(new EmptyContext()).BuildServiceProvider(); + Assert.NotNull(services.GetRequiredService().GetCodec()); } private sealed class EmptyContext : SerializerContext @@ -277,20 +274,20 @@ public void DuplicateDefaultFactoryRegistrationsUseFirstImplementation() var codec = new Int32Codec(); var copier = new ShallowCopier(); var service = new FactoryService(); - using var services = new ServiceCollection().AddSerializer(builder => - { - builder.Configure(options => + using var services = new ServiceCollection() + .Configure(options => { options.AddDefaultSerializer(_ => codec, _ => copier); options.AddDefaultSerializerService(_ => service); - }); - builder.Configure(options => + }) + .Configure(options => { options.AddDefaultSerializer(static _ => throw new InvalidOperationException("second manifest codec"), static _ => throw new InvalidOperationException("second manifest copier")); options.AddDefaultSerializerService(static _ => throw new InvalidOperationException("second manifest service")); - }); - }).BuildServiceProvider(); + }) + .AddSerializer() + .BuildServiceProvider(); var provider = services.GetRequiredService(); Assert.Same(codec, provider.GetCodec()); Assert.Same(copier, provider.GetDeepCopier()); @@ -400,6 +397,77 @@ public async Task GeneratedResponseHoldersCopyAndWriteDirectly(string methodName else Assert.Equal(response.Result, decoded.Result); } + [Theory] + [InlineData("Boolean", typeof(bool), "ContextOnly")] + [InlineData("Integer", typeof(int), "ContextOnly")] + [InlineData("Payload", typeof(NativeAotSmoke.RpcResponsePayload), "ContextOnly")] + [InlineData("Boolean", typeof(bool), "ProviderBeforeContext")] + [InlineData("Integer", typeof(int), "ProviderBeforeContext")] + [InlineData("Payload", typeof(NativeAotSmoke.RpcResponsePayload), "ProviderBeforeContext")] + [InlineData("Boolean", typeof(bool), "SameProviderBeforeContext")] + [InlineData("Integer", typeof(int), "SameProviderBeforeContext")] + [InlineData("Payload", typeof(NativeAotSmoke.RpcResponsePayload), "SameProviderBeforeContext")] + public async Task GeneratedResponseHoldersUseContextInJit(string methodName, Type resultType, string configurationOrder) + { + Assert.True(System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported); + var serviceCollection = new ServiceCollection(); + var context = new global::OrleansCodeGen.OrleansSerializationUnitTests.RpcResponseFactories(); + var beforeStrictCalls = 0; + if (configurationOrder != "ContextOnly") + { + if (configurationOrder == "SameProviderBeforeContext") + serviceCollection.AddSingleton>(context); + else + serviceCollection.AddSingleton, + global::OrleansCodeGen.OrleansSerializationUnitTests.RpcResponseFactories>(); + serviceCollection.Configure(options => + { + beforeStrictCalls++; + }); + } + serviceCollection.AddSerializerContext(context); + using var services = serviceCollection.BuildServiceProvider(); + _ = services.GetRequiredService>().Value; + Assert.Equal(configurationOrder == "ContextOnly" ? 0 : 1, beforeStrictCalls); + var provider = services.GetRequiredService(); + var contexts = services.GetRequiredService(); + var target = new RpcResponseTarget(); + var compatibility = new CountingResponseCopier(); + using var invokable = CreateInvokable(methodName); + invokable.SetTarget(new TargetHolder(target)); + using var response = await Assert.IsAssignableFrom(invokable).InvokeAndCopy( + provider, contexts, new DeepCopier(compatibility, contexts)); + + Assert.IsAssignableFrom(response); + Assert.Equal(0, compatibility.Copies); + Assert.Equal(resultType, response.GetSimpleResultType()); + Assert.True(provider.TryGetRawResponseReader(resultType, out var registered)); + var buffer = new ArrayBufferWriter(); + using (var session = services.GetRequiredService().GetSession()) + { + var writer = Writer.Create(buffer, session); + ((IRawResponseWriter)response).WriteRaw(ref writer); + writer.Commit(); + } + using var readerSession = services.GetRequiredService().GetSession(); + var reader = Reader.Create(buffer.WrittenMemory, readerSession); + var field = reader.ReadFieldHeader(); + using var decoded = registered!.ReadRaw(ref reader, ref field); + Assert.IsAssignableFrom(decoded); + if (methodName == "Payload") + { + var value = decoded.GetResult(); + Assert.NotNull(value); + Assert.NotSame(target.Result, response.GetResult()); + Assert.NotSame(target.Result, value); + Assert.Equal(17, value.Value); + } + else if (methodName == "Boolean") + Assert.True(decoded.GetResult()); + else + Assert.Equal(42, decoded.GetResult()); + } + [Fact] public async Task GeneratedResponseHolderPreservesRawWireBytesAndPoolReset() { From c26bb1610b00acb48efd43d0007b93c998ed3b58 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Fri, 2 Oct 2026 12:54:28 -0700 Subject: [PATCH 18/54] fix(serialization): use matching metadata for default eligibility --- .../Serializers/CodecProvider.cs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/Orleans.Serialization/Serializers/CodecProvider.cs b/src/Orleans.Serialization/Serializers/CodecProvider.cs index a9479450231..1bf9900b001 100644 --- a/src/Orleans.Serialization/Serializers/CodecProvider.cs +++ b/src/Orleans.Serialization/Serializers/CodecProvider.cs @@ -683,15 +683,8 @@ private bool IsDefaultContractEligible(TypeManifestOptions.DefaultSerializerCont if (!_manifest.IsDefaultSerializerService(contract.Service) || !visited.Add(contract.Service)) return true; var role = contract.Service.IsConstructedGenericType ? contract.Service.GetGenericTypeDefinition() : null; var target = role is null ? contract.Service : contract.Service.GenericTypeArguments[0]; - var implementations = role == typeof(IFieldCodec<>) ? _fieldCodecs - : role == typeof(IDeepCopier<>) ? _copiers - : role == typeof(IBaseCodec<>) ? _baseCodecs - : role == typeof(IValueSerializer<>) ? _valueSerializers - : role == typeof(IBaseCopier<>) ? _baseCopiers - : role == typeof(IActivator<>) ? _activators - : null; - if (implementations is not null && (implementations.TryGetValue(target, out var selected) - || target.IsConstructedGenericType && implementations.TryGetValue(target.GetGenericTypeDefinition(), out selected)) + if (role is not null + && TrySelectImplementation(role, target, target.IsConstructedGenericType ? target.GetGenericTypeDefinition() : target, out var selected) && !MatchesDefaultImplementation(selected, contract.Implementation, contract.CompatibleImplementation, target)) return false; foreach (var dependency in contract.Dependencies) From 85181887163f5670885ab2e99bd5d8071bf53b0e Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Fri, 2 Oct 2026 12:57:44 -0700 Subject: [PATCH 19/54] test(codegen): refresh canonical default contract snapshots --- ...ests.TestBasicGrain.DotNet10_0.verified.cs | 18 ++--- ...Tests.TestBasicGrain.DotNet8_0.verified.cs | 18 ++--- ...rializersAnnotation.DotNet10_0.verified.cs | 10 ++- ...erializersAnnotation.DotNet8_0.verified.cs | 10 ++- ...stGrainComplexGrain.DotNet10_0.verified.cs | 30 ++++---- ...estGrainComplexGrain.DotNet8_0.verified.cs | 30 ++++---- ...thInvokableBaseType.DotNet10_0.verified.cs | 18 ++--- ...ithInvokableBaseType.DotNet8_0.verified.cs | 18 ++--- ...WithResponseTimeout.DotNet10_0.verified.cs | 10 ++- ...dWithResponseTimeout.DotNet8_0.verified.cs | 10 ++- ...thDifferentKeyTypes.DotNet10_0.verified.cs | 68 ++++++++++--------- ...ithDifferentKeyTypes.DotNet8_0.verified.cs | 68 ++++++++++--------- ...hMultipleInterfaces.DotNet10_0.verified.cs | 14 ++-- ...thMultipleInterfaces.DotNet8_0.verified.cs | 14 ++-- 14 files changed, 170 insertions(+), 166 deletions(-) diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs index 7e52eb185a1..f1275a2fa92 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs @@ -273,15 +273,13 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); #if NET5_0_OR_GREATER - if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) - return; options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(string)); options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); @@ -481,14 +479,16 @@ internal sealed class Metadata_TestProject : global::Orleans.Serialization.Confi { protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) { - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IBasicGrain_GrainReference_6B0E24A1)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_BasicGrain)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IBasicGrain_GrainReference_6B0E24A1)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_BasicGrain)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IBasicGrain_GrainReference_6B0E24A1), typeof(OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_BasicGrain), typeof(global::TestProject.BasicGrain)); + config.AddBaseCodec(typeof(OrleansCodeGen.TestProject.Codec_BasicGrain), typeof(global::TestProject.BasicGrain)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IBasicGrain_GrainReference_6B0E24A1), typeof(OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_BasicGrain), typeof(global::TestProject.BasicGrain)); + config.AddBaseCopier(typeof(OrleansCodeGen.TestProject.Copier_BasicGrain), typeof(global::TestProject.BasicGrain)); config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IBasicGrain)); config.AddInterface(typeof(global::TestProject.IBasicGrain)); config.AddInterfaceImplementation(typeof(global::TestProject.BasicGrain)); - config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_BasicGrain)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_BasicGrain), typeof(global::TestProject.BasicGrain)); var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); var n2 = n1.GetOrAdd(typeof(global::Orleans.Runtime.GrainReference)); var n3 = n2.GetOrAdd(typeof(global::TestProject.IBasicGrain)); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs index 53ca71858b9..a975cb79779 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs @@ -273,15 +273,13 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); #if NET5_0_OR_GREATER - if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) - return; options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(string)); options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); @@ -482,14 +480,16 @@ internal sealed class Metadata_TestProject : global::Orleans.Serialization.Confi { protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) { - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IBasicGrain_GrainReference_6B0E24A1)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_BasicGrain)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IBasicGrain_GrainReference_6B0E24A1)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_BasicGrain)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IBasicGrain_GrainReference_6B0E24A1), typeof(OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_BasicGrain), typeof(global::TestProject.BasicGrain)); + config.AddBaseCodec(typeof(OrleansCodeGen.TestProject.Codec_BasicGrain), typeof(global::TestProject.BasicGrain)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IBasicGrain_GrainReference_6B0E24A1), typeof(OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_BasicGrain), typeof(global::TestProject.BasicGrain)); + config.AddBaseCopier(typeof(OrleansCodeGen.TestProject.Copier_BasicGrain), typeof(global::TestProject.BasicGrain)); config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IBasicGrain)); config.AddInterface(typeof(global::TestProject.IBasicGrain)); config.AddInterfaceImplementation(typeof(global::TestProject.BasicGrain)); - config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_BasicGrain)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_BasicGrain), typeof(global::TestProject.BasicGrain)); var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); var n2 = n1.GetOrAdd(typeof(global::Orleans.Runtime.GrainReference)); var n3 = n2.GetOrAdd(typeof(global::TestProject.IBasicGrain)); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs index c1d78c47d42..53da8c75257 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs @@ -179,15 +179,13 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); #if NET5_0_OR_GREATER - if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) - return; options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(string)); options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); @@ -387,8 +385,8 @@ internal sealed class Metadata_TestProject : global::Orleans.Serialization.Confi { protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) { - config.AddSerializer(typeof(OrleansCodeGen.Codec_Invokable_IMyGrain_GrainReference_6D39E404)); - config.AddCopier(typeof(OrleansCodeGen.Copier_Invokable_IMyGrain_GrainReference_6D39E404)); + config.AddSerializer(typeof(OrleansCodeGen.Codec_Invokable_IMyGrain_GrainReference_6D39E404), typeof(OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404)); + config.AddCopier(typeof(OrleansCodeGen.Copier_Invokable_IMyGrain_GrainReference_6D39E404), typeof(OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404)); config.AddInterfaceProxy(typeof(OrleansCodeGen.Proxy_IMyGrain)); config.AddInterface(typeof(global::IMyGrain)); var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs index 1df7ce87fea..e58edd13cac 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs @@ -179,15 +179,13 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); #if NET5_0_OR_GREATER - if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) - return; options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(string)); options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); @@ -388,8 +386,8 @@ internal sealed class Metadata_TestProject : global::Orleans.Serialization.Confi { protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) { - config.AddSerializer(typeof(OrleansCodeGen.Codec_Invokable_IMyGrain_GrainReference_6D39E404)); - config.AddCopier(typeof(OrleansCodeGen.Copier_Invokable_IMyGrain_GrainReference_6D39E404)); + config.AddSerializer(typeof(OrleansCodeGen.Codec_Invokable_IMyGrain_GrainReference_6D39E404), typeof(OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404)); + config.AddCopier(typeof(OrleansCodeGen.Copier_Invokable_IMyGrain_GrainReference_6D39E404), typeof(OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404)); config.AddInterfaceProxy(typeof(OrleansCodeGen.Proxy_IMyGrain)); config.AddInterface(typeof(global::IMyGrain)); var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs index d0354a36b1e..69c715c2b61 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs @@ -469,23 +469,21 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializer(static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider), static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider)); #if NET5_0_OR_GREATER - if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) - return; options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Codec_ComplexData()); options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Copier_ComplexData()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::TestProject.ComplexData)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.Int32Codec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(int)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(string)); options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); @@ -680,17 +678,21 @@ internal sealed class Metadata_TestProject : global::Orleans.Serialization.Confi { protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) { - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_ComplexData)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IComplexGrain_GrainReference_67FE5808)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_ComplexGrain)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_ComplexData)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IComplexGrain_GrainReference_67FE5808)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_ComplexGrain)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_ComplexData), typeof(global::TestProject.ComplexData)); + config.AddBaseCodec(typeof(OrleansCodeGen.TestProject.Codec_ComplexData), typeof(global::TestProject.ComplexData)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IComplexGrain_GrainReference_67FE5808), typeof(OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_ComplexGrain), typeof(global::TestProject.ComplexGrain)); + config.AddBaseCodec(typeof(OrleansCodeGen.TestProject.Codec_ComplexGrain), typeof(global::TestProject.ComplexGrain)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_ComplexData), typeof(global::TestProject.ComplexData)); + config.AddBaseCopier(typeof(OrleansCodeGen.TestProject.Copier_ComplexData), typeof(global::TestProject.ComplexData)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IComplexGrain_GrainReference_67FE5808), typeof(OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_ComplexGrain), typeof(global::TestProject.ComplexGrain)); + config.AddBaseCopier(typeof(OrleansCodeGen.TestProject.Copier_ComplexGrain), typeof(global::TestProject.ComplexGrain)); config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IComplexGrain)); config.AddInterface(typeof(global::TestProject.IComplexGrain)); config.AddInterfaceImplementation(typeof(global::TestProject.ComplexGrain)); - config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_ComplexData)); - config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_ComplexGrain)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_ComplexData), typeof(global::TestProject.ComplexData)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_ComplexGrain), typeof(global::TestProject.ComplexGrain)); var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); var n2 = n1.GetOrAdd(typeof(global::Orleans.Runtime.GrainReference)); var n3 = n2.GetOrAdd(typeof(global::TestProject.IComplexGrain)); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs index dd7dac19858..539269c73a8 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs @@ -468,23 +468,21 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializer(static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider), static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider)); #if NET5_0_OR_GREATER - if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) - return; options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Codec_ComplexData()); options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Copier_ComplexData()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::TestProject.ComplexData)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.Int32Codec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(int)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(string)); options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); @@ -680,17 +678,21 @@ internal sealed class Metadata_TestProject : global::Orleans.Serialization.Confi { protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) { - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_ComplexData)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IComplexGrain_GrainReference_67FE5808)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_ComplexGrain)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_ComplexData)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IComplexGrain_GrainReference_67FE5808)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_ComplexGrain)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_ComplexData), typeof(global::TestProject.ComplexData)); + config.AddBaseCodec(typeof(OrleansCodeGen.TestProject.Codec_ComplexData), typeof(global::TestProject.ComplexData)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IComplexGrain_GrainReference_67FE5808), typeof(OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_ComplexGrain), typeof(global::TestProject.ComplexGrain)); + config.AddBaseCodec(typeof(OrleansCodeGen.TestProject.Codec_ComplexGrain), typeof(global::TestProject.ComplexGrain)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_ComplexData), typeof(global::TestProject.ComplexData)); + config.AddBaseCopier(typeof(OrleansCodeGen.TestProject.Copier_ComplexData), typeof(global::TestProject.ComplexData)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IComplexGrain_GrainReference_67FE5808), typeof(OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_ComplexGrain), typeof(global::TestProject.ComplexGrain)); + config.AddBaseCopier(typeof(OrleansCodeGen.TestProject.Copier_ComplexGrain), typeof(global::TestProject.ComplexGrain)); config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IComplexGrain)); config.AddInterface(typeof(global::TestProject.IComplexGrain)); config.AddInterfaceImplementation(typeof(global::TestProject.ComplexGrain)); - config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_ComplexData)); - config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_ComplexGrain)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_ComplexData), typeof(global::TestProject.ComplexData)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_ComplexGrain), typeof(global::TestProject.ComplexGrain)); var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); var n2 = n1.GetOrAdd(typeof(global::Orleans.Runtime.GrainReference)); var n3 = n2.GetOrAdd(typeof(global::TestProject.IComplexGrain)); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs index c82c7c5e7ed..a81eaad18bb 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs @@ -278,15 +278,13 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); #if NET5_0_OR_GREATER - if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) - return; options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(string)); options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); @@ -486,14 +484,16 @@ internal sealed class Metadata_TestProject : global::Orleans.Serialization.Confi { protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) { - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IHelloGrain_GrainReference_5336307F)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_HelloGrain)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IHelloGrain_GrainReference_5336307F)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_HelloGrain)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IHelloGrain_GrainReference_5336307F), typeof(OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_HelloGrain), typeof(global::TestProject.HelloGrain)); + config.AddBaseCodec(typeof(OrleansCodeGen.TestProject.Codec_HelloGrain), typeof(global::TestProject.HelloGrain)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IHelloGrain_GrainReference_5336307F), typeof(OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_HelloGrain), typeof(global::TestProject.HelloGrain)); + config.AddBaseCopier(typeof(OrleansCodeGen.TestProject.Copier_HelloGrain), typeof(global::TestProject.HelloGrain)); config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IHelloGrain)); config.AddInterface(typeof(global::TestProject.IHelloGrain)); config.AddInterfaceImplementation(typeof(global::TestProject.HelloGrain)); - config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_HelloGrain)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_HelloGrain), typeof(global::TestProject.HelloGrain)); var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); var n2 = n1.GetOrAdd(typeof(global::Orleans.Runtime.GrainReference)); var n3 = n2.GetOrAdd(typeof(global::TestProject.IHelloGrain)); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs index 1ad0819ecc4..f7ab967c035 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs @@ -278,15 +278,13 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); #if NET5_0_OR_GREATER - if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) - return; options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(string)); options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); @@ -487,14 +485,16 @@ internal sealed class Metadata_TestProject : global::Orleans.Serialization.Confi { protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) { - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IHelloGrain_GrainReference_5336307F)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_HelloGrain)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IHelloGrain_GrainReference_5336307F)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_HelloGrain)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IHelloGrain_GrainReference_5336307F), typeof(OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_HelloGrain), typeof(global::TestProject.HelloGrain)); + config.AddBaseCodec(typeof(OrleansCodeGen.TestProject.Codec_HelloGrain), typeof(global::TestProject.HelloGrain)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IHelloGrain_GrainReference_5336307F), typeof(OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_HelloGrain), typeof(global::TestProject.HelloGrain)); + config.AddBaseCopier(typeof(OrleansCodeGen.TestProject.Copier_HelloGrain), typeof(global::TestProject.HelloGrain)); config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IHelloGrain)); config.AddInterface(typeof(global::TestProject.IHelloGrain)); config.AddInterfaceImplementation(typeof(global::TestProject.HelloGrain)); - config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_HelloGrain)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_HelloGrain), typeof(global::TestProject.HelloGrain)); var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); var n2 = n1.GetOrAdd(typeof(global::Orleans.Runtime.GrainReference)); var n3 = n2.GetOrAdd(typeof(global::TestProject.IHelloGrain)); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs index a88dcc50ab8..82dc68f8b35 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs @@ -178,15 +178,13 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); #if NET5_0_OR_GREATER - if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) - return; options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(string)); options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); @@ -386,8 +384,8 @@ internal sealed class Metadata_TestProject : global::Orleans.Serialization.Confi { protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) { - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8), typeof(OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8), typeof(OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8)); config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IResponseTimeoutGrain)); config.AddInterface(typeof(global::TestProject.IResponseTimeoutGrain)); config.AddInterfaceImplementation(typeof(global::TestProject.ResponseTimeoutGrain)); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs index 94f2edadeaa..b257f7b84f2 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs @@ -178,15 +178,13 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); #if NET5_0_OR_GREATER - if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) - return; options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(string)); options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); @@ -387,8 +385,8 @@ internal sealed class Metadata_TestProject : global::Orleans.Serialization.Confi { protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) { - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8), typeof(OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8), typeof(OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8)); config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IResponseTimeoutGrain)); config.AddInterface(typeof(global::TestProject.IResponseTimeoutGrain)); config.AddInterfaceImplementation(typeof(global::TestProject.ResponseTimeoutGrain)); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs index ffb287d2631..7e579a08384 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs @@ -857,43 +857,41 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); #if NET5_0_OR_GREATER - if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) - return; options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider)); + options.AddDefaultSerializer>, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>, global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec>) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier>) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response>)); options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider)); + options.AddDefaultSerializer>, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>, global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec>) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier>) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response>)); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.GuidCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(global::System.Guid)); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddDefaultSerializer, global::Orleans.Serialization.Codecs.TupleCodec, global::Orleans.Serialization.Codecs.TupleCopier>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::System.Tuple)); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddDefaultSerializer, global::Orleans.Serialization.Codecs.TupleCodec, global::Orleans.Serialization.Codecs.TupleCopier>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::System.Tuple)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.Int64Codec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(long)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(string)); options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); @@ -1513,22 +1511,30 @@ internal sealed class Metadata_TestProject : global::Orleans.Serialization.Confi { protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) { - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_GrainWithGuidKey)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IMyGrainWithStringKey_GrainReference_43570316)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_GrainWithStringKey)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_GrainWithGuidCompoundKey)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_GrainWithIntegerCompoundKey)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithGuidKey)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IMyGrainWithStringKey_GrainReference_43570316)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithStringKey)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithGuidCompoundKey)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithIntegerCompoundKey)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E), typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_GrainWithGuidKey), typeof(global::TestProject.GrainWithGuidKey)); + config.AddBaseCodec(typeof(OrleansCodeGen.TestProject.Codec_GrainWithGuidKey), typeof(global::TestProject.GrainWithGuidKey)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IMyGrainWithStringKey_GrainReference_43570316), typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_GrainWithStringKey), typeof(global::TestProject.GrainWithStringKey)); + config.AddBaseCodec(typeof(OrleansCodeGen.TestProject.Codec_GrainWithStringKey), typeof(global::TestProject.GrainWithStringKey)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF), typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_GrainWithGuidCompoundKey), typeof(global::TestProject.GrainWithGuidCompoundKey)); + config.AddBaseCodec(typeof(OrleansCodeGen.TestProject.Codec_GrainWithGuidCompoundKey), typeof(global::TestProject.GrainWithGuidCompoundKey)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A), typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_GrainWithIntegerCompoundKey), typeof(global::TestProject.GrainWithIntegerCompoundKey)); + config.AddBaseCodec(typeof(OrleansCodeGen.TestProject.Codec_GrainWithIntegerCompoundKey), typeof(global::TestProject.GrainWithIntegerCompoundKey)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E), typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithGuidKey), typeof(global::TestProject.GrainWithGuidKey)); + config.AddBaseCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithGuidKey), typeof(global::TestProject.GrainWithGuidKey)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IMyGrainWithStringKey_GrainReference_43570316), typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithStringKey), typeof(global::TestProject.GrainWithStringKey)); + config.AddBaseCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithStringKey), typeof(global::TestProject.GrainWithStringKey)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF), typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithGuidCompoundKey), typeof(global::TestProject.GrainWithGuidCompoundKey)); + config.AddBaseCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithGuidCompoundKey), typeof(global::TestProject.GrainWithGuidCompoundKey)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A), typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithIntegerCompoundKey), typeof(global::TestProject.GrainWithIntegerCompoundKey)); + config.AddBaseCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithIntegerCompoundKey), typeof(global::TestProject.GrainWithIntegerCompoundKey)); config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IMyGrainWithGuidKey)); config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IMyGrainWithStringKey)); config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IMyGrainWithGuidCompoundKey)); @@ -1541,10 +1547,10 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati config.AddInterfaceImplementation(typeof(global::TestProject.GrainWithStringKey)); config.AddInterfaceImplementation(typeof(global::TestProject.GrainWithGuidCompoundKey)); config.AddInterfaceImplementation(typeof(global::TestProject.GrainWithIntegerCompoundKey)); - config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_GrainWithGuidKey)); - config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_GrainWithStringKey)); - config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_GrainWithGuidCompoundKey)); - config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_GrainWithIntegerCompoundKey)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_GrainWithGuidKey), typeof(global::TestProject.GrainWithGuidKey)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_GrainWithStringKey), typeof(global::TestProject.GrainWithStringKey)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_GrainWithGuidCompoundKey), typeof(global::TestProject.GrainWithGuidCompoundKey)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_GrainWithIntegerCompoundKey), typeof(global::TestProject.GrainWithIntegerCompoundKey)); var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); var n2 = n1.GetOrAdd(typeof(global::Orleans.Runtime.GrainReference)); var n3 = n2.GetOrAdd(typeof(global::TestProject.IMyGrainWithGuidKey)); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs index b5f05540147..bfa640ffb6f 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs @@ -857,43 +857,41 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); #if NET5_0_OR_GREATER - if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) - return; options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider)); + options.AddDefaultSerializer>, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>, global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec>) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier>) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response>)); options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider)); + options.AddDefaultSerializer>, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>, global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec>) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier>) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response>)); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.GuidCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(global::System.Guid)); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddDefaultSerializer, global::Orleans.Serialization.Codecs.TupleCodec, global::Orleans.Serialization.Codecs.TupleCopier>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::System.Tuple)); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddDefaultSerializer, global::Orleans.Serialization.Codecs.TupleCodec, global::Orleans.Serialization.Codecs.TupleCopier>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::System.Tuple)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.Int64Codec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(long)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(string)); options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); @@ -1517,22 +1515,30 @@ internal sealed class Metadata_TestProject : global::Orleans.Serialization.Confi { protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) { - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_GrainWithGuidKey)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IMyGrainWithStringKey_GrainReference_43570316)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_GrainWithStringKey)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_GrainWithGuidCompoundKey)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_GrainWithIntegerCompoundKey)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithGuidKey)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IMyGrainWithStringKey_GrainReference_43570316)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithStringKey)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithGuidCompoundKey)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithIntegerCompoundKey)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E), typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_GrainWithGuidKey), typeof(global::TestProject.GrainWithGuidKey)); + config.AddBaseCodec(typeof(OrleansCodeGen.TestProject.Codec_GrainWithGuidKey), typeof(global::TestProject.GrainWithGuidKey)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IMyGrainWithStringKey_GrainReference_43570316), typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_GrainWithStringKey), typeof(global::TestProject.GrainWithStringKey)); + config.AddBaseCodec(typeof(OrleansCodeGen.TestProject.Codec_GrainWithStringKey), typeof(global::TestProject.GrainWithStringKey)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF), typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_GrainWithGuidCompoundKey), typeof(global::TestProject.GrainWithGuidCompoundKey)); + config.AddBaseCodec(typeof(OrleansCodeGen.TestProject.Codec_GrainWithGuidCompoundKey), typeof(global::TestProject.GrainWithGuidCompoundKey)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A), typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_GrainWithIntegerCompoundKey), typeof(global::TestProject.GrainWithIntegerCompoundKey)); + config.AddBaseCodec(typeof(OrleansCodeGen.TestProject.Codec_GrainWithIntegerCompoundKey), typeof(global::TestProject.GrainWithIntegerCompoundKey)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E), typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithGuidKey), typeof(global::TestProject.GrainWithGuidKey)); + config.AddBaseCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithGuidKey), typeof(global::TestProject.GrainWithGuidKey)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IMyGrainWithStringKey_GrainReference_43570316), typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithStringKey), typeof(global::TestProject.GrainWithStringKey)); + config.AddBaseCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithStringKey), typeof(global::TestProject.GrainWithStringKey)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF), typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithGuidCompoundKey), typeof(global::TestProject.GrainWithGuidCompoundKey)); + config.AddBaseCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithGuidCompoundKey), typeof(global::TestProject.GrainWithGuidCompoundKey)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A), typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithIntegerCompoundKey), typeof(global::TestProject.GrainWithIntegerCompoundKey)); + config.AddBaseCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithIntegerCompoundKey), typeof(global::TestProject.GrainWithIntegerCompoundKey)); config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IMyGrainWithGuidKey)); config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IMyGrainWithStringKey)); config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IMyGrainWithGuidCompoundKey)); @@ -1545,10 +1551,10 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati config.AddInterfaceImplementation(typeof(global::TestProject.GrainWithStringKey)); config.AddInterfaceImplementation(typeof(global::TestProject.GrainWithGuidCompoundKey)); config.AddInterfaceImplementation(typeof(global::TestProject.GrainWithIntegerCompoundKey)); - config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_GrainWithGuidKey)); - config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_GrainWithStringKey)); - config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_GrainWithGuidCompoundKey)); - config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_GrainWithIntegerCompoundKey)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_GrainWithGuidKey), typeof(global::TestProject.GrainWithGuidKey)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_GrainWithStringKey), typeof(global::TestProject.GrainWithStringKey)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_GrainWithGuidCompoundKey), typeof(global::TestProject.GrainWithGuidCompoundKey)); + config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_GrainWithIntegerCompoundKey), typeof(global::TestProject.GrainWithIntegerCompoundKey)); var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); var n2 = n1.GetOrAdd(typeof(global::Orleans.Runtime.GrainReference)); var n3 = n2.GetOrAdd(typeof(global::TestProject.IMyGrainWithGuidKey)); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs index c601281d9ee..574ef5f2d1a 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs @@ -332,15 +332,13 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); #if NET5_0_OR_GREATER - if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) - return; options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(string)); options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); @@ -540,10 +538,10 @@ internal sealed class Metadata_TestProject : global::Orleans.Serialization.Confi { protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) { - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IGrainA_GrainReference_11405B98)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IGrainB_GrainReference_6B5D7809)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IGrainA_GrainReference_11405B98)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IGrainB_GrainReference_6B5D7809)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IGrainA_GrainReference_11405B98), typeof(OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IGrainB_GrainReference_6B5D7809), typeof(OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IGrainA_GrainReference_11405B98), typeof(OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IGrainB_GrainReference_6B5D7809), typeof(OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809)); config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IGrainA)); config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IGrainB)); config.AddInterface(typeof(global::TestProject.IGrainA)); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs index 91ce58e8d1c..083dd009f16 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs @@ -332,15 +332,13 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); #if NET5_0_OR_GREATER - if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) - return; options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); + options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(string)); options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); @@ -541,10 +539,10 @@ internal sealed class Metadata_TestProject : global::Orleans.Serialization.Confi { protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) { - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IGrainA_GrainReference_11405B98)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IGrainB_GrainReference_6B5D7809)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IGrainA_GrainReference_11405B98)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IGrainB_GrainReference_6B5D7809)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IGrainA_GrainReference_11405B98), typeof(OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98)); + config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IGrainB_GrainReference_6B5D7809), typeof(OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IGrainA_GrainReference_11405B98), typeof(OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98)); + config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IGrainB_GrainReference_6B5D7809), typeof(OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809)); config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IGrainA)); config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IGrainB)); config.AddInterface(typeof(global::TestProject.IGrainA)); From 07c5d15db00912cfa64a61eb0cb75df9840f5024 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Fri, 2 Oct 2026 12:37:49 -0700 Subject: [PATCH 20/54] fix(codegen): remove generated field-accessor markers --- .../RpcResponseHolderGenerator.cs | 2 +- src/api/Orleans.Runtime/Orleans.Runtime.cs | 15 --------------- ...ansSourceGeneratorTests.TestAlias.verified.cs | 1 - ...urceGeneratorTests.TestBasicClass.verified.cs | 2 -- ...TestBasicClassWithAnnotatedFields.verified.cs | 2 -- ...ClassWithDifferentAccessModifiers.verified.cs | 4 ---- ...sts.TestBasicClassWithInheritance.verified.cs | 4 ---- ...ts.TestBasicClassWithoutNamespace.verified.cs | 2 -- ...orTests.TestBasicGrain.DotNet10_0.verified.cs | 4 ---- ...torTests.TestBasicGrain.DotNet8_0.verified.cs | 4 ---- ...urceGeneratorTests.TestBasicGrain.verified.cs | 4 ---- ...rceGeneratorTests.TestBasicStruct.verified.cs | 1 - ...neratorTests.TestClassNestedTypes.verified.cs | 2 -- ...atorTests.TestClassPrimitiveTypes.verified.cs | 2 -- ...tClassPrimitiveTypesUsingFullName.verified.cs | 2 -- ...ests.TestClassReferenceProperties.verified.cs | 2 -- ...dSerializersAnnotation.DotNet10_0.verified.cs | 2 -- ...odSerializersAnnotation.DotNet8_0.verified.cs | 2 -- ...nerateMethodSerializersAnnotation.verified.cs | 2 -- ...sWithGenerateSerializerAnnotation.verified.cs | 3 --- ...WithInterfaceConstructorParameter.verified.cs | 2 -- ...TestClassWithNoPublicConstructors.verified.cs | 2 -- ...WithOptionalConstructorParameters.verified.cs | 2 -- ...ClassWithParameterizedConstructor.verified.cs | 4 ---- ...tedActivatorConstructorAnnotation.verified.cs | 2 -- ...eratorTests.TestCompoundTypeAlias.verified.cs | 4 ---- ...ceGeneratorTests.TestGenericClass.verified.cs | 4 ---- ...nstructorParameters.FieldAccessor.verified.cs | 4 ---- ...structorParameters.UnsafeAccessor.verified.cs | 4 ---- ....TestGrainComplexGrain.DotNet10_0.verified.cs | 6 ------ ...s.TestGrainComplexGrain.DotNet8_0.verified.cs | 6 ------ ...eratorTests.TestGrainComplexGrain.verified.cs | 6 ------ ...dWithInvokableBaseType.DotNet10_0.verified.cs | 4 ---- ...edWithInvokableBaseType.DotNet8_0.verified.cs | 4 ---- ...hodAnnotatedWithInvokableBaseType.verified.cs | 4 ---- ...tedWithResponseTimeout.DotNet10_0.verified.cs | 2 -- ...atedWithResponseTimeout.DotNet8_0.verified.cs | 2 -- ...ethodAnnotatedWithResponseTimeout.verified.cs | 2 -- ...nWithDifferentKeyTypes.DotNet10_0.verified.cs | 16 ---------------- ...inWithDifferentKeyTypes.DotNet8_0.verified.cs | 16 ---------------- ...ts.TestGrainWithDifferentKeyTypes.verified.cs | 16 ---------------- ...WithMultipleInterfaces.DotNet10_0.verified.cs | 4 ---- ...nWithMultipleInterfaces.DotNet8_0.verified.cs | 4 ---- ...s.TestGrainWithMultipleInterfaces.verified.cs | 4 ---- ...sSourceGeneratorTests.TestRecords.verified.cs | 5 ----- ...tRecordsWithParameterIdAttributes.verified.cs | 5 ----- ...OmitDefaultMemberValuesAnnotation.verified.cs | 2 -- ...uppressReferenceTrackingAttribute.verified.cs | 2 -- 48 files changed, 1 insertion(+), 199 deletions(-) diff --git a/src/Orleans.CodeGenerator/RpcResponseHolderGenerator.cs b/src/Orleans.CodeGenerator/RpcResponseHolderGenerator.cs index 5a7c9f27d77..4b6f6530db7 100644 --- a/src/Orleans.CodeGenerator/RpcResponseHolderGenerator.cs +++ b/src/Orleans.CodeGenerator/RpcResponseHolderGenerator.cs @@ -35,7 +35,7 @@ internal static bool TryDescribe(IGeneratorServices services, ITypeSymbol result if (!SymbolEqualityComparer.Default.Equals(named.ContainingAssembly, services.Compilation.Assembly)) { var codecType = services.Compilation.GetTypeByMetadataName($"{SerializerGenerator.GetGeneratedNamespaceName(named)}.{SerializerGenerator.GetSimpleClassName(named.Name)}"); - if (codecType is null || ReferencedSerializerImplementation.Validate(codecType) is not null) + if (codecType is null) return false; } codec = registration.Codec; diff --git a/src/api/Orleans.Runtime/Orleans.Runtime.cs b/src/api/Orleans.Runtime/Orleans.Runtime.cs index 10da216e275..edaf0437875 100644 --- a/src/api/Orleans.Runtime/Orleans.Runtime.cs +++ b/src/api/Orleans.Runtime/Orleans.Runtime.cs @@ -1486,7 +1486,6 @@ namespace OrleansCodeGen.Orleans.LeaseProviders [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [System.ComponentModel.Description("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed partial class Codec_Invokable_ILeaseProvider_GrainReference_5C7B2877 : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Codecs.IFieldCodec { public Codec_Invokable_ILeaseProvider_GrainReference_5C7B2877(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) { } @@ -1505,7 +1504,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [System.ComponentModel.Description("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed partial class Codec_Invokable_ILeaseProvider_GrainReference_ACF8E0DD : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Codecs.IFieldCodec { public Codec_Invokable_ILeaseProvider_GrainReference_ACF8E0DD(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) { } @@ -1524,7 +1522,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [System.ComponentModel.Description("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed partial class Codec_Invokable_ILeaseProvider_GrainReference_F2BF11D0 : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Codecs.IFieldCodec { public Codec_Invokable_ILeaseProvider_GrainReference_F2BF11D0(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) { } @@ -1543,7 +1540,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [System.ComponentModel.Description("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed partial class Copier_Invokable_ILeaseProvider_GrainReference_5C7B2877 : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IDeepCopier { public Copier_Invokable_ILeaseProvider_GrainReference_5C7B2877(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) { } @@ -1554,7 +1550,6 @@ public Copier_Invokable_ILeaseProvider_GrainReference_5C7B2877(global::Orleans.S [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [System.ComponentModel.Description("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed partial class Copier_Invokable_ILeaseProvider_GrainReference_ACF8E0DD : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IDeepCopier { public Copier_Invokable_ILeaseProvider_GrainReference_ACF8E0DD(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) { } @@ -1565,7 +1560,6 @@ public Copier_Invokable_ILeaseProvider_GrainReference_ACF8E0DD(global::Orleans.S [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [System.ComponentModel.Description("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed partial class Copier_Invokable_ILeaseProvider_GrainReference_F2BF11D0 : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IDeepCopier { public Copier_Invokable_ILeaseProvider_GrainReference_F2BF11D0(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) { } @@ -1678,7 +1672,6 @@ namespace OrleansCodeGen.Orleans.Runtime [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [System.ComponentModel.Description("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed partial class Codec_ClusterMember : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Codecs.IFieldCodec { public Codec_ClusterMember(global::Orleans.Serialization.Activators.IActivator _activator, global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) { } @@ -1697,7 +1690,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [System.ComponentModel.Description("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed partial class Codec_ClusterMembershipSnapshot : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Codecs.IFieldCodec { public Codec_ClusterMembershipSnapshot(global::Orleans.Serialization.Activators.IActivator _activator, global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) { } @@ -1716,7 +1708,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [System.ComponentModel.Description("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed partial class Codec_ClusterMembershipUpdate : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Codecs.IFieldCodec { public Codec_ClusterMembershipUpdate(global::Orleans.Serialization.Activators.IActivator _activator, global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) { } @@ -1738,7 +1729,6 @@ namespace OrleansCodeGen.Orleans.Runtime.MembershipService [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [System.ComponentModel.Description("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed partial class Codec_OrleansClusterConnectivityCheckFailedException : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Codecs.IFieldCodec { public Codec_OrleansClusterConnectivityCheckFailedException(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) { } @@ -1757,7 +1747,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [System.ComponentModel.Description("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed partial class Codec_OrleansMissingMembershipEntryException : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Codecs.IFieldCodec { public Codec_OrleansMissingMembershipEntryException(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) { } @@ -1776,7 +1765,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [System.ComponentModel.Description("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed partial class Copier_OrleansClusterConnectivityCheckFailedException : global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.ExceptionCopier { public Copier_OrleansClusterConnectivityCheckFailedException(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) : base(default(Serialization.Serializers.ICodecProvider)!) { } @@ -1785,7 +1773,6 @@ public Copier_OrleansClusterConnectivityCheckFailedException(global::Orleans.Ser [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [System.ComponentModel.Description("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed partial class Copier_OrleansMissingMembershipEntryException : global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.ExceptionCopier { public Copier_OrleansMissingMembershipEntryException(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) : base(default(Serialization.Serializers.ICodecProvider)!) { } @@ -1797,7 +1784,6 @@ namespace OrleansCodeGen.Orleans.Runtime.MembershipService.SiloMetadata [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [System.ComponentModel.Description("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed partial class Codec_SiloMetadata : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec, global::Orleans.Serialization.Serializers.IBaseCodec { public Codec_SiloMetadata(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) { } @@ -1816,7 +1802,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - [System.ComponentModel.Description("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed partial class Copier_SiloMetadata : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier, global::Orleans.Serialization.Cloning.IBaseCopier { public void DeepCopy(global::Orleans.Runtime.MembershipService.SiloMetadata.SiloMetadata input, global::Orleans.Runtime.MembershipService.SiloMetadata.SiloMetadata output, global::Orleans.Serialization.Cloning.CopyContext context) { } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestAlias.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestAlias.verified.cs index 50873b581a6..8d745837d8a 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestAlias.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestAlias.verified.cs @@ -11,7 +11,6 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_MyTypeAliasStruct : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IValueSerializer { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.MyTypeAliasStruct); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClass.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClass.verified.cs index 3fc4b7e8f6b..34deeb5e3b7 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClass.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClass.verified.cs @@ -11,7 +11,6 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_DemoData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DemoData); @@ -80,7 +79,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_DemoData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithAnnotatedFields.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithAnnotatedFields.verified.cs index f90b5bce847..5fc7297b5d8 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithAnnotatedFields.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithAnnotatedFields.verified.cs @@ -11,7 +11,6 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_DemoDataWithFields : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DemoDataWithFields); @@ -100,7 +99,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_DemoDataWithFields : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Activators.IActivator _activator; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithDifferentAccessModifiers.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithDifferentAccessModifiers.verified.cs index edeff1eb256..e523ef25d63 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithDifferentAccessModifiers.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithDifferentAccessModifiers.verified.cs @@ -11,7 +11,6 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_PublicDemoData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.PublicDemoData); @@ -80,7 +79,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_PublicDemoData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -110,7 +108,6 @@ internal sealed class Activator_PublicDemoData : global::Orleans.Serialization.A } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] internal sealed class Codec_InternalDemoData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.InternalDemoData); @@ -179,7 +176,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] internal sealed class Copier_InternalDemoData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithInheritance.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithInheritance.verified.cs index 5cfc9ef7eaf..5b0ac2e2fa5 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithInheritance.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithInheritance.verified.cs @@ -11,7 +11,6 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_BaseData : global::Orleans.Serialization.Serializers.AbstractTypeSerializer { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -44,7 +43,6 @@ public override void Deserialize(ref global::Orleans.Serialization } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_BaseData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -61,7 +59,6 @@ public void DeepCopy(global::TestProject.BaseData input, global::TestProject.Bas } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_DerivedData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DerivedData); @@ -143,7 +140,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_DerivedData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly OrleansCodeGen.TestProject.Copier_BaseData _baseTypeCopier; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithoutNamespace.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithoutNamespace.verified.cs index fc1d4b3a34d..561bf0a11cc 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithoutNamespace.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithoutNamespace.verified.cs @@ -11,7 +11,6 @@ namespace OrleansCodeGen using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_DemoData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::DemoData); @@ -80,7 +79,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_DemoData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs index f1275a2fa92..d29c3c68f4b 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs @@ -90,7 +90,6 @@ public Proxy_IBasicGrain(global::Orleans.Runtime.GrainReferenceShared arg0, glob } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IBasicGrain_GrainReference_6B0E24A1 : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1); @@ -153,7 +152,6 @@ public OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1 } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IBasicGrain_GrainReference_6B0E24A1 : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -168,7 +166,6 @@ public OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1 } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_BasicGrain : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.BasicGrain); @@ -229,7 +226,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_BasicGrain : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs index a975cb79779..f4cb30c29f8 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs @@ -90,7 +90,6 @@ public Proxy_IBasicGrain(global::Orleans.Runtime.GrainReferenceShared arg0, glob } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IBasicGrain_GrainReference_6B0E24A1 : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1); @@ -153,7 +152,6 @@ public OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1 } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IBasicGrain_GrainReference_6B0E24A1 : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -168,7 +166,6 @@ public OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1 } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_BasicGrain : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.BasicGrain); @@ -229,7 +226,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_BasicGrain : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.verified.cs index 17591d516cc..4848ba692dc 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.verified.cs @@ -90,7 +90,6 @@ public Proxy_IBasicGrain(global::Orleans.Runtime.GrainReferenceShared arg0, glob } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IBasicGrain_GrainReference_6B0E24A1 : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1); @@ -153,7 +152,6 @@ public OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1 } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IBasicGrain_GrainReference_6B0E24A1 : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -168,7 +166,6 @@ public OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1 } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_BasicGrain : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.BasicGrain); @@ -229,7 +226,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_BasicGrain : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicStruct.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicStruct.verified.cs index 7303380754d..de13a21092e 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicStruct.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicStruct.verified.cs @@ -11,7 +11,6 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_DemoData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IValueSerializer { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DemoData); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassNestedTypes.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassNestedTypes.verified.cs index 8b57f9e37d3..3ac2cd83f0a 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassNestedTypes.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassNestedTypes.verified.cs @@ -11,7 +11,6 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_DemoData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DemoData); @@ -113,7 +112,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_DemoData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Cloning.IDeepCopier _copier_CyclicClass_AE634BDC96DD9410; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassPrimitiveTypes.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassPrimitiveTypes.verified.cs index b8dcb32febd..0e9a8cc8a8e 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassPrimitiveTypes.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassPrimitiveTypes.verified.cs @@ -11,7 +11,6 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_DemoData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DemoData); @@ -257,7 +256,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_DemoData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Codecs.ArrayCopier _copier_Int32_1_BD21C8B2FA9EFF52; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassPrimitiveTypesUsingFullName.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassPrimitiveTypesUsingFullName.verified.cs index b8dcb32febd..0e9a8cc8a8e 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassPrimitiveTypesUsingFullName.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassPrimitiveTypesUsingFullName.verified.cs @@ -11,7 +11,6 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_DemoData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DemoData); @@ -257,7 +256,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_DemoData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Codecs.ArrayCopier _copier_Int32_1_BD21C8B2FA9EFF52; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassReferenceProperties.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassReferenceProperties.verified.cs index f0871b68061..65bfc992332 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassReferenceProperties.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassReferenceProperties.verified.cs @@ -11,7 +11,6 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_DemoData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DemoData); @@ -118,7 +117,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_DemoData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Activators.IActivator _activator; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs index 53da8c75257..a6198d8f65a 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs @@ -90,7 +90,6 @@ public Proxy_IMyGrain(global::Orleans.Runtime.GrainReferenceShared arg0, global: } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IMyGrain_GrainReference_6D39E404 : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404); @@ -153,7 +152,6 @@ public OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404 ReadValue { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs index e58edd13cac..47a214ac251 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs @@ -90,7 +90,6 @@ public Proxy_IMyGrain(global::Orleans.Runtime.GrainReferenceShared arg0, global: } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IMyGrain_GrainReference_6D39E404 : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404); @@ -153,7 +152,6 @@ public OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404 ReadValue { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.verified.cs index 59569672718..e23ddea832f 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.verified.cs @@ -90,7 +90,6 @@ public Proxy_IMyGrain(global::Orleans.Runtime.GrainReferenceShared arg0, global: } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IMyGrain_GrainReference_6D39E404 : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404); @@ -153,7 +152,6 @@ public OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404 ReadValue { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateSerializerAnnotation.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateSerializerAnnotation.verified.cs index af94f99b8cd..24edc2fab33 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateSerializerAnnotation.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateSerializerAnnotation.verified.cs @@ -11,7 +11,6 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_MyCustomEnum : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.MyCustomEnum); @@ -30,7 +29,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_ClassWithImplicitFieldIds : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.ClassWithImplicitFieldIds); @@ -118,7 +116,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_ClassWithImplicitFieldIds : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithInterfaceConstructorParameter.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithInterfaceConstructorParameter.verified.cs index 7e9effa496a..172cf1f1c63 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithInterfaceConstructorParameter.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithInterfaceConstructorParameter.verified.cs @@ -11,7 +11,6 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_InterfaceCtorParam : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.InterfaceCtorParam); @@ -91,7 +90,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_InterfaceCtorParam : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Activators.IActivator _activator; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithNoPublicConstructors.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithNoPublicConstructors.verified.cs index 98245e15e62..4b1adaa7217 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithNoPublicConstructors.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithNoPublicConstructors.verified.cs @@ -11,7 +11,6 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_NoPublicCtor : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.NoPublicCtor); @@ -86,7 +85,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_NoPublicCtor : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Activators.IActivator _activator; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithOptionalConstructorParameters.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithOptionalConstructorParameters.verified.cs index e435b8d8deb..767270fa502 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithOptionalConstructorParameters.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithOptionalConstructorParameters.verified.cs @@ -11,7 +11,6 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_OptionalCtorParams : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.OptionalCtorParams); @@ -100,7 +99,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_OptionalCtorParams : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Activators.IActivator _activator; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithParameterizedConstructor.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithParameterizedConstructor.verified.cs index e3a5a396c9f..dae152224e7 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithParameterizedConstructor.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithParameterizedConstructor.verified.cs @@ -11,7 +11,6 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_MyServiceConsumer : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.MyServiceConsumer); @@ -86,7 +85,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_MyServiceConsumer : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Activators.IActivator _activator; @@ -116,7 +114,6 @@ public void DeepCopy(global::TestProject.MyServiceConsumer input, global::TestPr } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_RootType : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.RootType); @@ -192,7 +189,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_RootType : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly OrleansCodeGen.TestProject.Copier_MyServiceConsumer _copier_MyServiceConsumer_FAF0B52DDDE25F7A; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassesWithGeneratedActivatorConstructorAnnotation.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassesWithGeneratedActivatorConstructorAnnotation.verified.cs index aa24b0454af..a9dcb6b944e 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassesWithGeneratedActivatorConstructorAnnotation.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassesWithGeneratedActivatorConstructorAnnotation.verified.cs @@ -11,7 +11,6 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_ClassWithGeneratedActivatorConstructor : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.ClassWithGeneratedActivatorConstructor); @@ -90,7 +89,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_ClassWithGeneratedActivatorConstructor : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestCompoundTypeAlias.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestCompoundTypeAlias.verified.cs index d602490f2ac..d1ba3da19f8 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestCompoundTypeAlias.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestCompoundTypeAlias.verified.cs @@ -11,7 +11,6 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_MyCompoundTypeAliasBaseClass : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.MyCompoundTypeAliasBaseClass); @@ -80,7 +79,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_MyCompoundTypeAliasBaseClass : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -110,7 +108,6 @@ internal sealed class Activator_MyCompoundTypeAliasBaseClass : global::Orleans.S } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_MyCompoundTypeAliasClass : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.MyCompoundTypeAliasClass); @@ -198,7 +195,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_MyCompoundTypeAliasClass : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly OrleansCodeGen.TestProject.Copier_MyCompoundTypeAliasBaseClass _baseTypeCopier; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClass.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClass.verified.cs index 9f5ffc2fd27..b57fa34ea8a 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClass.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClass.verified.cs @@ -11,7 +11,6 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_GenericData : global::Orleans.Serialization.Codecs.IFieldCodec>, global::Orleans.Serialization.Serializers.IBaseCodec> { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GenericData); @@ -97,7 +96,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_GenericData : global::Orleans.Serialization.Cloning.IDeepCopier>, global::Orleans.Serialization.Cloning.IBaseCopier> { private readonly global::Orleans.Serialization.Cloning.IDeepCopier _copier_T_0CA466BDFA032082; @@ -134,7 +132,6 @@ internal sealed class Activator_GenericData : global::Orleans.Serialization.A } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_ConcreteUsage : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.ConcreteUsage); @@ -223,7 +220,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_ConcreteUsage : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly OrleansCodeGen.TestProject.Copier_GenericData _copier_GenericData_Int32_9F0DA0207759221D; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClassWithConstructorParameters.FieldAccessor.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClassWithConstructorParameters.FieldAccessor.verified.cs index 14ac1dacadb..9d506016e39 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClassWithConstructorParameters.FieldAccessor.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClassWithConstructorParameters.FieldAccessor.verified.cs @@ -11,7 +11,6 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Dynamic")] public sealed class Codec_GenericWithCtor : global::Orleans.Serialization.Codecs.IFieldCodec>, global::Orleans.Serialization.Serializers.IBaseCodec> { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GenericWithCtor); @@ -103,7 +102,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Dynamic")] public sealed class Copier_GenericWithCtor : global::Orleans.Serialization.Cloning.IDeepCopier>, global::Orleans.Serialization.Cloning.IBaseCopier> { private readonly global::Orleans.Serialization.Activators.IActivator> _activator; @@ -140,7 +138,6 @@ public void DeepCopy(global::TestProject.GenericWithCtor input, global::TestP } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_UsesGenericWithCtor : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.UsesGenericWithCtor); @@ -216,7 +213,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_UsesGenericWithCtor : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly OrleansCodeGen.TestProject.Copier_GenericWithCtor _copier_GenericWithCtor_String_C8ECFC0964C2C2C3; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClassWithConstructorParameters.UnsafeAccessor.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClassWithConstructorParameters.UnsafeAccessor.verified.cs index 3a263d98634..abfffbd2dc5 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClassWithConstructorParameters.UnsafeAccessor.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClassWithConstructorParameters.UnsafeAccessor.verified.cs @@ -11,7 +11,6 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_GenericWithCtor : global::Orleans.Serialization.Codecs.IFieldCodec>, global::Orleans.Serialization.Serializers.IBaseCodec> { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GenericWithCtor); @@ -103,7 +102,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_GenericWithCtor : global::Orleans.Serialization.Cloning.IDeepCopier>, global::Orleans.Serialization.Cloning.IBaseCopier> { private readonly global::Orleans.Serialization.Activators.IActivator> _activator; @@ -140,7 +138,6 @@ public void DeepCopy(global::TestProject.GenericWithCtor input, global::TestP } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_UsesGenericWithCtor : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.UsesGenericWithCtor); @@ -216,7 +213,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_UsesGenericWithCtor : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly OrleansCodeGen.TestProject.Copier_GenericWithCtor _copier_GenericWithCtor_String_C8ECFC0964C2C2C3; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs index 69c715c2b61..e4feb2d72fe 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs @@ -140,7 +140,6 @@ public Proxy_IComplexGrain(global::Orleans.Runtime.GrainReferenceShared arg0, gl } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_ComplexData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.ComplexData); @@ -219,7 +218,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_ComplexData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -250,7 +248,6 @@ internal sealed class Activator_ComplexData : global::Orleans.Serialization.Acti } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IComplexGrain_GrainReference_67FE5808 : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808); @@ -340,7 +337,6 @@ public OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE580 } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IComplexGrain_GrainReference_67FE5808 : global::Orleans.Serialization.Cloning.IDeepCopier { private readonly OrleansCodeGen.TestProject.Copier_ComplexData _copier_ComplexData_765A40ED2309AF35; @@ -364,7 +360,6 @@ public Copier_Invokable_IComplexGrain_GrainReference_67FE5808(global::Orleans.Se } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_ComplexGrain : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.ComplexGrain); @@ -425,7 +420,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_ComplexGrain : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs index 539269c73a8..0bd91569335 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs @@ -139,7 +139,6 @@ public Proxy_IComplexGrain(global::Orleans.Runtime.GrainReferenceShared arg0, gl } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_ComplexData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.ComplexData); @@ -218,7 +217,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_ComplexData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -249,7 +247,6 @@ internal sealed class Activator_ComplexData : global::Orleans.Serialization.Acti } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IComplexGrain_GrainReference_67FE5808 : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808); @@ -339,7 +336,6 @@ public OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE580 } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IComplexGrain_GrainReference_67FE5808 : global::Orleans.Serialization.Cloning.IDeepCopier { private readonly OrleansCodeGen.TestProject.Copier_ComplexData _copier_ComplexData_765A40ED2309AF35; @@ -363,7 +359,6 @@ public Copier_Invokable_IComplexGrain_GrainReference_67FE5808(global::Orleans.Se } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_ComplexGrain : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.ComplexGrain); @@ -424,7 +419,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_ComplexGrain : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.verified.cs index a637eb04e60..2868b676f37 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.verified.cs @@ -140,7 +140,6 @@ public Proxy_IComplexGrain(global::Orleans.Runtime.GrainReferenceShared arg0, gl } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_ComplexData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.ComplexData); @@ -219,7 +218,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_ComplexData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -250,7 +248,6 @@ internal sealed class Activator_ComplexData : global::Orleans.Serialization.Acti } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IComplexGrain_GrainReference_67FE5808 : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808); @@ -340,7 +337,6 @@ public OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE580 } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IComplexGrain_GrainReference_67FE5808 : global::Orleans.Serialization.Cloning.IDeepCopier { private readonly OrleansCodeGen.TestProject.Copier_ComplexData _copier_ComplexData_765A40ED2309AF35; @@ -364,7 +360,6 @@ public Copier_Invokable_IComplexGrain_GrainReference_67FE5808(global::Orleans.Se } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_ComplexGrain : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.ComplexGrain); @@ -425,7 +420,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_ComplexGrain : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs index a81eaad18bb..d8006b08ef4 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs @@ -95,7 +95,6 @@ public Proxy_IHelloGrain(global::Orleans.Runtime.GrainReferenceShared arg0, glob } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IHelloGrain_GrainReference_5336307F : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F); @@ -158,7 +157,6 @@ public OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IHelloGrain_GrainReference_5336307F : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -173,7 +171,6 @@ public OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_HelloGrain : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.HelloGrain); @@ -234,7 +231,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_HelloGrain : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs index f7ab967c035..dcd89653d43 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs @@ -95,7 +95,6 @@ public Proxy_IHelloGrain(global::Orleans.Runtime.GrainReferenceShared arg0, glob } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IHelloGrain_GrainReference_5336307F : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F); @@ -158,7 +157,6 @@ public OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IHelloGrain_GrainReference_5336307F : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -173,7 +171,6 @@ public OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_HelloGrain : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.HelloGrain); @@ -234,7 +231,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_HelloGrain : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.verified.cs index 1411ec351c9..59bbe4aab27 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.verified.cs @@ -95,7 +95,6 @@ public Proxy_IHelloGrain(global::Orleans.Runtime.GrainReferenceShared arg0, glob } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IHelloGrain_GrainReference_5336307F : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F); @@ -158,7 +157,6 @@ public OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IHelloGrain_GrainReference_5336307F : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -173,7 +171,6 @@ public OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_HelloGrain : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.HelloGrain); @@ -234,7 +231,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_HelloGrain : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs index 82dc68f8b35..19a53a2886a 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs @@ -92,7 +92,6 @@ public Proxy_IResponseTimeoutGrain(global::Orleans.Runtime.GrainReferenceShared } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8); @@ -155,7 +154,6 @@ public OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs index b257f7b84f2..32edc99f9b5 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs @@ -92,7 +92,6 @@ public Proxy_IResponseTimeoutGrain(global::Orleans.Runtime.GrainReferenceShared } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8); @@ -155,7 +154,6 @@ public OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.verified.cs index f6888e60505..f7184cfd5e5 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.verified.cs @@ -92,7 +92,6 @@ public Proxy_IResponseTimeoutGrain(global::Orleans.Runtime.GrainReferenceShared } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8); @@ -155,7 +154,6 @@ public OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs index 7e579a08384..d5aa06c1388 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs @@ -212,7 +212,6 @@ public Proxy_IMyGrainWithIntegerCompoundKey(global::Orleans.Runtime.GrainReferen } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E); @@ -258,7 +257,6 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8 } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -272,7 +270,6 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8 } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_GrainWithGuidKey : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GrainWithGuidKey); @@ -333,7 +330,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_GrainWithGuidKey : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; @@ -369,7 +365,6 @@ internal sealed class Activator_GrainWithGuidKey : global::Orleans.Serialization } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IMyGrainWithStringKey_GrainReference_43570316 : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316); @@ -415,7 +410,6 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IMyGrainWithStringKey_GrainReference_43570316 : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -429,7 +423,6 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_GrainWithStringKey : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GrainWithStringKey); @@ -490,7 +483,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_GrainWithStringKey : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; @@ -526,7 +518,6 @@ internal sealed class Activator_GrainWithStringKey : global::Orleans.Serializati } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF); @@ -572,7 +563,6 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainRef } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -586,7 +576,6 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainRef } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_GrainWithGuidCompoundKey : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GrainWithGuidCompoundKey); @@ -647,7 +636,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_GrainWithGuidCompoundKey : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; @@ -683,7 +671,6 @@ internal sealed class Activator_GrainWithGuidCompoundKey : global::Orleans.Seria } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A); @@ -729,7 +716,6 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_Grain } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -743,7 +729,6 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_Grain } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_GrainWithIntegerCompoundKey : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GrainWithIntegerCompoundKey); @@ -804,7 +789,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_GrainWithIntegerCompoundKey : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs index bfa640ffb6f..48adf90ada7 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs @@ -212,7 +212,6 @@ public Proxy_IMyGrainWithIntegerCompoundKey(global::Orleans.Runtime.GrainReferen } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E); @@ -258,7 +257,6 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8 } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -272,7 +270,6 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8 } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_GrainWithGuidKey : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GrainWithGuidKey); @@ -333,7 +330,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_GrainWithGuidKey : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; @@ -369,7 +365,6 @@ internal sealed class Activator_GrainWithGuidKey : global::Orleans.Serialization } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IMyGrainWithStringKey_GrainReference_43570316 : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316); @@ -415,7 +410,6 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IMyGrainWithStringKey_GrainReference_43570316 : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -429,7 +423,6 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_GrainWithStringKey : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GrainWithStringKey); @@ -490,7 +483,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_GrainWithStringKey : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; @@ -526,7 +518,6 @@ internal sealed class Activator_GrainWithStringKey : global::Orleans.Serializati } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF); @@ -572,7 +563,6 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainRef } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -586,7 +576,6 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainRef } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_GrainWithGuidCompoundKey : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GrainWithGuidCompoundKey); @@ -647,7 +636,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_GrainWithGuidCompoundKey : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; @@ -683,7 +671,6 @@ internal sealed class Activator_GrainWithGuidCompoundKey : global::Orleans.Seria } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A); @@ -729,7 +716,6 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_Grain } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -743,7 +729,6 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_Grain } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_GrainWithIntegerCompoundKey : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GrainWithIntegerCompoundKey); @@ -804,7 +789,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_GrainWithIntegerCompoundKey : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.verified.cs index 661b675c7f5..648e630aa1a 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.verified.cs @@ -212,7 +212,6 @@ public Proxy_IMyGrainWithIntegerCompoundKey(global::Orleans.Runtime.GrainReferen } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E); @@ -258,7 +257,6 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8 } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -272,7 +270,6 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8 } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_GrainWithGuidKey : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GrainWithGuidKey); @@ -333,7 +330,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_GrainWithGuidKey : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; @@ -369,7 +365,6 @@ internal sealed class Activator_GrainWithGuidKey : global::Orleans.Serialization } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IMyGrainWithStringKey_GrainReference_43570316 : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316); @@ -415,7 +410,6 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IMyGrainWithStringKey_GrainReference_43570316 : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -429,7 +423,6 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_GrainWithStringKey : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GrainWithStringKey); @@ -490,7 +483,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_GrainWithStringKey : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; @@ -526,7 +518,6 @@ internal sealed class Activator_GrainWithStringKey : global::Orleans.Serializati } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF); @@ -572,7 +563,6 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainRef } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -586,7 +576,6 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainRef } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_GrainWithGuidCompoundKey : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GrainWithGuidCompoundKey); @@ -647,7 +636,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_GrainWithGuidCompoundKey : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; @@ -683,7 +671,6 @@ internal sealed class Activator_GrainWithGuidCompoundKey : global::Orleans.Seria } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A); @@ -729,7 +716,6 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_Grain } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -743,7 +729,6 @@ public OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_Grain } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_GrainWithIntegerCompoundKey : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GrainWithIntegerCompoundKey); @@ -804,7 +789,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_GrainWithIntegerCompoundKey : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs index 574ef5f2d1a..a9c41ce3b23 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs @@ -168,7 +168,6 @@ public Proxy_IGrainB(global::Orleans.Runtime.GrainReferenceShared arg0, global:: } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IGrainA_GrainReference_11405B98 : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98); @@ -231,7 +230,6 @@ public OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 Read } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IGrainA_GrainReference_11405B98 : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -246,7 +244,6 @@ public OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 Deep } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IGrainB_GrainReference_6B5D7809 : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809); @@ -309,7 +306,6 @@ public OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809 Read } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IGrainB_GrainReference_6B5D7809 : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs index 083dd009f16..d8e2584d38d 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs @@ -168,7 +168,6 @@ public Proxy_IGrainB(global::Orleans.Runtime.GrainReferenceShared arg0, global:: } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IGrainA_GrainReference_11405B98 : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98); @@ -231,7 +230,6 @@ public OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 Read } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IGrainA_GrainReference_11405B98 : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -246,7 +244,6 @@ public OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 Deep } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IGrainB_GrainReference_6B5D7809 : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809); @@ -309,7 +306,6 @@ public OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809 Read } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IGrainB_GrainReference_6B5D7809 : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.verified.cs index 67c7eb78509..5ee9f1824df 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.verified.cs @@ -168,7 +168,6 @@ public Proxy_IGrainB(global::Orleans.Runtime.GrainReferenceShared arg0, global:: } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IGrainA_GrainReference_11405B98 : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98); @@ -231,7 +230,6 @@ public OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 Read } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IGrainA_GrainReference_11405B98 : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -246,7 +244,6 @@ public OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 Deep } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_Invokable_IGrainB_GrainReference_6B5D7809 : global::Orleans.Serialization.Codecs.IFieldCodec { private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809); @@ -309,7 +306,6 @@ public OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809 Read } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_Invokable_IGrainB_GrainReference_6B5D7809 : global::Orleans.Serialization.Cloning.IDeepCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestRecords.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestRecords.verified.cs index 1332f74b94f..24924825d88 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestRecords.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestRecords.verified.cs @@ -11,7 +11,6 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_DemoDataRecordStruct : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IValueSerializer { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DemoDataRecordStruct); @@ -74,7 +73,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_DemoDataRecordClass : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DemoDataRecordClass); @@ -159,7 +157,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_DemoDataRecordClass : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Activators.IActivator _activator; @@ -191,7 +188,6 @@ public void DeepCopy(global::TestProject.DemoDataRecordClass input, global::Test } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_DemoDataRecord : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DemoDataRecord); @@ -276,7 +272,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_DemoDataRecord : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Activators.IActivator _activator; diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestRecordsWithParameterIdAttributes.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestRecordsWithParameterIdAttributes.verified.cs index 8da887d8ee4..99103ab1742 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestRecordsWithParameterIdAttributes.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestRecordsWithParameterIdAttributes.verified.cs @@ -11,7 +11,6 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_SimpleRecord : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.SimpleRecord); @@ -110,7 +109,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_SimpleRecord : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Activators.IActivator _activator; @@ -145,7 +143,6 @@ public void DeepCopy(global::TestProject.SimpleRecord input, global::TestProject } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_RecordWithExtraProperty : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.RecordWithExtraProperty); @@ -260,7 +257,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_RecordWithExtraProperty : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { private readonly global::Orleans.Serialization.Activators.IActivator _activator; @@ -298,7 +294,6 @@ public void DeepCopy(global::TestProject.RecordWithExtraProperty input, global:: } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_RecordStructWithParameterId : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IValueSerializer { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.RecordStructWithParameterId); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithOmitDefaultMemberValuesAnnotation.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithOmitDefaultMemberValuesAnnotation.verified.cs index 5acee83695c..98cad6db203 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithOmitDefaultMemberValuesAnnotation.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithOmitDefaultMemberValuesAnnotation.verified.cs @@ -11,7 +11,6 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_DemoClass : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DemoClass); @@ -85,7 +84,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_DemoClass : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithSuppressReferenceTrackingAttribute.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithSuppressReferenceTrackingAttribute.verified.cs index 3afe0ce1cac..319f7322c72 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithSuppressReferenceTrackingAttribute.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithSuppressReferenceTrackingAttribute.verified.cs @@ -11,7 +11,6 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Codec_DemoClass : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec { private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DemoClass); @@ -85,7 +84,6 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::System.ComponentModel.DescriptionAttribute("OrleansCodeGen.FieldAccessors.v1:Static")] public sealed class Copier_DemoClass : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier { [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] From a7efd458e0327957b4588761a39ee837609fc2d7 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Fri, 2 Oct 2026 15:49:49 -0700 Subject: [PATCH 21/54] fix(codegen): close canonical pair construction dependencies --- .../SerializerFactoryGenerator.cs | 1 + .../OrleansSourceGeneratorTests.cs | 3 +++ .../RpcResponses.Contracts.cs | 16 +++++++--------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs b/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs index d43f9a1c9fd..db8e8fb6e01 100644 --- a/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs +++ b/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs @@ -507,6 +507,7 @@ private static string DefaultDependencyServices(IEnumerable depende { "System.Collections.Generic.List" => "List", "System.Collections.Generic.Dictionary" => "Dictionary", + "System.Collections.Generic.KeyValuePair" => "KeyValuePair", "System.Nullable" => "Nullable", _ => null }; diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index cc5e523534c..6b4873997de 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -2254,6 +2254,7 @@ public interface IResponses : IGrainWithIntegerKey ValueTask Integer(); Task Reference(); Task Repeated(); + Task> Pair(); } [GenerateSerializer, Alias("rpc.payload")] public sealed class Payload @@ -2270,6 +2271,8 @@ public sealed class Payload Assert.Contains("new global::Orleans.Serialization.Invocation.PooledResponseCopier>", source); Assert.Contains("PooledResponseCodec", source); Assert.Contains("new global::OrleansCodeGen.TestProject.Codec_Payload(provider)", source); + Assert.Contains("new global::Orleans.Serialization.Codecs.KeyValuePairCodec", source); + Assert.Contains("new global::Orleans.Serialization.Codecs.KeyValuePairCopier", source); Assert.Contains("caller => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(caller, provider)", source); Assert.Contains("caller => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(caller, provider)", source); Assert.Equal(1, CountOccurrences(source, "options.AddDefaultSerializer,")); diff --git a/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs b/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs index 2760ebec0f4..c44ea80ce59 100644 --- a/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs +++ b/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs @@ -257,15 +257,14 @@ public static void ExceptionTransportRequiresDeclaredGraph() { using var result = RoundTrip(services, exception); } - catch (NotSupportedException error) + catch (CodecNotFoundException error) { - Ensure(error.Message.Contains("ExceptionResponse", StringComparison.Ordinal) - && error.Message.Contains("exception and Data value types", StringComparison.Ordinal), - "Strict exception transport identifies its explicit codec graph contract."); + Ensure(error.Message.Contains("ExceptionResponse", StringComparison.Ordinal), + "Exception transport identifies the codec missing from the registered graph."); return; } - throw new InvalidOperationException("Strict exception transport requires its declared dependency graph."); + throw new InvalidOperationException("Exception transport requires its registered codec dependencies."); } public static void MissingNativeResponseRegistration() @@ -281,11 +280,10 @@ static void Check(Action lookup) { lookup(); } - catch (NotSupportedException exception) + catch (CodecNotFoundException exception) { - Ensure(exception.Message.Contains(typeof(Response).ToString(), StringComparison.Ordinal) - && exception.Message.Contains("serializer context", StringComparison.Ordinal), - "Missing response registrations identify the closed response and registration contract."); + Ensure(exception.Message.Contains(typeof(Response).ToString(), StringComparison.Ordinal), + "Missing response registrations identify the closed response and serialization service."); return; } From 9bfd7e25bb260d0a294d05791e55e66140b4fd55 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Fri, 2 Oct 2026 20:28:16 -0700 Subject: [PATCH 22/54] fix(codegen): close RPC constructor service dependencies --- .../docs/implementation/serialization.md | 6 +- src/Orleans.CodeGenerator/LibraryTypes.cs | 18 ++ .../SerializerFactoryGenerator.cs | 246 +++++++++++++++--- .../Configuration/TypeManifestOptions.cs | 29 ++- .../Serializers/CodecProvider.cs | 31 ++- .../OrleansSourceGeneratorTests.cs | 139 +++++++++- .../RpcResponses.Construction.cs | 67 +++++ test/Orleans.NativeAotSmoke/RpcResponses.cs | 3 +- .../RpcResponseTests.cs | 62 +++++ 9 files changed, 545 insertions(+), 56 deletions(-) create mode 100644 test/Orleans.NativeAotSmoke/RpcResponses.Construction.cs diff --git a/docs/site/src/content/docs/implementation/serialization.md b/docs/site/src/content/docs/implementation/serialization.md index 36b8024ed4c..e5c84056aae 100644 --- a/docs/site/src/content/docs/implementation/serialization.md +++ b/docs/site/src/content/docs/implementation/serialization.md @@ -149,9 +149,11 @@ The finite response graph supplies successful typed results and completed-respon These supplemental registrations are defaults: explicit closed factory registrations take precedence in either configuration order. Generated factories and registered metadata use one resolution pipeline, with closed services selected first. Direct-holder factories and raw-reader registrations bind the selected provider implementations in both JIT and native execution. Custom application codec/copier selection uses the compatibility invocation and serialization path. -Generated metadata also supplies static response factories for non-generic generated result models. These factories construct the model's canonical generated codec and copier using their generated constructor signatures. Construction dependencies include the selected activator and declared codec/copier service contracts; source-known finite dependencies use closed factories, while interface contracts use registered metadata dispatch. This keeps construction within the provider's publication boundary and preserves canonical service identity and rollback. Default activation uses the existing reference- or value-type activator implementation, and custom activation retains its declared contract. Serializer contexts contribute their complete finite dependency graphs and validate each declared member shape. +Generated metadata also supplies static response factories for closed generated result models. These factories construct the model's canonical generated codec and copier using their actual constructor signatures, including available generated activators from referenced assemblies. Source-known arrays, tuples, collections, and surrogate value serializers contribute their closed construction services. Interface contracts retain registered metadata dispatch and propagate their dependency requirements. Reference-assembly construction uses the producer's available constructor contracts and explicitly identified members. -The same collector closes source-known argument construction dependencies selected by generated proxy constructors. Tuple arguments and tuple members use the existing closed `TupleCodec` and `TupleCopier` implementations with their declared element services. Parameter-only one-way contracts register the required construction services while completion and result contracts also register their response graphs. Static interface helpers contribute no RPC construction roots. +Inferred defaults participate when their complete construction graph uses closed service factories, provider-owned services, or explicit instance registrations. Constructor dependencies supplied by ordinary dependency-injection factories or implementation types select canonical metadata activation before the provider starts a serialization construction transaction. carries these dependency edges, preserving explicit registration priority, canonical service identity, and graph rollback. Default activation uses the existing reference- or value-type activator implementation, and custom activation retains its declared contract. Serializer contexts contribute their complete finite dependency graphs and validate each declared member shape. + +The same collector closes source-known argument construction dependencies selected by generated proxy constructors. Reference and value tuples use their existing closed codec and copier implementations with their declared element services. Parameter-only one-way contracts register the required construction services while completion and result contracts also register their response graphs. `OrleansValidateRpcResponseFactories` enables compile-time validation of the response graph and defaults to the executable project's `PublishAot` setting. Diagnostic `ORLEANS0116` identifies an unresolved generic result, a custom return adapter requiring an explicit response contract, or a result dependency outside the supported finite graph. Applications with runtime-selected generic results register every permitted closed graph explicitly through and in a , and set `OrleansValidateRpcResponseFactories=false` for the project supplying that contract. A missing native response registration reports the closed response type and registration guidance at lookup. diff --git a/src/Orleans.CodeGenerator/LibraryTypes.cs b/src/Orleans.CodeGenerator/LibraryTypes.cs index 6f17d26f2fe..5d345d79948 100644 --- a/src/Orleans.CodeGenerator/LibraryTypes.cs +++ b/src/Orleans.CodeGenerator/LibraryTypes.cs @@ -133,7 +133,16 @@ private LibraryTypes(Compilation compilation) new(Type("System.Collections.Generic.Dictionary`2"), Type("Orleans.Serialization.Codecs.DictionaryCodec`2")), new(Type("System.Collections.Generic.List`1"), Type("Orleans.Serialization.Codecs.ListCodec`1")), new(Type("System.Collections.Generic.HashSet`1"), Type("Orleans.Serialization.Codecs.HashSetCodec`1")), + new(Type("System.Collections.Generic.KeyValuePair`2"), Type("Orleans.Serialization.Codecs.KeyValuePairCodec`2")), new(compilation.GetSpecialType(SpecialType.System_Nullable_T), Type("Orleans.Serialization.Codecs.NullableCodec`1")), + new(Type("System.Collections.Immutable.ImmutableArray`1"), Type("Orleans.Serialization.Codecs.ImmutableArrayCodec`1")), + new(Type("System.Collections.Immutable.ImmutableList`1"), Type("Orleans.Serialization.Codecs.ImmutableListCodec`1")), + new(Type("System.Collections.Immutable.ImmutableQueue`1"), Type("Orleans.Serialization.Codecs.ImmutableQueueCodec`1")), + new(Type("System.Collections.Immutable.ImmutableStack`1"), Type("Orleans.Serialization.Codecs.ImmutableStackCodec`1")), + new(Type("System.Collections.Immutable.ImmutableHashSet`1"), Type("Orleans.Serialization.Codecs.ImmutableHashSetCodec`1")), + new(Type("System.Collections.Immutable.ImmutableSortedSet`1"), Type("Orleans.Serialization.Codecs.ImmutableSortedSetCodec`1")), + new(Type("System.Collections.Immutable.ImmutableDictionary`2"), Type("Orleans.Serialization.Codecs.ImmutableDictionaryCodec`2")), + new(Type("System.Collections.Immutable.ImmutableSortedDictionary`2"), Type("Orleans.Serialization.Codecs.ImmutableSortedDictionaryCodec`2")), ]; StaticCopiers = [ @@ -148,7 +157,16 @@ private LibraryTypes(Compilation compilation) new(Type("System.Collections.Generic.Dictionary`2"), Type("Orleans.Serialization.Codecs.DictionaryCopier`2")), new(Type("System.Collections.Generic.List`1"), Type("Orleans.Serialization.Codecs.ListCopier`1")), new(Type("System.Collections.Generic.HashSet`1"), Type("Orleans.Serialization.Codecs.HashSetCopier`1")), + new(Type("System.Collections.Generic.KeyValuePair`2"), Type("Orleans.Serialization.Codecs.KeyValuePairCopier`2")), new(compilation.GetSpecialType(SpecialType.System_Nullable_T), Type("Orleans.Serialization.Codecs.NullableCopier`1")), + new(Type("System.Collections.Immutable.ImmutableArray`1"), Type("Orleans.Serialization.Codecs.ImmutableArrayCopier`1")), + new(Type("System.Collections.Immutable.ImmutableList`1"), Type("Orleans.Serialization.Codecs.ImmutableListCopier`1")), + new(Type("System.Collections.Immutable.ImmutableQueue`1"), Type("Orleans.Serialization.Codecs.ImmutableQueueCopier`1")), + new(Type("System.Collections.Immutable.ImmutableStack`1"), Type("Orleans.Serialization.Codecs.ImmutableStackCopier`1")), + new(Type("System.Collections.Immutable.ImmutableHashSet`1"), Type("Orleans.Serialization.Codecs.ImmutableHashSetCopier`1")), + new(Type("System.Collections.Immutable.ImmutableSortedSet`1"), Type("Orleans.Serialization.Codecs.ImmutableSortedSetCopier`1")), + new(Type("System.Collections.Immutable.ImmutableDictionary`2"), Type("Orleans.Serialization.Codecs.ImmutableDictionaryCopier`2")), + new(Type("System.Collections.Immutable.ImmutableSortedDictionary`2"), Type("Orleans.Serialization.Codecs.ImmutableSortedDictionaryCopier`2")), ]; Exception = Type("System.Exception"); ImmutableAttribute = Type(CodeGeneratorOptions.ImmutableAttribute); diff --git a/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs b/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs index db8e8fb6e01..8e059627d8a 100644 --- a/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs +++ b/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs @@ -3,6 +3,7 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; +using Orleans.CodeGenerator.Model; using Orleans.CodeGenerator.SyntaxGeneration; namespace Orleans.CodeGenerator; @@ -46,17 +47,42 @@ internal sealed record Failure(ITypeSymbol Type, string Reason); bool includeResponse) { cancellationToken.ThrowIfCancellationRequested(); - if (!constructionTypes.Add(type) || type.IsGenericType || type.IsAbstract || type.TypeKind == TypeKind.Interface + var originalBinding = services.Compilation.GetSemanticModel(services.Compilation.SyntaxTrees.First()); + type = originalBinding.GetSpeculativeTypeInfo(0, type.ToTypeSyntax(), SpeculativeBindingOption.BindAsTypeOrNamespace).Type as INamedTypeSymbol + ?? throw new InvalidOperationException($"Unable to bind serialization construction type {type}."); + if (!constructionTypes.Add(type) || ContainsTypeParameter(type) || type.ContainingType is { IsGenericType: true } + || type.IsAbstract || type.TypeKind == TypeKind.Interface || !type.HasAttribute(services.LibraryTypes.GenerateSerializerAttribute)) { return null; } var registration = new Registration(type); + var inspectionCompilation = services.Compilation; + var inspectionType = type; + var inspectionLibrary = services.LibraryTypes; + if (!SymbolEqualityComparer.Default.Equals(type.ContainingAssembly, services.Compilation.Assembly)) + { + inspectionCompilation = services.Compilation.WithOptions(services.Compilation.Options.WithMetadataImportOptions(MetadataImportOptions.All)); + var binding = inspectionCompilation.GetSemanticModel(inspectionCompilation.SyntaxTrees.First()); + inspectionType = binding.GetSpeculativeTypeInfo(0, type.ToTypeSyntax(), SpeculativeBindingOption.BindAsTypeOrNamespace).Type as INamedTypeSymbol + ?? throw new InvalidOperationException($"Unable to bind referenced serialization type {type}."); + inspectionLibrary = LibraryTypes.FromCompilation(inspectionCompilation, services.Options); + } ISerializableTypeDescription? constructionModel; try { - constructionModel = SerializableSourceOutputGenerator.CreateSerializableTypeDescription(services, type, inspectReferenceMetadata: true); + if (SymbolEqualityComparer.Default.Equals(type.ContainingAssembly, services.Compilation.Assembly)) + { + constructionModel = SerializableSourceOutputGenerator.CreateSerializableTypeDescription(services, type); + } + else + { + // Reference assemblies preserve constructor contracts, but can omit serialized private fields. + var fields = new FieldIdAssignmentHelper(inspectionType, [], GenerateFieldIds.None, inspectionLibrary); + constructionModel = new SerializableTypeDescription(inspectionCompilation, inspectionType, false, + SerializableSourceOutputGenerator.GetDataMembers(fields), inspectionLibrary); + } } catch (OrleansGeneratorDiagnosticAnalysisException) { @@ -68,21 +94,36 @@ internal sealed record Failure(ITypeSymbol Type, string Reason); } var requiresActivator = false; + INamedTypeSymbol? referencedActivator = null; + var codecDependencies = new List(); + var copierDependencies = new List(); if (SymbolEqualityComparer.Default.Equals(type.ContainingAssembly, services.Compilation.Assembly)) { - var model = SerializableSourceOutputGenerator.CreateSerializableTypeDescription(services, type); - if (model is null) return null; + var model = constructionModel; DescribeGeneratedModel(registration, type, model); - ConstructGeneratedModel(registration, services); + var codecDeclaration = new SerializerGenerator(services).Generate(model); + var copierDeclaration = new CopierGenerator(services).GenerateCopier(model, new()); + registration.CodecConstruction = ConstructGenerated(registration.Codec, codecDeclaration); + registration.CopierConstruction = copierDeclaration is null + ? $"new {registration.Copier}()" + : ConstructGenerated(registration.Copier, copierDeclaration); requiresActivator = model.UseActivator; + codecDependencies.AddRange(ConstructorDependencies(codecDeclaration)); + if (copierDeclaration is not null) + copierDependencies.AddRange(ConstructorDependencies(copierDeclaration)); } else { var generatedNamespace = SerializerGenerator.GetGeneratedNamespaceName(type); - var codecType = services.Compilation.GetTypeByMetadataName($"{generatedNamespace}.{SerializerGenerator.GetSimpleClassName(type.Name)}"); - if (codecType is null) return null; + var codecType = ResolveModelImplementation(SerializerGenerator.GetSimpleClassName(type.Name)); + if (codecType is null) + { + return null; + } + registration.Codec = Name(codecType); registration.CodecConstruction = ConstructReferenced(registration.Codec, codecType); + codecDependencies.AddRange(ConstructorDependencies(codecType)); requiresActivator = HasActivatorDependency(codecType); if (services.LibraryTypes.IsShallowCopyable(type)) { @@ -91,17 +132,32 @@ internal sealed record Failure(ITypeSymbol Type, string Reason); } else { - var copierType = services.Compilation.GetTypeByMetadataName($"{generatedNamespace}.{CopierGenerator.GetSimpleClassName(type.Name)}"); - if (copierType is null) return null; + var copierType = ResolveModelImplementation(CopierGenerator.GetSimpleClassName(type.Name)); + if (copierType is null) + { + return null; + } + registration.Copier = Name(copierType); registration.CopierConstruction = ConstructReferenced(registration.Copier, copierType); + copierDependencies.AddRange(ConstructorDependencies(copierType)); requiresActivator |= HasActivatorDependency(copierType); } + + INamedTypeSymbol? ResolveModelImplementation(string name) + { + var arity = type.TypeArguments.Length; + var definition = inspectionCompilation.GetTypeByMetadataName($"{generatedNamespace}.{name}{(arity > 0 ? $"`{arity}" : "")}"); + return definition is null || arity == 0 ? definition : definition.Construct([.. type.TypeArguments]); + } + if (requiresActivator) + referencedActivator = ResolveModelImplementation(ActivatorGenerator.GetSimpleClassName(constructionModel)); } if (requiresActivator - && (type.HasAttribute(services.LibraryTypes.UseActivatorAttribute) && !constructionModel.HasActivatorConstructor - || constructionModel.HasActivatorConstructor && !SymbolEqualityComparer.Default.Equals(type.ContainingAssembly, services.Compilation.Assembly))) + && (type.HasAttribute(services.LibraryTypes.UseActivatorAttribute) && !constructionModel.HasActivatorConstructor && referencedActivator is null + || constructionModel.HasActivatorConstructor && !SymbolEqualityComparer.Default.Equals(type.ContainingAssembly, services.Compilation.Assembly) + && (referencedActivator is null || !inspectionCompilation.IsSymbolAccessibleWithin(referencedActivator, inspectionCompilation.Assembly)))) { return null; } @@ -110,22 +166,40 @@ internal sealed record Failure(ITypeSymbol Type, string Reason); var codec = $"global::Orleans.Serialization.Invocation.PooledResponseCodec<{Name(type)}, {registration.Codec}>"; var copier = $"global::Orleans.Serialization.Invocation.PooledResponseCopier<{Name(type)}, {registration.Copier}>"; var result = new StringBuilder(); + foreach (var member in constructionModel.Members) + { + var memberName = Name(member.Type); + if (member.IsSerializable) + codecDependencies.Add($"global::Orleans.Serialization.Codecs.IFieldCodec<{memberName}>"); + if (member.IsCopyable && !services.LibraryTypes.IsShallowCopyable(type)) + copierDependencies.Add($"global::Orleans.Serialization.Cloning.IDeepCopier<{memberName}>"); + } foreach (var memberType in constructionModel.Members .Where(static member => member.IsSerializable || member.IsCopyable) .Select(static member => member.Type) .Distinct(SymbolEqualityComparer.Default)) { - AppendConstructionDependency(services, memberType, cancellationToken, constructionTypes, result); + var originalType = originalBinding.GetSpeculativeTypeInfo(0, memberType.ToTypeSyntax(), SpeculativeBindingOption.BindAsTypeOrNamespace).Type + ?? throw new InvalidOperationException($"Unable to bind serialization construction dependency {memberType}."); + AppendConstructionDependency(services, originalType, cancellationToken, constructionTypes, result); } - if (requiresActivator && constructionModel.HasActivatorConstructor + if (referencedActivator is not null) + { + result.Append("options.AddDefaultSerializerService, ").Append(Name(referencedActivator)).Append(">(static provider => ") + .Append(ConstructReferenced(Name(referencedActivator), referencedActivator)) + .Append(", dependencies: ").Append(DefaultServiceDependencies(ConstructorDependencies(referencedActivator))).AppendLine(");"); + } + else if (requiresActivator && constructionModel.HasActivatorConstructor && SymbolEqualityComparer.Default.Equals(type.ContainingAssembly, services.Compilation.Assembly)) { var activatorName = $"global::{constructionModel.GeneratedNamespace}.{ActivatorGenerator.GetSimpleClassName(constructionModel)}"; var activator = new ActivatorGenerator(services).GenerateActivator(constructionModel); result.Append("options.AddDefaultSerializerService, ").Append(activatorName).Append(">(static provider => ") - .Append(ConstructGenerated(activatorName, activator)).AppendLine(");"); + .Append(ConstructGenerated(activatorName, activator)) + .Append(", dependencies: ").Append(DefaultServiceDependencies(ConstructorDependencies(activator))).AppendLine(");"); } else if (requiresActivator && !type.HasAttribute(services.LibraryTypes.UseActivatorAttribute) && !constructionModel.HasActivatorConstructor) @@ -143,10 +217,19 @@ internal sealed record Failure(ITypeSymbol Type, string Reason); .Append(registration.CopierConstruction).AppendLine(");"); result.Append("options.AddDefaultSerializerService, ").Append(registration.Codec).Append(">(static provider => ") - .Append(Resolve(registration.Codec)).AppendLine(");"); + .Append(Resolve(registration.Codec)) + .Append(", dependencies: ").Append(DefaultServiceDependencies(codecDependencies)).AppendLine(");"); result.Append("options.AddDefaultSerializerService, ").Append(registration.Copier).Append(">(static provider => ") - .Append(Resolve(registration.Copier)).AppendLine(");"); + .Append(Resolve(registration.Copier)) + .Append(", dependencies: ").Append(DefaultServiceDependencies(copierDependencies)).AppendLine(");"); + if (type.IsValueType && type.TypeKind != TypeKind.Enum) + { + result.Append("options.AddDefaultSerializerService, ").Append(registration.Codec).Append(">(static provider => ") + .Append(Resolve(registration.Codec)) + .Append(", dependencies: ").Append(DefaultServiceDependencies(codecDependencies)).AppendLine(");"); + } if (!includeResponse) { return new Graph(new Dictionary(SymbolEqualityComparer.Default) { [type] = registration }, result.ToString()); @@ -166,8 +249,8 @@ internal sealed record Failure(ITypeSymbol Type, string Reason); bool HasActivatorDependency(INamedTypeSymbol implementation) => implementation.InstanceConstructors.SelectMany(static constructor => constructor.Parameters) .Any(parameter => parameter.Type is INamedTypeSymbol dependency - && SymbolEqualityComparer.Default.Equals(dependency.OriginalDefinition, services.LibraryTypes.IActivator_1) - && SymbolEqualityComparer.Default.Equals(dependency.TypeArguments[0], type)); + && SymbolEqualityComparer.Default.Equals(dependency.OriginalDefinition, inspectionLibrary.IActivator_1) + && SymbolEqualityComparer.Default.Equals(dependency.TypeArguments[0], inspectionType)); } @@ -197,6 +280,7 @@ private static void AppendConstructionDependency(IGeneratorServices services, IT && CreateRpcModelRoot(services, modelType, cancellationToken, constructionTypes, includeResponse: false) is { } modelGraph) { result.AppendLine(modelGraph.ConfigurationStatements); + return; } else { @@ -217,18 +301,33 @@ private static void AppendConstructionDependency(IGeneratorServices services, IT return; } + if (dependency is IArrayTypeSymbol { IsSZArray: true } arrayType) + { + AppendConstructionDependency(services, arrayType.ElementType, cancellationToken, constructionTypes, result); + var codec = services.LibraryTypes.ArrayCodec.Construct(arrayType.ElementType); + var copier = services.LibraryTypes.ArrayCopier.Construct(arrayType.ElementType); + result.Append("options.AddDefaultSerializerService<").Append(Name(codec)).Append(">(static provider => ") + .Append(ConstructReferenced(Name(codec), codec)).AppendLine(");"); + result.Append("options.AddDefaultSerializerService<").Append(Name(copier)).Append(">(static provider => ") + .Append(ConstructReferenced(Name(copier), copier)).AppendLine(");"); + result.Append("options.AddDefaultSerializer<").Append(Name(arrayType)).Append(", ").Append(Name(codec)).Append(", ").Append(Name(copier)).Append(">(static provider => ") + .Append(Resolve(Name(codec))).Append(", static provider => ").Append(Resolve(Name(copier))) + .Append(", codecDependencies: ").Append(DefaultDependencyServices([arrayType.ElementType], codec: true)) + .Append(", copierDependencies: ").Append(DefaultDependencyServices([arrayType.ElementType], codec: false)).AppendLine(");"); + return; + } + if (dependency is INamedTypeSymbol collection - && services.LibraryTypes.WellKnownCodecs.FindByUnderlyingType(collection.OriginalDefinition) is { } collectionCodec - && services.LibraryTypes.WellKnownCopiers.FindByUnderlyingType(collection.OriginalDefinition) is { } collectionCopier - && collectionCodec.CodecType.IsGenericType && collectionCopier.CopierType.IsGenericType) + && TryGetConstructionCollectionServices(services, collection, out var collectionCodec, out var collectionCopier)) { - var codec = collectionCodec.CodecType.Construct([.. collection.TypeArguments]); - var copier = collectionCopier.CopierType.Construct([.. collection.TypeArguments]); + var codec = collectionCodec; + var copier = collectionCopier; foreach (var argument in collection.TypeArguments) AppendConstructionDependency(services, argument, cancellationToken, constructionTypes, result); foreach (var parameter in codec.InstanceConstructors.SelectMany(static constructor => constructor.Parameters)) { if (parameter.Type is INamedTypeSymbol contract - && SymbolEqualityComparer.Default.Equals(contract.OriginalDefinition, services.LibraryTypes.FieldCodec_1)) + && (SymbolEqualityComparer.Default.Equals(contract.OriginalDefinition, services.LibraryTypes.FieldCodec_1) + || SymbolEqualityComparer.Default.Equals(contract.OriginalDefinition, services.LibraryTypes.ValueSerializer))) AppendConstructionDependency(services, contract.TypeArguments[0], cancellationToken, constructionTypes, result); } result.Append("options.AddDefaultSerializerService<").Append(Name(codec)).Append(">(static provider => ") @@ -237,17 +336,25 @@ private static void AppendConstructionDependency(IGeneratorServices services, IT .Append(ConstructReferenced(Name(copier), copier)).AppendLine(");"); result.Append("options.AddDefaultSerializer<").Append(Name(collection)).Append(", ").Append(Name(codec)).Append(", ").Append(Name(copier)).Append(">(static provider => ") .Append(Resolve(Name(codec))).Append(", static provider => ").Append(Resolve(Name(copier))) - .Append(", codecDependencies: ").Append(DefaultDependencyServices(collection.TypeArguments, codec: true)) - .Append(", copierDependencies: ").Append(DefaultDependencyServices(collection.TypeArguments, codec: false)).AppendLine(");"); + .Append(", codecDependencies: ").Append(DefaultServiceDependencies(ConstructorDependencies(codec, preferCompleteConstructor: true))) + .Append(", copierDependencies: ").Append(DefaultServiceDependencies(ConstructorDependencies(copier))).AppendLine(");"); return; } var name = Name(dependency); + IEnumerable bridgeDependencies = dependency switch + { + INamedTypeSymbol bridge => bridge.TypeArguments.AsEnumerable(), + IArrayTypeSymbol bridge => [bridge.ElementType], + _ => [] + }; // Metadata bridges add service contracts, while type dispatch stays with ordinary metadata. result.Append("options.AddDefaultSerializerService>(static provider => provider.GetCodec<").Append(name).AppendLine(">());"); + .Append(name).Append(">>(static provider => provider.GetCodec<").Append(name) + .Append(">(), dependencies: ").Append(DefaultDependencyServices(bridgeDependencies, codec: true)).AppendLine(");"); result.Append("options.AddDefaultSerializerService>(static provider => provider.GetDeepCopier<").Append(name).AppendLine(">());"); + .Append(name).Append(">>(static provider => provider.GetDeepCopier<").Append(name) + .Append(">(), dependencies: ").Append(DefaultDependencyServices(bridgeDependencies, codec: false)).AppendLine(");"); if (dependency is INamedTypeSymbol named) { foreach (var argument in named.TypeArguments) AppendConstructionDependency(services, argument, cancellationToken, constructionTypes, result); @@ -449,8 +556,24 @@ void ResolveResponseImplementations(Registration registration) } private static string DefaultDependencyServices(IEnumerable dependencies, bool codec) - => "new global::System.Type[] { " + string.Join(", ", dependencies.Select(dependency => - $"typeof(global::Orleans.Serialization.{(codec ? "Codecs.IFieldCodec" : "Cloning.IDeepCopier")}<{Name(dependency)}>)")) + " }"; + => DefaultServiceDependencies(dependencies.Select(dependency => + $"global::Orleans.Serialization.{(codec ? "Codecs.IFieldCodec" : "Cloning.IDeepCopier")}<{Name(dependency)}>")); + + private static string DefaultServiceDependencies(IEnumerable dependencies) + => "new global::System.Type[] { " + string.Join(", ", dependencies + .Where(static type => type != "global::Orleans.Serialization.Serializers.ICodecProvider") + .Distinct(StringComparer.Ordinal).Select(static type => $"typeof({type})")) + " }"; + + private static IEnumerable ConstructorDependencies(INamedTypeSymbol implementation, bool preferCompleteConstructor = false) + => GetReferencedConstructor(implementation, preferCompleteConstructor).Parameters.Select(static parameter => Name(parameter.Type)); + + private static IEnumerable ConstructorDependencies(ClassDeclarationSyntax declaration) + => (declaration.Members.OfType().SingleOrDefault()?.ParameterList.Parameters + .Select(static parameter => parameter.Type!.ToString()) ?? []) + .Concat(declaration.DescendantNodes().OfType() + .Where(static invocation => invocation.Expression is MemberAccessExpressionSyntax { Name: GenericNameSyntax { Identifier.ValueText: "GetService" } }) + .Select(static invocation => ((GenericNameSyntax)((MemberAccessExpressionSyntax)invocation.Expression).Name) + .TypeArgumentList.Arguments.Single().ToString())); private static string? Describe(Registration registration, IGeneratorServices services, Compilation implementationCompilation, CancellationToken cancellationToken) { @@ -704,14 +827,56 @@ private static bool TryGetTupleServices(IGeneratorServices services, INamedTypeS codec = null; copier = null; var arity = type.TypeArguments.Length; - if (arity == 0 || !SymbolEqualityComparer.Default.Equals(type.OriginalDefinition, - services.Compilation.GetTypeByMetadataName($"System.Tuple`{arity}"))) + if (arity == 0) { return false; } - codec = services.Compilation.GetTypeByMetadataName($"Orleans.Serialization.Codecs.TupleCodec`{arity}")!.Construct([.. type.TypeArguments]); - copier = services.Compilation.GetTypeByMetadataName($"Orleans.Serialization.Codecs.TupleCopier`{arity}")!.Construct([.. type.TypeArguments]); + var family = SymbolEqualityComparer.Default.Equals(type.OriginalDefinition, + services.Compilation.GetTypeByMetadataName($"System.Tuple`{arity}")) ? "Tuple" + : SymbolEqualityComparer.Default.Equals(type.OriginalDefinition, + services.Compilation.GetTypeByMetadataName($"System.ValueTuple`{arity}")) ? "ValueTuple" : null; + if (family is null) return false; + codec = services.Compilation.GetTypeByMetadataName($"Orleans.Serialization.Codecs.{family}Codec`{arity}")!.Construct([.. type.TypeArguments]); + copier = services.Compilation.GetTypeByMetadataName($"Orleans.Serialization.Codecs.{family}Copier`{arity}")!.Construct([.. type.TypeArguments]); + return true; + } + + private static bool TryGetConstructionCollectionServices(IGeneratorServices services, INamedTypeSymbol type, + [NotNullWhen(true)] out INamedTypeSymbol? codec, [NotNullWhen(true)] out INamedTypeSymbol? copier) + { + codec = null; + copier = null; + var codecDefinition = services.LibraryTypes.WellKnownCodecs.FindByUnderlyingType(type.OriginalDefinition)?.CodecType; + var copierDefinition = services.LibraryTypes.WellKnownCopiers.FindByUnderlyingType(type.OriginalDefinition)?.CopierType; + if (codecDefinition is null || copierDefinition is null) + { + var name = type.OriginalDefinition.ToDisplayString() switch + { + "System.Collections.Generic.SortedDictionary" => "SortedDictionary", + "System.Collections.Generic.SortedList" => "SortedList", + "System.Collections.Generic.SortedSet" => "SortedSet", + "System.Collections.Generic.Queue" => "Queue", + "System.Collections.Generic.Stack" => "Stack", + "System.Collections.Concurrent.ConcurrentDictionary" => "ConcurrentDictionary", + "System.Collections.Concurrent.ConcurrentQueue" => "ConcurrentQueue", + "System.Collections.ObjectModel.Collection" => "Collection", + "System.Collections.ObjectModel.ReadOnlyCollection" => "ReadOnlyCollection", + "System.Collections.ObjectModel.ReadOnlyDictionary" => "ReadOnlyDictionary", + "System.Collections.Frozen.FrozenDictionary" => "FrozenDictionary", + "System.Collections.Frozen.FrozenSet" => "FrozenSet", + "System.ArraySegment" => "ArraySegment", + "System.Memory" => "Memory", + "System.ReadOnlyMemory" => "ReadOnlyMemory", + _ => null + }; + if (name is null) return false; + codecDefinition = services.Compilation.GetTypeByMetadataName($"Orleans.Serialization.Codecs.{name}Codec`{type.Arity}"); + copierDefinition = services.Compilation.GetTypeByMetadataName($"Orleans.Serialization.Codecs.{name}Copier`{type.Arity}"); + } + if (codecDefinition is not { IsGenericType: true } || copierDefinition is not { IsGenericType: true }) return false; + codec = codecDefinition.Construct([.. type.TypeArguments]); + copier = copierDefinition.Construct([.. type.TypeArguments]); return true; } @@ -727,10 +892,7 @@ private static void ConstructGeneratedModel(Registration registration, IGenerato private static string ConstructReferenced(string name, INamedTypeSymbol implementation, bool preferCompleteConstructor = false) { - var constructors = implementation.InstanceConstructors.Where(static constructor => constructor.DeclaredAccessibility == Accessibility.Public); - var constructor = preferCompleteConstructor - ? constructors.OrderByDescending(static constructor => constructor.Parameters.Length).First() - : constructors.Single(); + var constructor = GetReferencedConstructor(implementation, preferCompleteConstructor); var arguments = constructor.Parameters.Select(parameter => parameter.Type.ToDisplayString() == "Orleans.Serialization.Serializers.ICodecProvider" ? "provider" @@ -738,6 +900,14 @@ private static string ConstructReferenced(string name, INamedTypeSymbol implemen return $"new {name}({string.Join(", ", arguments)})"; } + private static IMethodSymbol GetReferencedConstructor(INamedTypeSymbol implementation, bool preferCompleteConstructor) + { + var constructors = implementation.InstanceConstructors.Where(static constructor => constructor.DeclaredAccessibility == Accessibility.Public); + return preferCompleteConstructor + ? constructors.OrderByDescending(static constructor => constructor.Parameters.Length).First() + : constructors.Single(); + } + private static string ConstructGenerated(string name, ClassDeclarationSyntax declaration) { var constructor = declaration.Members.OfType().SingleOrDefault(); diff --git a/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs b/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs index 8367ff9bb6d..fa9be0e1805 100644 --- a/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs +++ b/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs @@ -184,6 +184,26 @@ public void AddDefaultSerializerService(Func AddSerializerServiceFactory(typeof(TService), factory, isDefault: true); } + /// + /// Registers a default service factory with its construction dependencies. + /// + /// The closed service type. + /// The default service factory. + /// Services required to construct the default graph. + /// + /// The factory participates when its dependencies are available through closed service factories, + /// provider-owned services, or instance registrations. Explicit registrations take precedence. + /// + /// or is null. + public void AddDefaultSerializerService(Func factory, Type[] dependencies) where TService : class + { + if (dependencies is null) throw new ArgumentNullException(nameof(dependencies)); + dependencies = CopyDefaultDependencies(dependencies); + var register = !SerializerServiceFactories.ContainsKey(typeof(TService)); + AddDefaultSerializerService(factory); + if (register) RegisterDefaultContract(typeof(TService), null, null, dependencies); + } + /// /// Registers an inferred service factory with its canonical implementation identity. /// @@ -191,7 +211,7 @@ public void AddDefaultSerializerService(Func /// The canonical implementation. /// The service factory. /// An equivalent metadata implementation. - /// The canonical implementation's serialization service dependencies. + /// The canonical implementation's construction dependencies. public void AddDefaultSerializerService( Func factory, Type? compatibleImplementationType = null, @@ -207,12 +227,13 @@ public void AddDefaultSerializerService( internal bool IsDefaultSerializerService(Type type) => _defaultSerializerServices.Contains(type); - private void RegisterDefaultContract(Type service, Type implementation, Type? compatible, Type[]? dependencies) + private void RegisterDefaultContract(Type service, Type? implementation, Type? compatible, Type[]? dependencies) { if (!_defaultSerializerServices.Contains(service) || DefaultSerializerContracts.ContainsKey(service)) return; var copiedDependencies = dependencies ?? Type.EmptyTypes; DefaultSerializerContracts.Add(service, new(service, implementation, compatible, copiedDependencies)); - DefaultSerializerContracts.TryAdd(implementation, new(service, implementation, compatible, copiedDependencies)); + if (implementation is not null) + DefaultSerializerContracts.TryAdd(implementation, new(service, implementation, compatible, copiedDependencies)); } private static Type[] CopyDefaultDependencies(Type[]? dependencies) @@ -225,7 +246,7 @@ private static Type[] CopyDefaultDependencies(Type[]? dependencies) return result; } - internal sealed record DefaultSerializerContract(Type Service, Type Implementation, Type? CompatibleImplementation, Type[] Dependencies); + internal sealed record DefaultSerializerContract(Type Service, Type? Implementation, Type? CompatibleImplementation, Type[] Dependencies); private void AddSerializerServiceFactory(Type type, Func factory, bool isDefault) { diff --git a/src/Orleans.Serialization/Serializers/CodecProvider.cs b/src/Orleans.Serialization/Serializers/CodecProvider.cs index 1bf9900b001..6964e96e6ea 100644 --- a/src/Orleans.Serialization/Serializers/CodecProvider.cs +++ b/src/Orleans.Serialization/Serializers/CodecProvider.cs @@ -678,20 +678,35 @@ private bool IsDefaultServiceEligible(Type service) => !_manifest.DefaultSerializerContracts.TryGetValue(service, out var contract) || IsDefaultContractEligible(contract, []); + private bool IsProviderService(Type serviceType) + => serviceType != typeof(object) + && (serviceType == typeof(CodecProvider) || serviceType.IsInterface) + && serviceType.IsInstanceOfType(this); + private bool IsDefaultContractEligible(TypeManifestOptions.DefaultSerializerContract contract, HashSet visited) { if (!_manifest.IsDefaultSerializerService(contract.Service) || !visited.Add(contract.Service)) return true; var role = contract.Service.IsConstructedGenericType ? contract.Service.GetGenericTypeDefinition() : null; var target = role is null ? contract.Service : contract.Service.GenericTypeArguments[0]; - if (role is not null + if (role is not null && contract.Implementation is { } implementation && TrySelectImplementation(role, target, target.IsConstructedGenericType ? target.GetGenericTypeDefinition() : target, out var selected) - && !MatchesDefaultImplementation(selected, contract.Implementation, contract.CompatibleImplementation, target)) + && !MatchesDefaultImplementation(selected, implementation, contract.CompatibleImplementation, target)) return false; foreach (var dependency in contract.Dependencies) { - if (_manifest.DefaultSerializerContracts.TryGetValue(dependency, out var required) - && !IsDefaultContractEligible(required, visited)) + if (_manifest.DefaultSerializerContracts.TryGetValue(dependency, out var required)) + { + if (!IsDefaultContractEligible(required, visited)) return false; + } + else if (!_manifest.SerializerServiceFactories.ContainsKey(dependency) + && !IsProviderService(dependency) + && dependency != typeof(IServiceProvider) + && dependency != typeof(IServiceProviderIsService) + && !(dependency == typeof(IServiceProviderIsKeyedService) && _serviceProvider is IKeyedServiceProvider) + && _serviceDescriptors.LastOrDefault(descriptor => !descriptor.IsKeyedService && descriptor.ServiceType == dependency)?.ImplementationInstance is null) + { return false; + } } return true; } @@ -985,7 +1000,7 @@ private sealed class ConstructionServiceProvider(CodecProvider owner) : IService { if (serviceType == typeof(IServiceProvider) || serviceType == typeof(IServiceProviderIsService) || serviceType == typeof(IServiceProviderIsKeyedService) && owner._serviceProvider is IKeyedServiceProvider) return this; - if (IsProviderService(serviceType)) return owner; + if (owner.IsProviderService(serviceType)) return owner; if (owner._serializerServices.TryGetValue(serviceType, out var completed)) return completed; if (scope.TryGetService(serviceType, out var constructed, requireInstance: false)) return constructed; if (owner.TryGetSerializerService(serviceType, out var registered)) return registered; @@ -1063,7 +1078,7 @@ public bool IsService(Type serviceType) scope?.ThrowIfFaulted(); if (scope is { IsPending: true }) { - return IsProviderService(serviceType) + return owner.IsProviderService(serviceType) || serviceType == typeof(IServiceProvider) || serviceType == typeof(IServiceProviderIsService) || serviceType == typeof(IServiceProviderIsKeyedService) && owner._serviceProvider is IKeyedServiceProvider @@ -1076,10 +1091,6 @@ public bool IsService(Type serviceType) return owner._serviceProvider.GetRequiredService().IsService(serviceType); } - private bool IsProviderService(Type serviceType) - => serviceType != typeof(object) - && (serviceType == typeof(CodecProvider) || serviceType.IsInterface) - && serviceType.IsInstanceOfType(owner); } [DoesNotReturn] diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index 6b4873997de..dd06c47a853 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -2373,6 +2373,143 @@ public sealed class Payload Assert.Contains(strict.Diagnostics, static diagnostic => diagnostic.Id == "ORLEANS0116"); } + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task RpcReferencedGeneratedActivatorFactoryIsClosed(bool referenceAssembly) + { + var producer = await CreateCompilation(""" + using Orleans; + [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ClosureConsumer")] + namespace ReferencedClosure; + [GenerateSerializer, Immutable] + internal sealed class Payload + { + [Id(0)] private int _value; + [System.NonSerialized] internal readonly object _state = new(); + [GeneratedActivatorConstructor] + public Payload(int value) => _value = value; + } + """, "ClosureProducer"); + var generated = RunSourceGenerator(producer); + Assert.Empty(generated.Diagnostics); + producer = producer.AddReferences(MetadataReference.CreateFromFile(typeof(Microsoft.Extensions.Options.IConfigureOptions<>).Assembly.Location)) + .AddSyntaxTrees(generated.GeneratedSources.Select(static source => CSharpSyntaxTree.ParseText(source.SourceText, path: source.HintName))); + using var image = new System.IO.MemoryStream(); + var emitted = producer.Emit(image, + options: new Microsoft.CodeAnalysis.Emit.EmitOptions(metadataOnly: referenceAssembly, includePrivateMembers: !referenceAssembly), + cancellationToken: TestContext.Current.CancellationToken); + Assert.True(emitted.Success, string.Join(Environment.NewLine, emitted.Diagnostics)); + var compilation = (await CreateCompilation(""" + using Orleans; + namespace ClosureProof; + [GenerateSerializer, Immutable] + internal struct Package + { + [Id(0)] public ReferencedClosure.Payload Context { get; set; } + [Id(1)] public System.Collections.Generic.IList> Nested { get; set; } + } + """, "ClosureConsumer")).AddReferences(MetadataReference.CreateFromImage(image.ToArray())); + var type = compilation.GetTypeByMetadataName("ReferencedClosure.Payload"); + Assert.NotNull(type); + var services = new GeneratorServices(compilation, new CodeGeneratorOptions()); + var graph = SerializerFactoryGenerator.CreateRpcModelRoot(services, type, TestContext.Current.CancellationToken); + Assert.NotNull(graph); + Assert.Contains("Activator_Payload", graph.ConfigurationStatements); + Assert.Contains("Codec_Payload", graph.ConfigurationStatements); + var construction = SerializerFactoryGenerator.CreateRpcConstructionRoot(services, type, TestContext.Current.CancellationToken); + Assert.Contains("Activator_Payload", construction.ConfigurationStatements); + Assert.Contains("Codec_Payload", construction.ConfigurationStatements); + var package = compilation.GetTypeByMetadataName("ClosureProof.Package"); + Assert.NotNull(package); + Assert.True(compilation.IsSymbolAccessibleWithin(package, compilation.Assembly)); + Assert.NotNull(SerializerFactoryGenerator.CreateRpcModelRoot(services, package, TestContext.Current.CancellationToken)); + var parent = SerializerFactoryGenerator.CreateRpcConstructionRoot(services, + compilation.GetTypeByMetadataName("System.Collections.Generic.List`1")!.Construct(package), TestContext.Current.CancellationToken); + Assert.True(parent.ConfigurationStatements.Contains("Activator_Payload", StringComparison.Ordinal), parent.ConfigurationStatements); + Assert.Contains("ArrayCodec", parent.ConfigurationStatements); + Assert.Contains("TupleCodec", parent.ConfigurationStatements); + Assert.Contains("IFieldCodec Array; + public System.Collections.Immutable.ImmutableList List; + public System.Collections.Immutable.ImmutableQueue Queue; + public System.Collections.Immutable.ImmutableStack Stack; + public System.Collections.Immutable.ImmutableHashSet Set; + public System.Collections.Immutable.ImmutableSortedSet SortedSet; + public System.Collections.Immutable.ImmutableDictionary Dictionary; + public System.Collections.Immutable.ImmutableSortedDictionary SortedDictionary; + } + """, $"ImmutableClosureProof{Guid.NewGuid():N}"); + var services = new GeneratorServices(compilation, new CodeGeneratorOptions()); + var statements = new System.Text.StringBuilder(); + var assertions = new System.Text.StringBuilder(); + foreach (var field in compilation.GetTypeByMetadataName("ClosureProof.Root")!.GetMembers().OfType()) + { + var type = (INamedTypeSymbol)field.Type; + var graph = SerializerFactoryGenerator.CreateRpcConstructionRoot(services, type, TestContext.Current.CancellationToken); + var codec = services.LibraryTypes.WellKnownCodecs.FindByUnderlyingType(type.OriginalDefinition)!.CodecType.Construct([.. type.TypeArguments]); + var surrogate = ((INamedTypeSymbol)codec.InstanceConstructors.Single().Parameters.Single().Type).TypeArguments.Single(); + var typeName = type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); + var codecName = codec.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); + var surrogateName = surrogate.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); + Assert.Contains($"IValueSerializer<{surrogateName}>", graph.ConfigurationStatements); + Assert.Contains($"new {codecName}(", graph.ConfigurationStatements); + statements.AppendLine(graph.ConfigurationStatements); + assertions.AppendLine($""" + if (!ReferenceEquals(provider.GetCodec<{typeName}>(), + Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService<{codecName}>(null, provider))) return false; + if (!ReferenceEquals(provider.GetValueSerializer<{surrogateName}>(), provider.GetCodec<{surrogateName}>())) return false; + _ = provider.GetDeepCopier<{typeName}>(); + """); + } + var exercise = $$""" + using System; + using System.Collections.Immutable; + using Microsoft.Extensions.DependencyInjection; + using Orleans.Serialization; + using Orleans.Serialization.Serializers; + public static class ImmutableClosureProof + { + public static bool Run() + { + using var services = new ServiceCollection().AddSerializer(builder => builder.Configure(options => + { + {{statements}} + })).BuildServiceProvider(); + var provider = services.GetRequiredService(); + {{assertions}} + var serializer = services.GetRequiredService(); + var source = ImmutableDictionary.Create(StringComparer.OrdinalIgnoreCase).Add("Key", 47); + var result = serializer.Deserialize>(serializer.SerializeToArray(source)); + var sorted = ImmutableSortedDictionary.Create(StringComparer.OrdinalIgnoreCase).Add("Key", 59); + var sortedResult = serializer.Deserialize>(serializer.SerializeToArray(sorted)); + return result["KEY"] == 47 && sortedResult["KEY"] == 59 + && ReferenceEquals(result.KeyComparer, source.KeyComparer) + && ReferenceEquals(sortedResult.KeyComparer, sorted.KeyComparer); + } + } + """; + compilation = compilation.AddReferences( + MetadataReference.CreateFromFile(typeof(Microsoft.Extensions.Options.IConfigureOptions<>).Assembly.Location), + MetadataReference.CreateFromFile(typeof(Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions).Assembly.Location)) + .AddSyntaxTrees(CSharpSyntaxTree.ParseText(exercise, cancellationToken: TestContext.Current.CancellationToken)); + using var image = new System.IO.MemoryStream(); + var emitted = compilation.Emit(image, cancellationToken: TestContext.Current.CancellationToken); + Assert.True(emitted.Success, string.Join(Environment.NewLine, emitted.Diagnostics)); + var assembly = System.Reflection.Assembly.Load(image.ToArray()); + Assert.Equal(true, assembly.GetType("ImmutableClosureProof")!.GetMethod("Run")!.Invoke(null, null)); + } + [Fact] public async Task RpcResponseFactoriesConstructPartialModelRootsWithinPendingGraphs() { @@ -2496,7 +2633,7 @@ public static bool Run(bool includeActivator) var run = assembly.GetType("RootProof")!.GetMethod("Run")!; var rejected = Assert.Throws(() => run.Invoke(null, [false])); var error = Assert.IsType(rejected.InnerException); - Assert.Contains("IActivator", error.Message); + Assert.Contains("Dependency injection cannot resolve", error.Message); Assert.Contains("graph is unpublished", error.Message); Assert.Equal(true, run.Invoke(null, [true])); } diff --git a/test/Orleans.NativeAotSmoke/RpcResponses.Construction.cs b/test/Orleans.NativeAotSmoke/RpcResponses.Construction.cs new file mode 100644 index 00000000000..09c9827d28d --- /dev/null +++ b/test/Orleans.NativeAotSmoke/RpcResponses.Construction.cs @@ -0,0 +1,67 @@ +using System; +using Microsoft.Extensions.DependencyInjection; +using Orleans.Serialization; +using Orleans.Serialization.Activators; +using Orleans.Serialization.Codecs; +using Orleans.Serialization.Configuration; +using Orleans.Serialization.GeneratedCodeHelpers; +using Orleans.Serialization.Serializers; + +namespace Orleans.NativeAotSmoke; + +internal static class RpcConstructionContracts +{ + public static void DefaultGraphsRespectConstructorDependencies() + { + var calls = 0; + var collection = new ServiceCollection().AddSingleton(); + collection.AddSerializerContext(new global::OrleansCodeGen.OrleansNativeAotSmoke.RpcResponseFactories()); + collection.Configure(options => + { + options.AddFieldCodec(typeof(global::OrleansCodeGen.Orleans.NativeAotSmoke.Codec_RpcActivatedValue), typeof(RpcActivatedValue)); + options.AddActivator(typeof(global::OrleansCodeGen.Orleans.NativeAotSmoke.Activator_RpcActivatedValue), typeof(RpcActivatedValue)); + options.AddDefaultSerializerService, global::OrleansCodeGen.Orleans.NativeAotSmoke.Activator_RpcActivatedValue>( + provider => new global::OrleansCodeGen.Orleans.NativeAotSmoke.Activator_RpcActivatedValue( + OrleansGeneratedCodeHelper.GetService(null!, provider)), + dependencies: [typeof(RpcConstructorDependency)]); + options.AddDefaultSerializerService(provider => + { + calls++; + return new(OrleansGeneratedCodeHelper.GetService>(null!, provider)); + }); + options.AddDefaultSerializerService, global::OrleansCodeGen.Orleans.NativeAotSmoke.Codec_RpcActivatedValue>( + provider => OrleansGeneratedCodeHelper.GetService(null!, provider), + dependencies: [typeof(IActivator)]); + options.AddAllowedType(typeof(RpcActivatedValue)); + }); + using var services = collection.BuildServiceProvider(); + var provider = services.GetRequiredService(); + var codec = provider.GetCodec(); + if (calls != 0 || codec is not global::OrleansCodeGen.Orleans.NativeAotSmoke.Codec_RpcActivatedValue + || !ReferenceEquals(codec, provider.GetCodec())) + throw new InvalidOperationException("The inferred graph must decline arbitrary DI before canonical generated codec activation."); + var serializer = services.GetRequiredService(); + var source = new RpcActivatedValue(services.GetRequiredService()) { Value = 59 }; + var result = serializer.Deserialize(serializer.SerializeToArray(source)); + if (result is null || result.Value != 59 || result.ConstructionValue != 47 || calls != 0) + throw new InvalidOperationException("The rooted generated codec and activator must construct through ordinary native metadata dispatch."); + } +} + +public sealed class RpcConstructorDependency +{ + public int Value => 47; +} + +[GenerateSerializer, Immutable] +public sealed class RpcActivatedValue +{ + [GeneratedActivatorConstructor] + public RpcActivatedValue(RpcConstructorDependency dependency) => ConstructionValue = dependency.Value; + + [NonSerialized] + public readonly int ConstructionValue; + + [Id(0)] + public int Value { get; set; } +} diff --git a/test/Orleans.NativeAotSmoke/RpcResponses.cs b/test/Orleans.NativeAotSmoke/RpcResponses.cs index fd9475706a8..0e7553caeff 100644 --- a/test/Orleans.NativeAotSmoke/RpcResponses.cs +++ b/test/Orleans.NativeAotSmoke/RpcResponses.cs @@ -12,4 +12,5 @@ RpcResponseContracts.ExceptionTransportRequiresDeclaredGraph(); RpcResponseContracts.RawResponses(); RpcResponseContracts.MissingNativeResponseRegistration(); -Console.WriteLine("Native Response dispatch passed: DeepCopier, bool, int, reference cycles, null, completion/exception identity, and raw message encoding."); +RpcConstructionContracts.DefaultGraphsRespectConstructorDependencies(); +Console.WriteLine("Native Response dispatch passed: DeepCopier, bool, int, reference cycles, null, completion/exception identity, raw message encoding, and canonical constructor activation after default graph declination."); diff --git a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs index c00246b494b..453d658f2cc 100644 --- a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs +++ b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs @@ -237,6 +237,68 @@ public void LegacyJitDictionaryResponsesPreserveCustomComparers() Assert.Equal(42, result.TypedResult["ENTRY"]); } + [Theory] + [InlineData("None", false)] + [InlineData("ImplementationType", false)] + [InlineData("ImplementationFactory", false)] + [InlineData("Instance", true)] + [InlineData("SerializerFactory", true)] + public void DefaultFactoryConstructorDependenciesRespectPublicationBoundary(string registration, bool eligible) + { + var dependency = new FactoryDependency(); + var codec = new Int32Codec(); + var calls = 0; + var collection = new ServiceCollection(); + if (registration == "ImplementationType") collection.AddSingleton(); + if (registration == "ImplementationFactory") collection.AddSingleton(_ => dependency); + if (registration == "Instance") collection.AddSingleton(dependency); + using var services = collection.Configure(options => + { + if (registration == "SerializerFactory") + options.AddSerializerService(_ => dependency); + options.AddDefaultSerializerService( + provider => new(OrleansGeneratedCodeHelper.GetService(null!, provider)), + dependencies: [typeof(FactoryDependency)]); + var bridgeDependencies = new[] { typeof(DependencyBoundFactoryService) }; + options.AddDefaultSerializerService( + provider => new(OrleansGeneratedCodeHelper.GetService(null!, provider)), + bridgeDependencies); + bridgeDependencies[0] = typeof(InvalidOperationException); + options.AddDefaultSerializer>(provider => + { + calls++; + var bridge = OrleansGeneratedCodeHelper.GetService(null!, provider); + Assert.Same(dependency, bridge.Service.Dependency); + return codec; + }, static _ => new ShallowCopier(), codecDependencies: [typeof(ConstructorBridge)]); + }).AddSerializer().BuildServiceProvider(); + var provider = services.GetRequiredService(); + var result = provider.GetCodec(); + Assert.Equal(eligible ? 1 : 0, calls); + if (eligible) + { + Assert.Same(codec, result); + Assert.Same(dependency, OrleansGeneratedCodeHelper.GetService(null!, provider).Dependency); + } + else + { + Assert.IsType(result); + Assert.NotSame(codec, result); + } + } + + private sealed class FactoryDependency; + + private sealed class DependencyBoundFactoryService(FactoryDependency dependency) + { + public FactoryDependency Dependency { get; } = dependency; + } + + private sealed class ConstructorBridge(DependencyBoundFactoryService service) + { + public DependencyBoundFactoryService Service { get; } = service; + } + [Theory] [InlineData(false)] [InlineData(true)] From 423d0eab9b37918ddc236bd48dea9eec227cb50e Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Fri, 2 Oct 2026 20:46:43 -0700 Subject: [PATCH 23/54] docs(serialization): align missing response diagnostics --- docs/site/src/content/docs/implementation/serialization.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/site/src/content/docs/implementation/serialization.md b/docs/site/src/content/docs/implementation/serialization.md index e5c84056aae..e737051594f 100644 --- a/docs/site/src/content/docs/implementation/serialization.md +++ b/docs/site/src/content/docs/implementation/serialization.md @@ -155,7 +155,7 @@ Inferred defaults participate when their complete construction graph uses closed The same collector closes source-known argument construction dependencies selected by generated proxy constructors. Reference and value tuples use their existing closed codec and copier implementations with their declared element services. Parameter-only one-way contracts register the required construction services while completion and result contracts also register their response graphs. -`OrleansValidateRpcResponseFactories` enables compile-time validation of the response graph and defaults to the executable project's `PublishAot` setting. Diagnostic `ORLEANS0116` identifies an unresolved generic result, a custom return adapter requiring an explicit response contract, or a result dependency outside the supported finite graph. Applications with runtime-selected generic results register every permitted closed graph explicitly through and in a , and set `OrleansValidateRpcResponseFactories=false` for the project supplying that contract. A missing native response registration reports the closed response type and registration guidance at lookup. +`OrleansValidateRpcResponseFactories` enables compile-time validation of the response graph and defaults to the executable project's `PublishAot` setting. Diagnostic `ORLEANS0116` identifies an unresolved generic result, a custom return adapter requiring an explicit response contract, or a result dependency outside the supported finite graph. Applications with runtime-selected generic results register every permitted closed graph explicitly through and in a , and set `OrleansValidateRpcResponseFactories=false` for the project supplying that contract. A missing native response registration reports the closed response type and requested serialization service at lookup. Dictionary results and dictionary members require an explicit closed registration which preserves the application's comparer contract. A dictionary's comparer is selected per value, so the method's declared result type alone supplies the key/value shape while the registration supplies comparer serialization and copying. From 8244d9965cea6ae3acaab4835c7afe1bbc1b94c8 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Fri, 2 Oct 2026 21:18:56 -0700 Subject: [PATCH 24/54] fix(codegen): gate concrete RPC factories independently of aliases --- .../SerializerFactoryGenerator.cs | 40 +++++++++++++------ .../Configuration/TypeManifestOptions.cs | 8 +++- ...ests.TestBasicGrain.DotNet10_0.verified.cs | 4 +- ...Tests.TestBasicGrain.DotNet8_0.verified.cs | 4 +- ...rializersAnnotation.DotNet10_0.verified.cs | 4 +- ...erializersAnnotation.DotNet8_0.verified.cs | 4 +- ...stGrainComplexGrain.DotNet10_0.verified.cs | 8 ++-- ...estGrainComplexGrain.DotNet8_0.verified.cs | 8 ++-- ...thInvokableBaseType.DotNet10_0.verified.cs | 4 +- ...ithInvokableBaseType.DotNet8_0.verified.cs | 4 +- ...WithResponseTimeout.DotNet10_0.verified.cs | 4 +- ...dWithResponseTimeout.DotNet8_0.verified.cs | 4 +- ...thDifferentKeyTypes.DotNet10_0.verified.cs | 24 +++++------ ...ithDifferentKeyTypes.DotNet8_0.verified.cs | 24 +++++------ ...hMultipleInterfaces.DotNet10_0.verified.cs | 4 +- ...thMultipleInterfaces.DotNet8_0.verified.cs | 4 +- .../RpcResponses.Construction.cs | 16 +++++++- .../RpcResponseTests.cs | 33 +++++++++++---- 18 files changed, 126 insertions(+), 75 deletions(-) diff --git a/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs b/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs index 8e059627d8a..7b236024349 100644 --- a/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs +++ b/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs @@ -212,9 +212,11 @@ internal sealed record Failure(ITypeSymbol Type, string Reason); } result.Append("options.AddDefaultSerializerService<").Append(registration.Codec).Append(">(static provider => ") - .Append(registration.CodecConstruction).AppendLine(");"); + .Append(registration.CodecConstruction) + .Append(", dependencies: ").Append(DefaultServiceDependencies(codecDependencies)).AppendLine(");"); result.Append("options.AddDefaultSerializerService<").Append(registration.Copier).Append(">(static provider => ") - .Append(registration.CopierConstruction).AppendLine(");"); + .Append(registration.CopierConstruction) + .Append(", dependencies: ").Append(DefaultServiceDependencies(copierDependencies)).AppendLine(");"); result.Append("options.AddDefaultSerializerService, ").Append(registration.Codec).Append(">(static provider => ") .Append(Resolve(registration.Codec)) @@ -236,9 +238,11 @@ internal sealed record Failure(ITypeSymbol Type, string Reason); } result.Append("options.AddDefaultSerializerService<").Append(codec).Append(">(static provider => new ") - .Append(codec).Append("(caller => ").Append(Resolve(registration.Codec, "caller")).AppendLine("));"); + .Append(codec).Append("(caller => ").Append(Resolve(registration.Codec, "caller")) + .Append("), dependencies: ").Append(DefaultDependencyServices([type], codec: true)).AppendLine(");"); result.Append("options.AddDefaultSerializerService<").Append(copier).Append(">(static provider => new ") - .Append(copier).Append("(caller => ").Append(Resolve(registration.Copier, "caller")).AppendLine("));"); + .Append(copier).Append("(caller => ").Append(Resolve(registration.Copier, "caller")) + .Append("), dependencies: ").Append(DefaultDependencyServices([type], codec: false)).AppendLine(");"); result.Append("options.AddDefaultSerializer<").Append(Name(responseType)).Append(", ").Append(codec).Append(", ").Append(copier).Append(">(static provider => ") .Append(Resolve(codec)).Append(", static provider => ").Append(Resolve(copier)) .Append(", codecDependencies: ").Append(DefaultDependencyServices([type], codec: true)) @@ -291,9 +295,11 @@ private static void AppendConstructionDependency(IGeneratorServices services, IT { foreach (var element in tupleType.TypeArguments) AppendConstructionDependency(services, element, cancellationToken, constructionTypes, result); result.Append("options.AddDefaultSerializerService<").Append(Name(tupleCodec)).Append(">(static provider => ") - .Append(ConstructReferenced(Name(tupleCodec), tupleCodec)).AppendLine(");"); + .Append(ConstructReferenced(Name(tupleCodec), tupleCodec)) + .Append(", dependencies: ").Append(DefaultServiceDependencies(ConstructorDependencies(tupleCodec))).AppendLine(");"); result.Append("options.AddDefaultSerializerService<").Append(Name(tupleCopier)).Append(">(static provider => ") - .Append(ConstructReferenced(Name(tupleCopier), tupleCopier)).AppendLine(");"); + .Append(ConstructReferenced(Name(tupleCopier), tupleCopier)) + .Append(", dependencies: ").Append(DefaultServiceDependencies(ConstructorDependencies(tupleCopier))).AppendLine(");"); result.Append("options.AddDefaultSerializer<").Append(Name(tupleType)).Append(", ").Append(Name(tupleCodec)).Append(", ").Append(Name(tupleCopier)).Append(">(static provider => ") .Append(Resolve(Name(tupleCodec))).Append(", static provider => ").Append(Resolve(Name(tupleCopier))) .Append(", codecDependencies: ").Append(DefaultDependencyServices(tupleType.TypeArguments, codec: true)) @@ -307,9 +313,11 @@ private static void AppendConstructionDependency(IGeneratorServices services, IT var codec = services.LibraryTypes.ArrayCodec.Construct(arrayType.ElementType); var copier = services.LibraryTypes.ArrayCopier.Construct(arrayType.ElementType); result.Append("options.AddDefaultSerializerService<").Append(Name(codec)).Append(">(static provider => ") - .Append(ConstructReferenced(Name(codec), codec)).AppendLine(");"); + .Append(ConstructReferenced(Name(codec), codec)) + .Append(", dependencies: ").Append(DefaultServiceDependencies(ConstructorDependencies(codec))).AppendLine(");"); result.Append("options.AddDefaultSerializerService<").Append(Name(copier)).Append(">(static provider => ") - .Append(ConstructReferenced(Name(copier), copier)).AppendLine(");"); + .Append(ConstructReferenced(Name(copier), copier)) + .Append(", dependencies: ").Append(DefaultServiceDependencies(ConstructorDependencies(copier))).AppendLine(");"); result.Append("options.AddDefaultSerializer<").Append(Name(arrayType)).Append(", ").Append(Name(codec)).Append(", ").Append(Name(copier)).Append(">(static provider => ") .Append(Resolve(Name(codec))).Append(", static provider => ").Append(Resolve(Name(copier))) .Append(", codecDependencies: ").Append(DefaultDependencyServices([arrayType.ElementType], codec: true)) @@ -331,9 +339,11 @@ private static void AppendConstructionDependency(IGeneratorServices services, IT AppendConstructionDependency(services, contract.TypeArguments[0], cancellationToken, constructionTypes, result); } result.Append("options.AddDefaultSerializerService<").Append(Name(codec)).Append(">(static provider => ") - .Append(ConstructReferenced(Name(codec), codec, preferCompleteConstructor: true)).AppendLine(");"); + .Append(ConstructReferenced(Name(codec), codec, preferCompleteConstructor: true)) + .Append(", dependencies: ").Append(DefaultServiceDependencies(ConstructorDependencies(codec, preferCompleteConstructor: true))).AppendLine(");"); result.Append("options.AddDefaultSerializerService<").Append(Name(copier)).Append(">(static provider => ") - .Append(ConstructReferenced(Name(copier), copier)).AppendLine(");"); + .Append(ConstructReferenced(Name(copier), copier)) + .Append(", dependencies: ").Append(DefaultServiceDependencies(ConstructorDependencies(copier))).AppendLine(");"); result.Append("options.AddDefaultSerializer<").Append(Name(collection)).Append(", ").Append(Name(codec)).Append(", ").Append(Name(copier)).Append(">(static provider => ") .Append(Resolve(Name(codec))).Append(", static provider => ").Append(Resolve(Name(copier))) .Append(", codecDependencies: ").Append(DefaultServiceDependencies(ConstructorDependencies(codec, preferCompleteConstructor: true))) @@ -481,9 +491,15 @@ internal static bool TryCreate( } result.Append("options.").Append(addService).Append('<').Append(registration.Codec).Append(">(static provider => ") - .Append(registration.CodecConstruction).AppendLine(");"); + .Append(registration.CodecConstruction); + if (useDefaultFactories && registration.Dependencies.Count > 0) + result.Append(", dependencies: ").Append(DefaultDependencyServices(registration.Dependencies, codec: true)); + result.AppendLine(");"); result.Append("options.").Append(addService).Append('<').Append(registration.Copier).Append(">(static provider => ") - .Append(registration.CopierConstruction).AppendLine(");"); + .Append(registration.CopierConstruction); + if (useDefaultFactories && registration.Dependencies.Count > 0) + result.Append(", dependencies: ").Append(DefaultDependencyServices(registration.Dependencies, codec: false)); + result.AppendLine(");"); result.Append("options.").Append(addSerializer).Append('<').Append(typeName); if (useDefaultFactories) result.Append(", ").Append(registration.Codec).Append(", ").Append(registration.Copier); diff --git a/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs b/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs index fa9be0e1805..445d2c05fef 100644 --- a/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs +++ b/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs @@ -125,12 +125,12 @@ public void AddDefaultSerializer( if (registerCodec) { RegisterDefaultContract(typeof(IFieldCodec), typeof(TCodec), compatibleCodecType, codecDependencies); - DefaultCodecFactoryContracts.Add(typeof(T), DefaultSerializerContracts[typeof(IFieldCodec)]); + DefaultCodecFactoryContracts.TryAdd(typeof(T), DefaultSerializerContracts[typeof(IFieldCodec)]); } if (registerCopier) { RegisterDefaultContract(typeof(IDeepCopier), typeof(TCopier), compatibleCopierType, copierDependencies); - DefaultCopierFactoryContracts.Add(typeof(T), DefaultSerializerContracts[typeof(IDeepCopier)]); + DefaultCopierFactoryContracts.TryAdd(typeof(T), DefaultSerializerContracts[typeof(IDeepCopier)]); } } @@ -147,6 +147,10 @@ private void RegisterSerializerFactories( Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null!, provider)); AddSerializerServiceFactory(typeof(IFieldCodec), codecFactory, isDefault); AddSerializerServiceFactory(typeof(IDeepCopier), copierFactory, isDefault); + if (DefaultSerializerContracts.TryGetValue(typeof(IFieldCodec), out var codecContract)) + DefaultCodecFactoryContracts.TryAdd(typeof(T), codecContract); + if (DefaultSerializerContracts.TryGetValue(typeof(IDeepCopier), out var copierContract)) + DefaultCopierFactoryContracts.TryAdd(typeof(T), copierContract); ContextTypes.Add(typeof(T)); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs index d29c3c68f4b..79284d3bcdb 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs @@ -269,8 +269,8 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); #if NET5_0_OR_GREATER - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs index f4cb30c29f8..5253130afae 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs @@ -269,8 +269,8 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); #if NET5_0_OR_GREATER - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs index a6198d8f65a..43b63e13263 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs @@ -177,8 +177,8 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); #if NET5_0_OR_GREATER - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs index 47a214ac251..43368876901 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs @@ -177,8 +177,8 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); #if NET5_0_OR_GREATER - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs index e4feb2d72fe..bc06cdbeda8 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs @@ -463,12 +463,12 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializer(static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider), static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider)); #if NET5_0_OR_GREATER - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); - options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Codec_ComplexData()); - options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Copier_ComplexData()); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Codec_ComplexData(), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Copier_ComplexData(), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::TestProject.ComplexData)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.Int32Codec()); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs index 0bd91569335..f5b74905d8d 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs @@ -462,12 +462,12 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializer(static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider), static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider)); #if NET5_0_OR_GREATER - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); - options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Codec_ComplexData()); - options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Copier_ComplexData()); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Codec_ComplexData(), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Copier_ComplexData(), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::TestProject.ComplexData)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.Int32Codec()); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs index d8006b08ef4..d0530895d53 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs @@ -274,8 +274,8 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); #if NET5_0_OR_GREATER - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs index dcd89653d43..e45ffd4dc65 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs @@ -274,8 +274,8 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); #if NET5_0_OR_GREATER - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs index 19a53a2886a..25034525a90 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs @@ -176,8 +176,8 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); #if NET5_0_OR_GREATER - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs index 32edc99f9b5..b68e26faadf 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs @@ -176,8 +176,8 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); #if NET5_0_OR_GREATER - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs index d5aa06c1388..b8e11edb1e0 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs @@ -841,32 +841,32 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); #if NET5_0_OR_GREATER - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); - options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec>) }); + options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier>) }); options.AddDefaultSerializer>, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>, global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec>) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier>) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response>)); - options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec>) }); + options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier>) }); options.AddDefaultSerializer>, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>, global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec>) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier>) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response>)); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.GuidCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(global::System.Guid)); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Codecs.TupleCodec, global::Orleans.Serialization.Codecs.TupleCopier>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::System.Tuple)); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Codecs.TupleCodec, global::Orleans.Serialization.Codecs.TupleCopier>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::System.Tuple)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.Int64Codec()); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs index 48adf90ada7..61ffbd20ad7 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs @@ -841,32 +841,32 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); #if NET5_0_OR_GREATER - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); - options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec>) }); + options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier>) }); options.AddDefaultSerializer>, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>, global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec>) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier>) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response>)); - options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec>) }); + options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier>) }); options.AddDefaultSerializer>, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>, global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec>) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier>) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response>)); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.GuidCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(global::System.Guid)); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Codecs.TupleCodec, global::Orleans.Serialization.Codecs.TupleCopier>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::System.Tuple)); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Codecs.TupleCodec, global::Orleans.Serialization.Codecs.TupleCopier>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::System.Tuple)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.Int64Codec()); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs index a9c41ce3b23..f4157010400 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs @@ -328,8 +328,8 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); #if NET5_0_OR_GREATER - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs index d8e2584d38d..cc6bb7cd909 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs @@ -328,8 +328,8 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); #if NET5_0_OR_GREATER - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); diff --git a/test/Orleans.NativeAotSmoke/RpcResponses.Construction.cs b/test/Orleans.NativeAotSmoke/RpcResponses.Construction.cs index 09c9827d28d..d931ab91c12 100644 --- a/test/Orleans.NativeAotSmoke/RpcResponses.Construction.cs +++ b/test/Orleans.NativeAotSmoke/RpcResponses.Construction.cs @@ -12,6 +12,12 @@ namespace Orleans.NativeAotSmoke; internal static class RpcConstructionContracts { public static void DefaultGraphsRespectConstructorDependencies() + { + Check(false); + Check(true); + } + + private static void Check(bool bridgeFirst) { var calls = 0; var collection = new ServiceCollection().AddSingleton(); @@ -20,6 +26,7 @@ public static void DefaultGraphsRespectConstructorDependencies() { options.AddFieldCodec(typeof(global::OrleansCodeGen.Orleans.NativeAotSmoke.Codec_RpcActivatedValue), typeof(RpcActivatedValue)); options.AddActivator(typeof(global::OrleansCodeGen.Orleans.NativeAotSmoke.Activator_RpcActivatedValue), typeof(RpcActivatedValue)); + if (bridgeFirst) RegisterBridge(options); options.AddDefaultSerializerService, global::OrleansCodeGen.Orleans.NativeAotSmoke.Activator_RpcActivatedValue>( provider => new global::OrleansCodeGen.Orleans.NativeAotSmoke.Activator_RpcActivatedValue( OrleansGeneratedCodeHelper.GetService(null!, provider)), @@ -28,16 +35,19 @@ public static void DefaultGraphsRespectConstructorDependencies() { calls++; return new(OrleansGeneratedCodeHelper.GetService>(null!, provider)); - }); + }, [typeof(IActivator)]); options.AddDefaultSerializerService, global::OrleansCodeGen.Orleans.NativeAotSmoke.Codec_RpcActivatedValue>( provider => OrleansGeneratedCodeHelper.GetService(null!, provider), dependencies: [typeof(IActivator)]); + if (!bridgeFirst) RegisterBridge(options); options.AddAllowedType(typeof(RpcActivatedValue)); }); using var services = collection.BuildServiceProvider(); var provider = services.GetRequiredService(); var codec = provider.GetCodec(); + var concrete = OrleansGeneratedCodeHelper.GetService(null!, provider); if (calls != 0 || codec is not global::OrleansCodeGen.Orleans.NativeAotSmoke.Codec_RpcActivatedValue + || concrete is null || !ReferenceEquals(codec, provider.GetCodec())) throw new InvalidOperationException("The inferred graph must decline arbitrary DI before canonical generated codec activation."); var serializer = services.GetRequiredService(); @@ -46,6 +56,10 @@ public static void DefaultGraphsRespectConstructorDependencies() if (result is null || result.Value != 59 || result.ConstructionValue != 47 || calls != 0) throw new InvalidOperationException("The rooted generated codec and activator must construct through ordinary native metadata dispatch."); } + + private static void RegisterBridge(TypeManifestOptions options) + => options.AddDefaultSerializerService>( + provider => provider.GetCodec(), [typeof(IActivator)]); } public sealed class RpcConstructorDependency diff --git a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs index 453d658f2cc..e9944d2b12b 100644 --- a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs +++ b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs @@ -238,12 +238,17 @@ public void LegacyJitDictionaryResponsesPreserveCustomComparers() } [Theory] - [InlineData("None", false)] - [InlineData("ImplementationType", false)] - [InlineData("ImplementationFactory", false)] - [InlineData("Instance", true)] - [InlineData("SerializerFactory", true)] - public void DefaultFactoryConstructorDependenciesRespectPublicationBoundary(string registration, bool eligible) + [InlineData("None", false, false)] + [InlineData("None", false, true)] + [InlineData("ImplementationType", false, false)] + [InlineData("ImplementationType", false, true)] + [InlineData("ImplementationFactory", false, false)] + [InlineData("ImplementationFactory", false, true)] + [InlineData("Instance", true, false)] + [InlineData("Instance", true, true)] + [InlineData("SerializerFactory", true, false)] + [InlineData("SerializerFactory", true, true)] + public void DefaultFactoryConstructorDependenciesRespectPublicationBoundary(string registration, bool eligible, bool bridgeFirst) { var dependency = new FactoryDependency(); var codec = new Int32Codec(); @@ -264,27 +269,39 @@ public void DefaultFactoryConstructorDependenciesRespectPublicationBoundary(stri provider => new(OrleansGeneratedCodeHelper.GetService(null!, provider)), bridgeDependencies); bridgeDependencies[0] = typeof(InvalidOperationException); - options.AddDefaultSerializer>(provider => + if (bridgeFirst) RegisterBridge(options); + options.AddDefaultSerializerService(provider => { calls++; var bridge = OrleansGeneratedCodeHelper.GetService(null!, provider); Assert.Same(dependency, bridge.Service.Dependency); return codec; - }, static _ => new ShallowCopier(), codecDependencies: [typeof(ConstructorBridge)]); + }, [typeof(ConstructorBridge)]); + options.AddDefaultSerializer>( + provider => OrleansGeneratedCodeHelper.GetService(null!, provider), + static _ => new ShallowCopier(), codecDependencies: [typeof(ConstructorBridge)]); + if (!bridgeFirst) RegisterBridge(options); }).AddSerializer().BuildServiceProvider(); var provider = services.GetRequiredService(); var result = provider.GetCodec(); + var concrete = OrleansGeneratedCodeHelper.GetService(null!, provider); Assert.Equal(eligible ? 1 : 0, calls); if (eligible) { Assert.Same(codec, result); + Assert.Same(codec, concrete); Assert.Same(dependency, OrleansGeneratedCodeHelper.GetService(null!, provider).Dependency); } else { Assert.IsType(result); Assert.NotSame(codec, result); + Assert.NotSame(codec, concrete); } + + void RegisterBridge(TypeManifestOptions options) + => options.AddDefaultSerializerService>( + _ => codec, [typeof(ConstructorBridge)]); } private sealed class FactoryDependency; From 01e829bcdef3266000f05a56792c14db77bf7218 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Fri, 2 Oct 2026 21:50:45 -0700 Subject: [PATCH 25/54] fix(codegen): specialize canonical generic constructor contracts --- .../SerializerFactoryGenerator.cs | 25 +++++++++-- .../OrleansSourceGeneratorTests.cs | 42 +++++++++++++++++++ 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs b/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs index 7b236024349..901026f59da 100644 --- a/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs +++ b/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs @@ -99,10 +99,14 @@ internal sealed record Failure(ITypeSymbol Type, string Reason); var copierDependencies = new List(); if (SymbolEqualityComparer.Default.Equals(type.ContainingAssembly, services.Compilation.Assembly)) { - var model = constructionModel; + var model = type.IsGenericType + ? SerializableSourceOutputGenerator.CreateSerializableTypeDescription(services, type.OriginalDefinition)! + : constructionModel; DescribeGeneratedModel(registration, type, model); - var codecDeclaration = new SerializerGenerator(services).Generate(model); + var codecDeclaration = SpecializeGeneratedSyntax(new SerializerGenerator(services).Generate(model), model, type); var copierDeclaration = new CopierGenerator(services).GenerateCopier(model, new()); + if (copierDeclaration is not null) + copierDeclaration = SpecializeGeneratedSyntax(copierDeclaration, model, type); registration.CodecConstruction = ConstructGenerated(registration.Codec, codecDeclaration); registration.CopierConstruction = copierDeclaration is null ? $"new {registration.Copier}()" @@ -195,7 +199,10 @@ internal sealed record Failure(ITypeSymbol Type, string Reason); && SymbolEqualityComparer.Default.Equals(type.ContainingAssembly, services.Compilation.Assembly)) { var activatorName = $"global::{constructionModel.GeneratedNamespace}.{ActivatorGenerator.GetSimpleClassName(constructionModel)}"; - var activator = new ActivatorGenerator(services).GenerateActivator(constructionModel); + var activatorModel = type.IsGenericType + ? SerializableSourceOutputGenerator.CreateSerializableTypeDescription(services, type.OriginalDefinition)! + : constructionModel; + var activator = SpecializeGeneratedSyntax(new ActivatorGenerator(services).GenerateActivator(activatorModel), activatorModel, type); result.Append("options.AddDefaultSerializerService, ").Append(activatorName).Append(">(static provider => ") .Append(ConstructGenerated(activatorName, activator)) @@ -935,6 +942,18 @@ private static string ConstructGenerated(string name, ClassDeclarationSyntax dec return $"new {name}({string.Join(", ", arguments)})"; } + private static TSyntax SpecializeGeneratedSyntax(TSyntax syntax, ISerializableTypeDescription definition, INamedTypeSymbol type) + where TSyntax : SyntaxNode + { + var substitutions = definition.TypeParameters + .Zip(type.GetAllTypeArguments(), static (parameter, argument) => (parameter.Parameter.Name, Type: argument.ToTypeSyntax())) + .ToDictionary(static entry => entry.Name, static entry => entry.Type, StringComparer.Ordinal); + return syntax.ReplaceNodes(syntax.DescendantNodesAndSelf().OfType() + .Where(identifier => identifier.Parent is not QualifiedNameSyntax and not AliasQualifiedNameSyntax + && substitutions.ContainsKey(identifier.Identifier.ValueText)), + (original, _) => substitutions[original.Identifier.ValueText]); + } + private static Failure? AppendTypeMetadata(StringBuilder result, ITypeSymbol symbol, LibraryTypes library, HashSet visited, int depth = 0) { if (visited.Contains(symbol)) return null; diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index dd06c47a853..c536d861acc 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -2373,6 +2373,48 @@ public sealed class Payload Assert.Contains(strict.Diagnostics, static diagnostic => diagnostic.Id == "ORLEANS0116"); } + [Theory] + [InlineData("string")] + [InlineData("int")] + public async Task RpcClosedGenericModelFactoriesUseDefinitionConstructorContracts(string argument) + { + var compilation = await CreateCompilation(""" + using Orleans; + namespace GenericConstruction; + [GenerateSerializer] + public sealed class Payload + { + [Id(0)] private T _value; + public Payload(T value) => _value = value; + public T Value => _value; + } + """); + var definition = compilation.GetTypeByMetadataName("GenericConstruction.Payload`1")!; + var parameter = compilation.GetSpecialType(argument == "string" ? SpecialType.System_String : SpecialType.System_Int32); + var graph = SerializerFactoryGenerator.CreateRpcModelRoot(new GeneratorServices(compilation, new CodeGeneratorOptions()), + definition.Construct(parameter), TestContext.Current.CancellationToken); + Assert.NotNull(graph); + Assert.Contains($"IActivator>", graph.ConfigurationStatements); + Assert.Contains("provider), provider)", graph.ConfigurationStatements); + Assert.DoesNotContain("Payload", graph.ConfigurationStatements); + var generated = RunSourceGenerator(compilation); + Assert.Empty(generated.Diagnostics); + var exercise = $$""" + public sealed class GenericConstructionContext : Orleans.Serialization.SerializerContext + { + protected override void ConfigureInner(Orleans.Serialization.Configuration.TypeManifestOptions options) + { + {{graph.ConfigurationStatements}} + } + } + """; + compilation = compilation.AddReferences(MetadataReference.CreateFromFile(typeof(Microsoft.Extensions.Options.IConfigureOptions<>).Assembly.Location)) + .AddSyntaxTrees(generated.GeneratedSources.Select(static source => CSharpSyntaxTree.ParseText(source.SourceText, path: source.HintName))) + .AddSyntaxTrees(CSharpSyntaxTree.ParseText(exercise, cancellationToken: TestContext.Current.CancellationToken)); + Assert.Empty(compilation.GetDiagnostics(TestContext.Current.CancellationToken) + .Where(static diagnostic => diagnostic.Severity == DiagnosticSeverity.Error)); + } + [Theory] [InlineData(false)] [InlineData(true)] From 51ae885bf1dae17bfbcae8742b0dd75fb9e4e898 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Fri, 2 Oct 2026 22:57:13 -0700 Subject: [PATCH 26/54] fix(codegen): diagnose aggregate RPC graph admission failures --- .../docs/implementation/serialization.md | 2 + .../RpcResponseGenerator.cs | 9 +-- .../OrleansSourceGeneratorTests.cs | 67 +++++++++++++++++++ 3 files changed, 71 insertions(+), 7 deletions(-) diff --git a/docs/site/src/content/docs/implementation/serialization.md b/docs/site/src/content/docs/implementation/serialization.md index e737051594f..6b9c79629e0 100644 --- a/docs/site/src/content/docs/implementation/serialization.md +++ b/docs/site/src/content/docs/implementation/serialization.md @@ -157,6 +157,8 @@ The same collector closes source-known argument construction dependencies select `OrleansValidateRpcResponseFactories` enables compile-time validation of the response graph and defaults to the executable project's `PublishAot` setting. Diagnostic `ORLEANS0116` identifies an unresolved generic result, a custom return adapter requiring an explicit response contract, or a result dependency outside the supported finite graph. Applications with runtime-selected generic results register every permitted closed graph explicitly through and in a , and set `OrleansValidateRpcResponseFactories=false` for the project supplying that contract. A missing native response registration reports the closed response type and requested serialization service at lookup. +The combined inferred response graph supports up to 1,024 closed types. A larger union produces `ORLEANS0116` in both managed and native builds, even when each method's graph fits individually. The generator retains response holder declarations so the size diagnostic identifies the admission failure directly. + Dictionary results and dictionary members require an explicit closed registration which preserves the application's comparer contract. A dictionary's comparer is selected per value, so the method's declared result type alone supplies the key/value shape while the registration supplies comparer serialization and copying. The focused .NET 10 NativeAOT smoke exercises the generated response graph for boolean, integer, and reference results, including recursive factory dependencies and payload identity. Full silo startup and RPC execution additionally require the native support for activation, request serialization, grain references, and runtime metadata. Managed .NET 8 tests exercise JIT compatibility and compiled-reference contracts. diff --git a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs index c9d97991df4..a94c22aec66 100644 --- a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs +++ b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs @@ -183,13 +183,8 @@ internal static ImmutableArray Generate( SerializerFactoryGenerator.Graph? graph = null; if (supportedResults.Count > 0 && !SerializerFactoryGenerator.TryCreate(services, supportedResults.Select(type => responseDefinition.Construct(type)), cancellationToken, out graph, out var graphFailure, useDefaultFactories: true)) { - if (options.ValidateRpcResponseFactories) - { - output.Add(SourceOutputResult.FromDiagnostic(Diagnostic.Create( - UnsupportedResponse, Location.None, compilation.AssemblyName, graphFailure.Type.ToDisplayString(), graphFailure.Reason))); - } - - return output.ToImmutable(); + output.Add(SourceOutputResult.FromDiagnostic(Diagnostic.Create( + UnsupportedResponse, Location.None, compilation.AssemblyName, graphFailure.Type.ToDisplayString(), graphFailure.Reason))); } var generatedNamespace = $"{GeneratedCodeUtilities.CodeGeneratorName}.{Identifier.SanitizeIdentifierName(compilation.AssemblyName ?? "Assembly").EscapeIdentifier()}"; diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index c536d861acc..ef4284e3fdd 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -2373,6 +2373,73 @@ public sealed class Payload Assert.Contains(strict.Diagnostics, static diagnostic => diagnostic.Id == "ORLEANS0116"); } + [Theory] + [InlineData(510, false)] + [InlineData(510, true)] + [InlineData(511, false)] + [InlineData(511, true)] + public async Task RpcCombinedGraphLimitKeepsHolderDeclarations(int membersPerResult, bool validateFactories) + { + var source = new System.Text.StringBuilder(""" + using Orleans; + using System.Threading.Tasks; + namespace CombinedGraph; + [GenerateSerializer] public sealed class Tag { } + public interface IContract : IGrainWithIntegerKey + { + Task ReadFirst(); + Task ReadSecond(); + } + """); + foreach (var name in new[] { "First", "Second" }) + { + for (var index = 0; index < membersPerResult; index++) + source.AppendLine($"public sealed class {name}Marker{index} {{ }}"); + source.AppendLine($"[GenerateSerializer] public sealed class {name} {{"); + for (var index = 0; index < membersPerResult; index++) + source.AppendLine($"[Id({index})] public Tag<{name}Marker{index}> Member{index} {{ get; set; }}"); + source.AppendLine("}"); + } + var compilation = await CreateCompilation(source.ToString()); + var services = new GeneratorServices(compilation, new CodeGeneratorOptions()); + var response = compilation.GetTypeByMetadataName("Orleans.Serialization.Invocation.Response`1")!; + foreach (var name in new[] { "First", "Second" }) + { + var resultType = compilation.GetTypeByMetadataName($"CombinedGraph.{name}")!; + Assert.True(SerializerFactoryGenerator.TryCreate(services, [response.Construct(resultType)], + TestContext.Current.CancellationToken, out var individual, out var failure), failure?.Reason); + Assert.Equal(membersPerResult + 2, individual.Registrations.Count); + } + if (membersPerResult == 510) + { + Assert.True(SerializerFactoryGenerator.TryCreate(services, + new[] { "First", "Second" }.Select(name => response.Construct(compilation.GetTypeByMetadataName($"CombinedGraph.{name}")!)), + TestContext.Current.CancellationToken, out var combined, out var failure), failure?.Reason); + Assert.Equal(1024, combined.Registrations.Count); + } + var result = RunSourceGenerator(compilation, new Dictionary + { + ["build_property.OrleansValidateRpcResponseFactories"] = validateFactories.ToString() + }); + var errors = result.Diagnostics.Where(static diagnostic => diagnostic.Severity == DiagnosticSeverity.Error).ToArray(); + if (membersPerResult == 510) + { + Assert.Empty(errors); + } + else + { + var diagnostic = Assert.Single(errors); + Assert.Equal("ORLEANS0116", diagnostic.Id); + Assert.Contains("exceeds 1024 closed types", diagnostic.GetMessage()); + } + Assert.Contains(result.GeneratedSources, static entry => entry.HintName.EndsWith(".orleans.rpcresponses.g.cs", StringComparison.Ordinal)); + compilation = compilation.AddReferences(MetadataReference.CreateFromFile(typeof(Microsoft.Extensions.Options.IConfigureOptions<>).Assembly.Location)) + .AddSyntaxTrees(result.GeneratedSources.Select(static entry => CSharpSyntaxTree.ParseText(entry.SourceText, + options: new CSharpParseOptions(preprocessorSymbols: ["NET5_0_OR_GREATER"]), path: entry.HintName))); + Assert.Empty(compilation.GetDiagnostics(TestContext.Current.CancellationToken) + .Where(static diagnostic => diagnostic.Severity == DiagnosticSeverity.Error)); + } + [Theory] [InlineData("string")] [InlineData("int")] From 4b5836daec36dab882a12a108dacda96a660982c Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Sat, 3 Oct 2026 00:53:54 -0700 Subject: [PATCH 27/54] fix(messaging): restrict raw response writers to response bodies --- .../SelfWritingResponseMessageTests.cs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/Orleans.Core.Tests/Serialization/SelfWritingResponseMessageTests.cs b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseMessageTests.cs index 60f2fe6e1db..8ad7339f409 100644 --- a/test/Orleans.Core.Tests/Serialization/SelfWritingResponseMessageTests.cs +++ b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseMessageTests.cs @@ -72,6 +72,26 @@ public void Write_UnregisteredHolder_InvokesRawWriterWithoutRuntimeCodecLookup() AssertHeaders(message, received); } + [Fact] + public void Write_RequestImplementingRawWriter_PreservesOrdinaryRequestFrame() + { + using var environment = new SerializationEnvironment(); + var body = new RequestWithRawWriter { Value = 47 }; + var message = CreateMessage(Response.Completed); + message.BodyObject = body; + message.Direction = Message.Directions.Request; + + var frame = WriteFrame(environment.Serializer, message); + var received = ReadFrame(environment.Serializer, frame); + + Assert.Equal(0, body.WriteCount); + Assert.Equal(Message.ResponseTypes.None, message.Result); + Assert.Equal(Message.Directions.Request, received.Direction); + Assert.Equal(Message.ResponseTypes.None, received.Result); + Assert.Equal(47, Assert.IsType(received.BodyObject).Value); + AssertHeaders(message, received); + } + [Fact] public void Read_RegisteredReader_IsCachedBeforeLegacyResponseCodecLookup() { @@ -396,6 +416,22 @@ private sealed class LookupCounts public int LegacyCodecLookups; } + [GenerateSerializer] + public sealed class RequestWithRawWriter : IRawResponseWriter + { + [Id(0)] + public int Value { get; set; } + + [NonSerialized] + public int WriteCount; + + public void WriteRaw(ref Writer writer) where TBufferWriter : IBufferWriter + { + WriteCount++; + throw new InvalidOperationException("A request body uses its ordinary field codec."); + } + } + private sealed class CountingRawReader(TCodec codec) : IRawResponseReader where TCodec : class, IFieldCodec { From 0920a0adb75a3fb44d9cfa12fb432bf1c8ef2e94 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Sat, 3 Oct 2026 01:33:09 -0700 Subject: [PATCH 28/54] fix(codegen): disambiguate generated RPC response names --- .../InvokableGenerator.cs | 5 +- .../OrleansSourceGenerator.cs | 13 +- .../ProxyGenerationContext.cs | 18 +- .../ProxySourceOutputGenerator.cs | 10 +- .../RpcResponseGenerator.cs | 8 +- .../RpcResponseHolderGenerator.cs | 67 +++++- .../RpcResponseHolderNamingTests.cs | 203 ++++++++++++++++++ 7 files changed, 306 insertions(+), 18 deletions(-) create mode 100644 test/Orleans.CodeGenerator.Tests/RpcResponseHolderNamingTests.cs diff --git a/src/Orleans.CodeGenerator/InvokableGenerator.cs b/src/Orleans.CodeGenerator/InvokableGenerator.cs index fbcf7c3f4f1..3db90b5b4f8 100644 --- a/src/Orleans.CodeGenerator/InvokableGenerator.cs +++ b/src/Orleans.CodeGenerator/InvokableGenerator.cs @@ -156,10 +156,11 @@ private ClassDeclarationSyntax GetClassDeclarationSyntax( if (method.AllTypeParameters.Count == 0 && method.Method.ReturnType is INamedTypeSymbol { TypeArguments.Length: 1 } result && baseClassType.OriginalDefinition.ToDisplayString() is "Orleans.Runtime.TaskRequest" or "Orleans.Runtime.Request" - && RpcResponseHolderGenerator.TryDescribe(_generationContext, result.TypeArguments[0], out _, out _)) + && _generationContext.RpcResponseNames.TryGetValue( + result.TypeArguments[0].ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat), out var responseName)) { var type = result.TypeArguments[0].ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); - var factory = $"global::{RpcResponseHolderGenerator.GetNamespace(_generationContext.Compilation)}.{RpcResponseHolderGenerator.GetName(result.TypeArguments[0])}Factory"; + var factory = $"global::{RpcResponseHolderGenerator.GetNamespace(_generationContext.Compilation)}.{responseName}Factory"; classDeclaration = classDeclaration.AddBaseListTypes(SimpleBaseType(ParseTypeName("global::Orleans.Serialization.Invocation.IResponseInvokable"))); classDeclaration = classDeclaration.AddMembers(ParseMemberDeclaration($$""" async global::System.Threading.Tasks.ValueTask diff --git a/src/Orleans.CodeGenerator/OrleansSourceGenerator.cs b/src/Orleans.CodeGenerator/OrleansSourceGenerator.cs index 82394edf7fb..777cfc0e22b 100644 --- a/src/Orleans.CodeGenerator/OrleansSourceGenerator.cs +++ b/src/Orleans.CodeGenerator/OrleansSourceGenerator.cs @@ -151,10 +151,18 @@ public void Initialize(IncrementalGeneratorInitializationContext context) .Select(static (input, _) => ModelExtractor.MergeProxyInterfaces(input.Left, input.Right.ReferencedProxyInterfaces)) .WithComparer(ImmutableArrayComparer.Instance); + var responseNames = allProxyInterfaces + .Combine(compilationProvider) + .Combine(generatorOptions) + .Select(static (input, ct) => RpcResponseHolderGenerator.GetNames(input.Left.Right, input.Left.Left, input.Right, ct)) + .WithComparer(ImmutableArrayComparer<(string TypeName, string HolderName)>.Instance); + var preparedProxyOutputs = allProxyInterfaces .Combine(compilationProvider) .Combine(generatorOptions) - .Select(static (input, ct) => ProxySourceOutputGenerator.CreateProxyOutputPreparation(input.Left.Right, input.Left.Left, input.Right, ct)) + .Combine(responseNames) + .Select(static (input, ct) => ProxySourceOutputGenerator.CreateProxyOutputPreparation( + input.Left.Left.Right, input.Left.Left.Left, input.Left.Right, input.Right, ct)) .WithTrackingName(PreparedProxyOutputsTrackingName); context.RegisterSourceOutput(preparedProxyOutputs, static (productionContext, input) => @@ -224,8 +232,9 @@ public void Initialize(IncrementalGeneratorInitializationContext context) var responseOutputs = preparedProxyOutputModels .Combine(compilationProvider) .Combine(generatorOptions) + .Combine(responseNames) .SelectMany(static (input, ct) => RpcResponseGenerator.Generate( - input.Left.Right, input.Left.Left, input.Right, ct)); + input.Left.Left.Right, input.Left.Left.Left, input.Left.Right, input.Right, ct)); context.RegisterSourceOutput(responseOutputs, static (productionContext, input) => { diff --git a/src/Orleans.CodeGenerator/ProxyGenerationContext.cs b/src/Orleans.CodeGenerator/ProxyGenerationContext.cs index 7a4501e27ff..763b78e047e 100644 --- a/src/Orleans.CodeGenerator/ProxyGenerationContext.cs +++ b/src/Orleans.CodeGenerator/ProxyGenerationContext.cs @@ -18,15 +18,28 @@ internal sealed class ProxyGenerationContext : IGeneratorServices private readonly Dictionary _interfaceProxyBases = new(SymbolEqualityComparer.Default); internal ProxyGenerationContext(Compilation compilation, CodeGeneratorOptions options) - : this(compilation, options, LibraryTypes.FromCompilation(compilation, options)) + : this(compilation, options, LibraryTypes.FromCompilation(compilation, options), []) { } - internal ProxyGenerationContext(Compilation compilation, CodeGeneratorOptions options, LibraryTypes libraryTypes) + internal ProxyGenerationContext( + Compilation compilation, + CodeGeneratorOptions options, + ImmutableArray<(string TypeName, string HolderName)> responseNames) + : this(compilation, options, LibraryTypes.FromCompilation(compilation, options), responseNames) + { + } + + internal ProxyGenerationContext( + Compilation compilation, + CodeGeneratorOptions options, + LibraryTypes libraryTypes, + ImmutableArray<(string TypeName, string HolderName)> responseNames) { Compilation = compilation ?? throw new ArgumentNullException(nameof(compilation)); Options = options ?? throw new ArgumentNullException(nameof(options)); LibraryTypes = libraryTypes ?? throw new ArgumentNullException(nameof(libraryTypes)); + RpcResponseNames = responseNames.ToDictionary(static entry => entry.TypeName, static entry => entry.HolderName, StringComparer.Ordinal); InvokableBaseTypeResolver = new InvokableBaseTypeResolver(compilation); MetadataModel = new MetadataModel(); ProxyGenerator = new ProxyGenerator(this, new CopierGenerator(this)); @@ -41,6 +54,7 @@ internal ProxyGenerationContext(Compilation compilation, CodeGeneratorOptions op internal MetadataModel MetadataModel { get; } internal ProxyGenerator ProxyGenerator { get; } internal InvokableGenerator InvokableGenerator { get; } + internal IReadOnlyDictionary RpcResponseNames { get; } internal void AddMember(string ns, MemberDeclarationSyntax member) { diff --git a/src/Orleans.CodeGenerator/ProxySourceOutputGenerator.cs b/src/Orleans.CodeGenerator/ProxySourceOutputGenerator.cs index 817e419c3ce..ddf29ca9166 100644 --- a/src/Orleans.CodeGenerator/ProxySourceOutputGenerator.cs +++ b/src/Orleans.CodeGenerator/ProxySourceOutputGenerator.cs @@ -13,6 +13,7 @@ internal static SourceOutputResult CreateProxySourceOutput( TypeSymbolResolver resolver, ProxyOutputModel proxyOutputModel, SourceGeneratorOptions options, + ImmutableArray<(string TypeName, string HolderName)> responseNames, CancellationToken cancellationToken) { try @@ -20,7 +21,7 @@ internal static SourceOutputResult CreateProxySourceOutput( SourceGeneratorOptionsParser.AttachDebuggerIfRequested(options); var codeGeneratorOptions = SourceGeneratorOptionsParser.CreateCodeGeneratorOptions(options); var generatorServices = new GeneratorServices(compilation, codeGeneratorOptions); - var proxyContext = new ProxyGenerationContext(compilation, codeGeneratorOptions); + var proxyContext = new ProxyGenerationContext(compilation, codeGeneratorOptions, responseNames); var model = proxyOutputModel.ProxyInterface; PopulateProxyInterfaces(proxyContext, resolver, [model], cancellationToken); @@ -177,6 +178,7 @@ internal static ProxyOutputPreparationResult CreateProxyOutputPreparation( Compilation compilation, ImmutableArray models, SourceGeneratorOptions options, + ImmutableArray<(string TypeName, string HolderName)> responseNames, CancellationToken cancellationToken) { try @@ -191,7 +193,7 @@ internal static ProxyOutputPreparationResult CreateProxyOutputPreparation( var codeGeneratorOptions = SourceGeneratorOptionsParser.CreateCodeGeneratorOptions(options); var libraryTypes = LibraryTypes.FromCompilation(compilation, codeGeneratorOptions); var generatorServices = new GeneratorServices(compilation, codeGeneratorOptions, libraryTypes); - var proxyContext = new ProxyGenerationContext(compilation, codeGeneratorOptions, libraryTypes); + var proxyContext = new ProxyGenerationContext(compilation, codeGeneratorOptions, libraryTypes, responseNames); var resolver = new TypeSymbolResolver(compilation); PopulateProxyInterfaces(proxyContext, resolver, models, cancellationToken); @@ -212,6 +214,7 @@ internal static ProxyOutputPreparationResult CreateProxyOutputPreparation( resolver, proxyOutputModels, options, + responseNames, cancellationToken), diagnostics); } @@ -232,6 +235,7 @@ internal static ImmutableArray CreateProxySourceOutputs( TypeSymbolResolver resolver, ImmutableArray proxyOutputModels, SourceGeneratorOptions options, + ImmutableArray<(string TypeName, string HolderName)> responseNames, CancellationToken cancellationToken) { if (proxyOutputModels.IsDefaultOrEmpty) @@ -245,7 +249,7 @@ internal static ImmutableArray CreateProxySourceOutputs( foreach (var proxyOutputModel in proxyOutputModels) { cancellationToken.ThrowIfCancellationRequested(); - sourceOutputs.Add(CreateProxySourceOutput(compilation, resolver, proxyOutputModel, options, cancellationToken)); + sourceOutputs.Add(CreateProxySourceOutput(compilation, resolver, proxyOutputModel, options, responseNames, cancellationToken)); } } else diff --git a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs index a94c22aec66..1f7deb40d53 100644 --- a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs +++ b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs @@ -23,6 +23,7 @@ internal static ImmutableArray Generate( Compilation compilation, ImmutableArray proxies, SourceGeneratorOptions options, + ImmutableArray<(string TypeName, string HolderName)> responseNames, CancellationToken cancellationToken) { if (proxies.IsDefaultOrEmpty) @@ -33,7 +34,7 @@ internal static ImmutableArray Generate( var services = new GeneratorServices(compilation, SourceGeneratorOptionsParser.CreateCodeGeneratorOptions(options)); var responseDefinition = compilation.GetTypeByMetadataName("Orleans.Serialization.Invocation.Response`1")!; var resolver = new TypeSymbolResolver(compilation); - var proxyContext = new ProxyGenerationContext(compilation, SourceGeneratorOptionsParser.CreateCodeGeneratorOptions(options)); + var proxyContext = new ProxyGenerationContext(compilation, SourceGeneratorOptionsParser.CreateCodeGeneratorOptions(options), responseNames); ProxySourceOutputGenerator.PopulateProxyInterfaces(proxyContext, resolver, proxies.Select(static proxy => proxy.ProxyInterface).ToImmutableArray(), cancellationToken); var binding = compilation.GetSemanticModel(compilation.SyntaxTrees.First()); @@ -202,7 +203,7 @@ internal static ImmutableArray Generate( source.AppendLine("{"); foreach (var holder in responseHolders) { - var name = RpcResponseHolderGenerator.GetName(holder.Key); + var name = proxyContext.RpcResponseNames[holder.Key.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)]; var factory = name + "Factory"; var type = holder.Key.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); var resolve = $"{factory}.Resolve(provider)"; @@ -269,7 +270,8 @@ internal static ImmutableArray Generate( source.AppendLine("}"); foreach (var holder in responseHolders) { - source.AppendLine(RpcResponseHolderGenerator.Generate(services, holder.Key, holder.Value.Codec, holder.Value.Copier)); + var name = proxyContext.RpcResponseNames[holder.Key.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)]; + source.AppendLine(RpcResponseHolderGenerator.Generate(services, holder.Key, name, holder.Value.Codec, holder.Value.Copier)); } source.AppendLine("}"); var unit = CSharpSyntaxTree.ParseText(source.ToString(), diff --git a/src/Orleans.CodeGenerator/RpcResponseHolderGenerator.cs b/src/Orleans.CodeGenerator/RpcResponseHolderGenerator.cs index 4b6f6530db7..ec27be40d5f 100644 --- a/src/Orleans.CodeGenerator/RpcResponseHolderGenerator.cs +++ b/src/Orleans.CodeGenerator/RpcResponseHolderGenerator.cs @@ -1,14 +1,70 @@ -using System.Text; +using System.Collections.Immutable; +using System.Globalization; using Microsoft.CodeAnalysis; -using Orleans.CodeGenerator.Hashing; +using Orleans.CodeGenerator.Model; using Orleans.CodeGenerator.SyntaxGeneration; namespace Orleans.CodeGenerator; internal static class RpcResponseHolderGenerator { - internal static string GetName(ITypeSymbol resultType) - => $"RpcResponse_{HexConverter.ToString(XxHash32.Hash(Encoding.UTF8.GetBytes(resultType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat))))}"; + internal static ImmutableArray<(string TypeName, string HolderName)> GetNames( + Compilation compilation, + ImmutableArray proxies, + SourceGeneratorOptions options, + CancellationToken cancellationToken) + { + if (proxies.IsDefaultOrEmpty) + { + return []; + } + + var services = new GeneratorServices(compilation, SourceGeneratorOptionsParser.CreateCodeGeneratorOptions(options)); + var resolver = new TypeSymbolResolver(compilation); + var resultTypes = new HashSet(SymbolEqualityComparer.Default); + foreach (var proxy in proxies) + { + cancellationToken.ThrowIfCancellationRequested(); + if (!resolver.TryResolveProxyInterface(proxy, cancellationToken, out var interfaceType)) + { + continue; + } + + foreach (var method in interfaceType.GetDeclaredInstanceMembers() + .Concat(interfaceType.AllInterfaces.SelectMany(static type => type.GetDeclaredInstanceMembers()))) + { + if (method.MethodKind == MethodKind.Ordinary + && method.ReturnType is INamedTypeSymbol { TypeArguments.Length: 1 } returnType + && (SymbolEqualityComparer.Default.Equals(returnType.OriginalDefinition, services.LibraryTypes.Task_1) + || SymbolEqualityComparer.Default.Equals(returnType.OriginalDefinition, services.LibraryTypes.ValueTask_1))) + { + resultTypes.Add(returnType.TypeArguments[0].WithNullableAnnotation(NullableAnnotation.None)); + } + } + } + + return GetNames(resultTypes.Where(type => TryDescribe(services, type, out _, out _)) + .Select(static type => type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat))); + } + + internal static ImmutableArray<(string TypeName, string HolderName)> GetNames(IEnumerable resultTypeNames) + { + var names = ImmutableArray.CreateBuilder<(string TypeName, string HolderName)>(); + var usedNames = new HashSet(StringComparer.Ordinal); + foreach (var typeName in resultTypeNames.Distinct(StringComparer.Ordinal).OrderBy(static name => name, StringComparer.Ordinal)) + { + var baseName = $"RpcResponse_{GeneratedSourceOutput.CreateStableHash(typeName)}"; + var name = baseName; + for (var index = 1; !usedNames.Add(name); index++) + { + name = $"{baseName}_{index.ToString(CultureInfo.InvariantCulture)}"; + } + + names.Add((typeName, name)); + } + + return names.ToImmutable(); + } internal static string GetNamespace(Compilation compilation) => $"{GeneratedCodeUtilities.CodeGeneratorName}.{Identifier.SanitizeIdentifierName(compilation.AssemblyName ?? "Assembly").EscapeIdentifier()}"; @@ -46,10 +102,9 @@ internal static bool TryDescribe(IGeneratorServices services, ITypeSymbol result return false; } - internal static string Generate(IGeneratorServices services, ITypeSymbol resultType, string codec, string copier) + internal static string Generate(IGeneratorServices services, ITypeSymbol resultType, string name, string codec, string copier) { var type = resultType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); - var name = GetName(resultType); var factory = name + "Factory"; var shallow = services.LibraryTypes.IsShallowCopyable(resultType); var staticCodec = services.LibraryTypes.StaticCodecs.FindByUnderlyingType(resultType)?.CodecType; diff --git a/test/Orleans.CodeGenerator.Tests/RpcResponseHolderNamingTests.cs b/test/Orleans.CodeGenerator.Tests/RpcResponseHolderNamingTests.cs new file mode 100644 index 00000000000..132e397b878 --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/RpcResponseHolderNamingTests.cs @@ -0,0 +1,203 @@ +using System.Buffers; +using System.IO; +using System.Reflection; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.Extensions.DependencyInjection; +using Orleans.Serialization; +using Orleans.Serialization.Buffers; +using Orleans.Serialization.Cloning; +using Orleans.Serialization.Codecs; +using Orleans.Serialization.Invocation; +using Orleans.Serialization.Serializers; +using Orleans.Serialization.Session; + +namespace Orleans.CodeGenerator.Tests; + +[TestSuite("BVT")] +[TestProvider("None")] +[TestArea("CodeGen")] +public sealed class RpcResponseHolderNamingTests +{ + private const string FirstResult = """ + namespace TestProject; + [Orleans.GenerateSerializer] + public sealed class Response42799 { [Orleans.Id(0)] public int Value { get; set; } } + public interface IFirst : Orleans.IGrainWithIntegerKey + { + System.Threading.Tasks.Task First(); + } + """; + + private const string SecondResult = """ + namespace TestProject; + [Orleans.GenerateSerializer] + public sealed class Response123510 { [Orleans.Id(0)] public int Value { get; set; } } + public interface ISecond : Orleans.IGrainWithIntegerKey + { + System.Threading.Tasks.ValueTask Second(); + } + """; + + private const string Target = """ + namespace TestProject; + public sealed class CollisionTarget : IFirst, ISecond + { + public Response42799 FirstValue { get; } = new() { Value = 47 }; + public Response123510 SecondValue { get; } = new() { Value = 59 }; + public System.Threading.Tasks.Task First() => System.Threading.Tasks.Task.FromResult(FirstValue); + public System.Threading.Tasks.ValueTask Second() => new(SecondValue); + } + """; + + [Fact] + public void ResolvedNamesDisambiguateHashesAndPreserveNoncollidingNames() + { + string[] types = ["global::TestProject.Response42799", "string", "global::TestProject.Response123510"]; + var names = RpcResponseHolderGenerator.GetNames(types); + Assert.Equal( + [ + ("global::TestProject.Response123510", "RpcResponse_A633008A"), + ("global::TestProject.Response42799", "RpcResponse_A633008A_1"), + ("string", "RpcResponse_9146C7E3"), + ], + names); + Assert.Equal(names, RpcResponseHolderGenerator.GetNames(Enumerable.Reverse(types).Concat(types))); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task CollidingResultsCompileAndUseDistinctFactories(bool compatibilityInvokers) + { + var compilation = await CreateCompilation($"RpcResponseCollision{Guid.NewGuid():N}"); + var (result, output) = RunGenerator(compilation, compatibilityInvokers); + Assert.Empty(result.Diagnostics); + AssertNoErrors(output.GetDiagnostics(TestContext.Current.CancellationToken)); + using var image = new MemoryStream(); + var emit = output.Emit(image, cancellationToken: TestContext.Current.CancellationToken); + Assert.True(emit.Success, string.Join(Environment.NewLine, emit.Diagnostics)); + var assembly = Assembly.Load(image.ToArray()); + using var services = new ServiceCollection().AddSerializer(builder => builder.AddAssembly(assembly)).BuildServiceProvider(); + var provider = services.GetRequiredService(); + var contexts = services.GetRequiredService(); + var copier = services.GetRequiredService().GetCopier(); + var target = Activator.CreateInstance(assembly.GetType("TestProject.CollisionTarget")!); + var requests = assembly.GetTypes() + .Where(static type => typeof(IResponseInvokable).IsAssignableFrom(type)) + .Select(static type => (IInvokable)Activator.CreateInstance(type)!) + .OrderBy(static request => request.GetMethodName(), StringComparer.Ordinal) + .ToArray(); + Assert.Equal(2, requests.Length); + using var firstRequest = requests[0]; + using var secondRequest = requests[1]; + firstRequest.SetTarget(new TargetHolder(target!)); + secondRequest.SetTarget(new TargetHolder(target!)); + using var first = await ((IResponseInvokable)firstRequest).InvokeAndCopy(provider, contexts, copier); + using var second = await ((IResponseInvokable)secondRequest).InvokeAndCopy(provider, contexts, copier); + Assert.IsAssignableFrom(first); + Assert.IsAssignableFrom(second); + Assert.NotEqual(first.GetType(), second.GetType()); + Assert.NotSame(provider.GetCodec(first.GetType()), provider.GetCodec(second.GetType())); + Assert.True(provider.TryGetRawResponseReader(Assert.IsAssignableFrom(first.GetSimpleResultType()), out var firstReader)); + Assert.True(provider.TryGetRawResponseReader(Assert.IsAssignableFrom(second.GetSimpleResultType()), out var secondReader)); + Assert.NotSame(firstReader, secondReader); + Assert.NotEqual(firstReader.GetType(), secondReader.GetType()); + AssertCopiedPayload(first, target!, "FirstValue", "Response42799", 47); + AssertCopiedPayload(second, target!, "SecondValue", "Response123510", 59); + AssertRawRoundTrip(first, firstReader, services, 47); + AssertRawRoundTrip(second, secondReader, services, 59); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task ReorderedCollidingResultsProduceIdenticalSources(bool compatibilityInvokers) + { + var compilation = await CreateCompilation(); + var reversed = compilation.RemoveAllSyntaxTrees().AddSyntaxTrees(compilation.SyntaxTrees.Reverse()); + var (result, output) = RunGenerator(compilation, compatibilityInvokers); + var (reordered, reorderedOutput) = RunGenerator(reversed, compatibilityInvokers); + AssertNoErrors(output.GetDiagnostics(TestContext.Current.CancellationToken)); + AssertNoErrors(reorderedOutput.GetDiagnostics(TestContext.Current.CancellationToken)); + Assert.Equal( + result.GeneratedSources.OrderBy(static source => source.HintName, StringComparer.Ordinal) + .Select(static source => (source.HintName, Source: source.SourceText.ToString())), + reordered.GeneratedSources.OrderBy(static source => source.HintName, StringComparer.Ordinal) + .Select(static source => (source.HintName, Source: source.SourceText.ToString()))); + } + + private static async Task CreateCompilation(string assemblyName = "TestProject") + { + var compilation = await TestCompilationHelper.CreateCompilation(FirstResult, assemblyName); + return compilation.AddReferences( + MetadataReference.CreateFromFile(typeof(Microsoft.Extensions.Options.IConfigureOptions<>).Assembly.Location), + MetadataReference.CreateFromFile(typeof(ServiceProvider).Assembly.Location)) + .AddSyntaxTrees( + CSharpSyntaxTree.ParseText(SecondResult, cancellationToken: TestContext.Current.CancellationToken), + CSharpSyntaxTree.ParseText(Target, cancellationToken: TestContext.Current.CancellationToken)); + } + + private static (GeneratorRunResult Result, Compilation Output) RunGenerator(CSharpCompilation compilation, bool compatibilityInvokers) + { + GeneratorDriver driver = CSharpGeneratorDriver.Create( + generators: [new OrleansSerializationSourceGenerator().AsSourceGenerator()], + parseOptions: new CSharpParseOptions(preprocessorSymbols: ["NET5_0_OR_GREATER"]), + optionsProvider: TestCompilationHelper.CreateOptionsProvider(new Dictionary + { + ["build_property.OrleansGenerateCompatibilityInvokers"] = compatibilityInvokers.ToString(), + })); + driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out var output, out var diagnostics); + AssertNoErrors(diagnostics); + return (driver.GetRunResult().Results.Single(), output); + } + + private static void AssertCopiedPayload(Response response, object target, string property, string typeName, int expected) + { + Assert.Null(response.Exception); + var value = response.Result; + Assert.NotNull(value); + Assert.Equal(typeName, value.GetType().Name); + Assert.Equal(value.GetType(), response.GetSimpleResultType()); + Assert.Equal(expected, value.GetType().GetProperty("Value")!.GetValue(value)); + var original = target.GetType().GetProperty(property)!.GetValue(target); + Assert.NotSame(original, value); + value.GetType().GetProperty("Value")!.SetValue(original, -1); + Assert.Equal(expected, value.GetType().GetProperty("Value")!.GetValue(value)); + } + + private static void AssertRawRoundTrip(Response response, IRawResponseReader rawReader, ServiceProvider services, int expected) + { + var buffer = new ArrayBufferWriter(); + var sessions = services.GetRequiredService(); + using (var session = sessions.GetSession()) + { + var writer = Writer.Create(buffer, session); + ((IRawResponseWriter)response).WriteRaw(ref writer); + writer.Commit(); + } + + using var readerSession = sessions.GetSession(); + var reader = Reader.Create(buffer.WrittenMemory, readerSession); + var field = reader.ReadFieldHeader(); + Assert.Equal(response.GetSimpleResultType(), field.FieldType); + using var roundTrip = rawReader.ReadRaw(ref reader, ref field); + Assert.Equal(response.GetType(), roundTrip.GetType()); + Assert.Equal(response.GetSimpleResultType(), roundTrip.GetSimpleResultType()); + Assert.NotNull(roundTrip.Result); + Assert.Equal(expected, roundTrip.Result.GetType().GetProperty("Value")!.GetValue(roundTrip.Result)); + Assert.Equal(buffer.WrittenCount, reader.Position); + } + + private static void AssertNoErrors(IEnumerable diagnostics) + { + var errors = diagnostics.Where(static diagnostic => diagnostic.Severity == DiagnosticSeverity.Error).ToArray(); + Assert.True(errors.Length == 0, string.Join(Environment.NewLine, errors.Select(static error => error.ToString()))); + } + + private sealed class TargetHolder(object target) : ITargetHolder + { + public object GetTarget() => target; + public object? GetComponent(Type componentType) => componentType.IsInstanceOfType(target) ? target : null; + } +} From 6b476a41a1ffd7a95a78d27053d8cf02f30a031f Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Sat, 3 Oct 2026 02:27:02 -0700 Subject: [PATCH 29/54] fix(rpc): preserve isolated response ownership through send --- src/Orleans.Core/Core/GrainMethodInvoker.cs | 90 ++- src/Orleans.Core/Core/ResponseCopyBoundary.cs | 49 ++ src/Orleans.Core/Runtime/IRuntimeClient.cs | 3 + .../Runtime/InvokableObjectManager.cs | 74 +- .../Core/InsideRuntimeClient.cs | 84 ++- .../SelfWritingResponseOwnershipTests.cs | 685 ++++++++++++++++++ 6 files changed, 917 insertions(+), 68 deletions(-) create mode 100644 src/Orleans.Core/Core/ResponseCopyBoundary.cs create mode 100644 test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs diff --git a/src/Orleans.Core/Core/GrainMethodInvoker.cs b/src/Orleans.Core/Core/GrainMethodInvoker.cs index 126ecae08ca..99259e30862 100644 --- a/src/Orleans.Core/Core/GrainMethodInvoker.cs +++ b/src/Orleans.Core/Core/GrainMethodInvoker.cs @@ -14,7 +14,7 @@ namespace Orleans.Runtime /// /// Invokes a request on a grain. /// - internal sealed class GrainMethodInvoker : IIncomingGrainCallContext + internal sealed class GrainMethodInvoker : IIncomingGrainCallContext, IDisposable { private readonly Message message; private readonly IInvokable request; @@ -24,6 +24,9 @@ internal sealed class GrainMethodInvoker : IIncomingGrainCallContext private readonly IGrainContext grainContext; private readonly ICodecProvider codecProvider; private readonly CopyContextPool copyContexts; + private Response? ownedResponse; + private bool ownedResponseIsCopied; + private List<(Response Response, bool IsCopied)>? otherOwnedResponses; private int stage; /// @@ -77,6 +80,82 @@ public object? Result public Response? Response { get; set; } + internal (Response Response, bool IsCopied) TakeResponse() + { + var response = Response!; + var isCopied = false; + if (ReferenceEquals(response, ownedResponse)) + { + isCopied = ownedResponseIsCopied; + ownedResponse = null; + } + + if (otherOwnedResponses is { } others) + { + for (var i = others.Count - 1; i >= 0; i--) + { + if (ReferenceEquals(response, others[i].Response)) + { + isCopied = others[i].IsCopied; + others.RemoveAt(i); + } + } + } + + Response = null; + return (response, isCopied); + } + + public void Dispose() + { + var response = ownedResponse; + ownedResponse = null; + var current = Response; + Response = null; + try + { + if (current is not null && !ReferenceEquals(current, response) + && (otherOwnedResponses is null || !otherOwnedResponses.Exists(entry => ReferenceEquals(current, entry.Response)))) + { + current.Dispose(); + } + } + finally + { + try + { + response?.Dispose(); + } + finally + { + if (otherOwnedResponses is { } others) + { + otherOwnedResponses = null; + foreach (var entry in others) entry.Response.Dispose(); + } + } + } + } + + private void SetOwnedResponse(Response response, bool isCopied) + { + if (ownedResponse is { } previous && !ReferenceEquals(previous, response)) + { + (otherOwnedResponses ??= []).Add((previous, ownedResponseIsCopied)); + } + + if (otherOwnedResponses is { } others) + { + for (var i = others.Count - 1; i >= 0; i--) + { + if (ReferenceEquals(response, others[i].Response)) others.RemoveAt(i); + } + } + + ownedResponse = Response = response; + ownedResponseIsCopied = isCopied; + } + public GrainId? SourceId => message.SendingGrain is { IsDefault: false } source ? source : null; public IGrainContext TargetContext => grainContext; @@ -134,18 +213,21 @@ public async Task Invoke() { // Finally call the root-level invoker. stage++; - this.Response = request is IResponseInvokable direct + var response = request is IResponseInvokable direct ? await direct.InvokeAndCopy(codecProvider, copyContexts, responseCopier) : await request.Invoke(); // Propagate exceptions to other filters. - if (this.Response.Exception is { } exception) + if (response.Exception is { } exception) { + SetOwnedResponse(response, isCopied: false); ExceptionDispatchInfo.Capture(exception).Throw(); } if (request is not IResponseInvokable) - this.Response = this.responseCopier.Copy(this.Response); + response = ResponseCopyBoundary.CopyAndDispose(response, this.responseCopier); + + SetOwnedResponse(response, isCopied: true); return; } diff --git a/src/Orleans.Core/Core/ResponseCopyBoundary.cs b/src/Orleans.Core/Core/ResponseCopyBoundary.cs new file mode 100644 index 00000000000..2bb3eaff31a --- /dev/null +++ b/src/Orleans.Core/Core/ResponseCopyBoundary.cs @@ -0,0 +1,49 @@ +using System; +using System.Threading.Tasks; +using Orleans.Serialization; +using Orleans.Serialization.Cloning; +using Orleans.Serialization.Invocation; +using Orleans.Serialization.Serializers; + +namespace Orleans.Runtime; + +internal static class ResponseCopyBoundary +{ + internal static ValueTask InvokeAndCopy( + IInvokable request, + ICodecProvider codecProvider, + CopyContextPool copyContexts, + DeepCopier responseCopier) + => request is IResponseInvokable direct + ? direct.InvokeAndCopy(codecProvider, copyContexts, responseCopier) + : InvokeLegacy(request, responseCopier); + + private static async ValueTask InvokeLegacy(IInvokable request, DeepCopier responseCopier) + => CopyAndDispose(await request.Invoke(), responseCopier); + + internal static Response CopyAndDispose(Response response, DeepCopier copier) + { + Response? copy = null; + try + { + return copy = copier.Copy(response)!; + } + finally + { + if (!ReferenceEquals(response, copy)) response.Dispose(); + } + } + + internal static Response CopyAndDispose(Response response, DeepCopier copier) + { + Response? copy = null; + try + { + return copy = copier.Copy(response)!; + } + finally + { + if (!ReferenceEquals(response, copy)) response.Dispose(); + } + } +} diff --git a/src/Orleans.Core/Runtime/IRuntimeClient.cs b/src/Orleans.Core/Runtime/IRuntimeClient.cs index 746e7a317a7..ebc07a3d17b 100644 --- a/src/Orleans.Core/Runtime/IRuntimeClient.cs +++ b/src/Orleans.Core/Runtime/IRuntimeClient.cs @@ -46,6 +46,9 @@ internal interface IRuntimeClient void SendRequest(GrainReference target, IInvokable request, IResponseCompletionSource? context, InvokeMethodOptions options); + /// + /// Transfers the response to the messaging pipeline for delivery. + /// void SendResponse(Message request, Response response); void ReceiveResponse(Message message); diff --git a/src/Orleans.Core/Runtime/InvokableObjectManager.cs b/src/Orleans.Core/Runtime/InvokableObjectManager.cs index c48e1d30c1e..7dee0df5766 100644 --- a/src/Orleans.Core/Runtime/InvokableObjectManager.cs +++ b/src/Orleans.Core/Runtime/InvokableObjectManager.cs @@ -373,6 +373,7 @@ private async Task ProcessMessageAsync(Message message) return; } + Response? response = null; try { request.SetTarget(this); @@ -382,37 +383,38 @@ private async Task ProcessMessageAsync(Message message) } var filters = _manager.GrainCallFilters; - Response response; + bool isCopied; if (filters is { Count: > 0 } || LocalObject is IIncomingGrainCallFilter) { - var invoker = new GrainMethodInvoker(message, this, request, filters, _manager._interfaceToImplementationMapping, + using var invoker = new GrainMethodInvoker(message, this, request, filters, _manager._interfaceToImplementationMapping, _manager._responseCopier, _manager.runtimeClient.ServiceProvider.GetRequiredService(), _manager.runtimeClient.ServiceProvider.GetRequiredService()); await invoker.Invoke(); - response = invoker.Response!; + (response, isCopied) = invoker.TakeResponse(); } else { - if (request is IResponseInvokable direct) - response = await direct.InvokeAndCopy( - _manager.runtimeClient.ServiceProvider.GetRequiredService(), - _manager.runtimeClient.ServiceProvider.GetRequiredService(), _manager._responseCopier); - else - { - response = await request.Invoke(); - response = _manager._responseCopier.Copy(response)!; - } + response = await ResponseCopyBoundary.InvokeAndCopy(request, + _manager.runtimeClient.ServiceProvider.GetRequiredService(), + _manager.runtimeClient.ServiceProvider.GetRequiredService(), _manager._responseCopier); + isCopied = request is not IResponseInvokable || response.Exception is null; } if (message.Direction != Message.Directions.OneWay) { - this.SendResponseAsync(message, response); + var outgoing = response; + response = null; + this.SendResponseAsync(message, outgoing, isCopied); } } catch (Exception exc) { this.ReportException(message, exc); } + finally + { + response?.Dispose(); + } } catch (Exception outerException) { @@ -464,31 +466,39 @@ private bool TryCancelInvokable(IInvokable request) private void SendCanceledResponse(Message message) => _manager.runtimeClient.SendResponse(message, Response.FromException(new OperationCanceledException())); - private void SendResponseAsync(Message message, Response resultObject) + private void SendResponseAsync(Message message, Response resultObject, bool isCopied) { - if (message.IsExpired) - { - _manager.messagingTrace.OnDropExpiredMessage(message, MessagingInstruments.Phase.Respond); - return; - } - - Response deepCopy; + Response? response = resultObject; try { - // we're expected to notify the caller if the deep copy failed. - // The copier preserves the null state of its input. - deepCopy = _manager.deepCopier.Copy(resultObject)!; + if (message.IsExpired) + { + _manager.messagingTrace.OnDropExpiredMessage(message, MessagingInstruments.Phase.Respond); + return; + } + + if (!isCopied) + { + try + { + response = null; + response = ResponseCopyBoundary.CopyAndDispose(resultObject, _manager.deepCopier); + } + catch (Exception exc2) + { + _manager.runtimeClient.SendResponse(message, Response.FromException(exc2)); + LogErrorSendingResponse(_manager.logger, exc2); + return; + } + } + + _manager.runtimeClient.SendResponse(message, response); + response = null; } - catch (Exception exc2) + finally { - _manager.runtimeClient.SendResponse(message, Response.FromException(exc2)); - LogErrorSendingResponse(_manager.logger, exc2); - return; + response?.Dispose(); } - - // the deep-copy succeeded. - _manager.runtimeClient.SendResponse(message, deepCopy); - return; } private void ReportException(Message message, Exception exception) diff --git a/src/Orleans.Runtime/Core/InsideRuntimeClient.cs b/src/Orleans.Runtime/Core/InsideRuntimeClient.cs index 2b2a84a6576..b2bb5d579de 100644 --- a/src/Orleans.Runtime/Core/InsideRuntimeClient.cs +++ b/src/Orleans.Runtime/Core/InsideRuntimeClient.cs @@ -235,6 +235,7 @@ public void SendResponse(Message request, Response response) if (request.IsExpired) { this.messagingTrace.OnDropExpiredMessage(request, MessagingInstruments.Phase.Respond); + response.Dispose(); return; } @@ -309,7 +310,8 @@ public async Task Invoke(IGrainContext target, Message message) RequestContextExtensions.Import(message.RequestContextData); } - Response response; + Response? response = null; + var isCopied = false; try { switch (message.BodyObject) @@ -321,20 +323,16 @@ public async Task Invoke(IGrainContext target, Message message) CancellationSourcesExtension.RegisterCancellationTokens(target, invokable); if (GrainCallFilters is { Count: > 0 } || target.GrainInstance is IIncomingGrainCallFilter) { - var invoker = new GrainMethodInvoker(message, target, invokable, GrainCallFilters, this.interfaceToImplementationMapping, + using var invoker = new GrainMethodInvoker(message, target, invokable, GrainCallFilters, this.interfaceToImplementationMapping, this.responseCopier, this.responseCodecProvider, this.responseCopyContexts); await invoker.Invoke(); - response = invoker.Response!; + (response, isCopied) = invoker.TakeResponse(); } else { - if (invokable is IResponseInvokable direct) - response = await direct.InvokeAndCopy(this.responseCodecProvider, this.responseCopyContexts, this.responseCopier); - else - { - response = await invokable.Invoke(); - response = this.responseCopier.Copy(response)!; - } + response = await ResponseCopyBoundary.InvokeAndCopy(invokable, + this.responseCodecProvider, this.responseCopyContexts, this.responseCopier); + isCopied = invokable is not IResponseInvokable || response.Exception is null; } invokable.Dispose(); @@ -346,36 +344,47 @@ public async Task Invoke(IGrainContext target, Message message) } catch (Exception exc1) { + response?.Dispose(); response = Response.FromException(exc1); + isCopied = false; } - if (response.Exception is { } invocationException) + try { - LogGrainInvokeException(this.invokeExceptionLogger, message.Direction != Message.Directions.OneWay ? LogLevel.Debug : LogLevel.Warning, invocationException, message); - - // If a grain allowed an inconsistent state exception to escape and the exception originated from - // this activation, then deactivate it. - if (invocationException is InconsistentStateException ise && ise.IsSourceActivation) + if (response.Exception is { } invocationException) { - // Mark the exception so that it doesn't deactivate any other activations. - ise.IsSourceActivation = false; - - LogDeactivatingInconsistentState(this.invokeExceptionLogger, target, invocationException); + LogGrainInvokeException(this.invokeExceptionLogger, message.Direction != Message.Directions.OneWay ? LogLevel.Debug : LogLevel.Warning, invocationException, message); - if (target is ActivationData ad && message.RequestContextData.TryGetActivityContext() is { } ac) + // If a grain allowed an inconsistent state exception to escape and the exception originated from + // this activation, then deactivate it. + if (invocationException is InconsistentStateException ise && ise.IsSourceActivation) { - ad.Deactivate(new DeactivationReason(DeactivationReasonCode.ApplicationError, LogFormatter.PrintException(invocationException)), ac); - } - else - { - target.Deactivate(new DeactivationReason(DeactivationReasonCode.ApplicationError, LogFormatter.PrintException(invocationException))); + // Mark the exception so that it doesn't deactivate any other activations. + ise.IsSourceActivation = false; + + LogDeactivatingInconsistentState(this.invokeExceptionLogger, target, invocationException); + + if (target is ActivationData ad && message.RequestContextData.TryGetActivityContext() is { } ac) + { + ad.Deactivate(new DeactivationReason(DeactivationReasonCode.ApplicationError, LogFormatter.PrintException(invocationException)), ac); + } + else + { + target.Deactivate(new DeactivationReason(DeactivationReasonCode.ApplicationError, LogFormatter.PrintException(invocationException))); + } } } - } - if (message.Direction != Message.Directions.OneWay) + if (message.Direction != Message.Directions.OneWay) + { + var outgoing = response; + response = null; + SafeSendResponse(message, outgoing, isCopied); + } + } + finally { - SafeSendResponse(message, response); + response?.Dispose(); } return; @@ -391,18 +400,29 @@ public async Task Invoke(IGrainContext target, Message message) } } - private void SafeSendResponse(Message message, Response response) + private void SafeSendResponse(Message message, Response response, bool isCopied) { + Response? ownedResponse = response; try { - // The copier preserves the null state of its input. - SendResponse(message, (Response)this._deepCopier.Copy(response)!); + if (!isCopied) + { + ownedResponse = null; + ownedResponse = ResponseCopyBoundary.CopyAndDispose(response, this._deepCopier); + } + + SendResponse(message, ownedResponse); + ownedResponse = null; } catch (Exception exc) { LogWarningResponseFailed(this.logger, exc); SendResponse(message, Response.FromException(exc)); } + finally + { + ownedResponse?.Dispose(); + } } private void SafeSendExceptionResponse(Message message, Exception ex) diff --git a/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs new file mode 100644 index 00000000000..26b01a0ce05 --- /dev/null +++ b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs @@ -0,0 +1,685 @@ +using System.Buffers; +using System.Collections.Concurrent; +using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.Metrics; +using System.IO.Pipelines; +using System.Net; +using System.Reflection; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.Extensions.Options; +using Microsoft.Extensions.Time.Testing; +using NSubstitute; +using Orleans; +using Orleans.CodeGeneration; +using Orleans.Configuration; +using Orleans.GrainReferences; +using Orleans.Metadata; +using Orleans.Networking.Shared; +using Orleans.Placement.Repartitioning; +using Orleans.Runtime; +using Orleans.Runtime.Messaging; +using Orleans.Serialization; +using Orleans.Serialization.Buffers; +using Orleans.Serialization.Cloning; +using Orleans.Serialization.Codecs; +using Orleans.Serialization.Configuration; +using Orleans.Serialization.Invocation; +using Orleans.Serialization.Serializers; +using Orleans.Serialization.Session; +using Xunit; + +namespace UnitTests.Serialization; + +[TestSuite("BVT")] +[TestProvider("None")] +[TestArea("Serialization")] +[TestCategory("BVT"), TestCategory("Serialization")] +public sealed class SelfWritingResponseOwnershipTests +{ + [Theory] + [InlineData(false, false)] + [InlineData(false, true)] + [InlineData(true, false)] + [InlineData(true, true)] + public async Task DirectResponse_ReachesSendWithOneCopyAndOneOwnedHolder(bool observer, bool filtered) + { + var counts = new Counts(); + var payload = new Payload { Values = [17, 23, 41] }; + var filter = filtered ? new CallbackFilter(async context => + { + await context.Invoke(); + Assert.Equal(1, counts.PayloadCopies); + Assert.NotSame(payload, context.Result); + payload.Values[0] = 99; + payload.Values.Add(73); + }) : null; + await using var fixture = new SendFixture(counts, filter); + var request = new DirectRequest(payload, counts); + + using var response = await fixture.Invoke(request, observer); + + Assert.Null(response.Exception); + Assert.Equal(1, counts.PayloadCopies); + Assert.Equal(1, counts.Rents); + Assert.Same(request.ReturnedResponse, response); + Assert.Equal(0, counts.Returns); + Assert.Equal(0, counts.ResponseCopies); + Assert.NotSame(payload, response.Result); + var result = Assert.IsType(response.Result); + Assert.Equal(new[] { 17, 23, 41 }, result.Values); + payload.Values.Clear(); + Assert.Equal(new[] { 17, 23, 41 }, result.Values); + await fixture.AssertFrameRoundTrip(response); + response.Dispose(); + Assert.Equal(1, counts.Returns); + } + + [Theory] + [InlineData(false, false)] + [InlineData(false, true)] + [InlineData(true, false)] + [InlineData(true, true)] + public async Task LegacyResponse_CopiesOnceAndReturnsBothOwnedWrappers(bool observer, bool filtered) + { + var counts = new Counts(); + var payload = new Payload { Values = [17, 23, 41] }; + var filter = filtered ? new CallbackFilter(async context => + { + await context.Invoke(); + Assert.Equal(1, counts.PayloadCopies); + payload.Values.Clear(); + Assert.Equal(new[] { 17, 23, 41 }, Assert.IsType(context.Result).Values); + }) : null; + await using var fixture = new SendFixture(counts, filter); + var request = new LegacyRequest(payload, counts); + + using var response = await fixture.Invoke(request, observer); + + Assert.Null(response.Exception); + Assert.NotSame(request.ReturnedResponse, response); + Assert.Equal(1, counts.PayloadCopies); + Assert.Equal(1, counts.ResponseCopies); + Assert.Equal(2, counts.Rents); + Assert.Equal(1, counts.Returns); + Assert.Equal(new[] { 17, 23, 41 }, Assert.IsType(response.Result).Values); + response.Dispose(); + Assert.Equal(2, counts.Returns); + } + + [Theory] + [InlineData(false, false)] + [InlineData(false, true)] + [InlineData(true, false)] + [InlineData(true, true)] + public async Task FilterSelectedResponse_IsCopiedAndReleasesSupersededRoot(bool observer, bool invokeRoot) + { + var counts = new Counts(); + var original = new Payload { Values = [17, 23, 41] }; + var replacement = new Payload { Values = [5, 8, 13] }; + var filter = new CallbackFilter(async context => + { + if (invokeRoot) await context.Invoke(); + context.Response = CountedResponse.Rent(replacement, counts, + Assert.IsAssignableFrom(context.Request).Codec); + }); + await using var fixture = new SendFixture(counts, filter); + var request = new DirectRequest(original, counts); + + using var response = await fixture.Invoke(request, observer); + + Assert.Null(response.Exception); + Assert.Equal(invokeRoot ? 2 : 1, counts.PayloadCopies); + Assert.Equal(1, counts.ResponseCopies); + Assert.Equal(invokeRoot ? 3 : 2, counts.Rents); + Assert.Equal(invokeRoot ? 2 : 1, counts.Returns); + Assert.NotSame(replacement, response.Result); + replacement.Values.Clear(); + Assert.Equal(new[] { 5, 8, 13 }, Assert.IsType(response.Result).Values); + response.Dispose(); + Assert.Equal(counts.Rents, counts.Returns); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task FilterRestoresEarlierRoot_ReusesItsIsolationAndDisposesOtherRoot(bool observer) + { + var counts = new Counts(); + var filter = new CallbackFilter(async context => + { + await context.Invoke(); + var first = context.Response; + await context.Invoke(); + Assert.NotSame(first, context.Response); + context.Response = first; + }); + await using var fixture = new SendFixture(counts, filter); + using var response = await fixture.Invoke(new DirectRequest(new Payload { Values = [17] }, counts), observer); + Assert.Null(response.Exception); + Assert.Equal(2, counts.PayloadCopies); + Assert.Equal(0, counts.ResponseCopies); + Assert.Equal(2, counts.Rents); + Assert.Equal(1, counts.Returns); + response.Dispose(); + Assert.Equal(2, counts.Returns); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task FilterThrowsAfterCopy_ReturnsRootAndPreservesException(bool observer) + { + var counts = new Counts(); + var failure = new InvalidOperationException("after isolated invocation"); + var filter = new CallbackFilter(async context => + { + await context.Invoke(); + throw failure; + }); + await using var fixture = new SendFixture(counts, filter); + using var response = await fixture.Invoke(new DirectRequest(new Payload { Values = [17] }, counts), observer); + Assert.Same(failure, response.Exception); + Assert.Equal(1, counts.PayloadCopies); + Assert.Equal(1, counts.Rents); + Assert.Equal(1, counts.Returns); + } + + [Theory] + [InlineData(false, false)] + [InlineData(false, true)] + [InlineData(true, false)] + [InlineData(true, true)] + public async Task LegacyCopyFailure_ReturnsOriginalOwnedWrapper(bool observer, bool filtered) + { + var counts = new Counts { ThrowCopy = true }; + var filter = filtered ? new CallbackFilter(context => context.Invoke()) : null; + await using var fixture = new SendFixture(counts, filter); + using var response = await fixture.Invoke(new LegacyRequest(new Payload { Values = [17] }, counts), observer); + Assert.Same(counts.CopyFailure, response.Exception); + Assert.Equal(1, counts.PayloadCopies); + Assert.Equal(1, counts.Rents); + Assert.Equal(1, counts.Returns); + } + + [Theory] + [InlineData(false, false)] + [InlineData(false, true)] + [InlineData(true, false)] + [InlineData(true, true)] + public async Task CustomCopierReturnsInput_PreservesSelectionAndTransfersOneOwner(bool observer, bool filtered) + { + var counts = new Counts { ReturnInput = true }; + var filter = filtered ? new CallbackFilter(context => context.Invoke()) : null; + await using var fixture = new SendFixture(counts, filter); + var request = new LegacyRequest(new Payload { Values = [17] }, counts); + using var response = await fixture.Invoke(request, observer); + Assert.Null(response.Exception); + Assert.Same(request.ReturnedResponse, response); + Assert.Equal(1, counts.ResponseCopies); + Assert.Equal(0, counts.PayloadCopies); + Assert.Equal(1, counts.Rents); + Assert.Equal(0, counts.Returns); + response.Dispose(); + Assert.Equal(1, counts.Returns); + } + + [Theory] + [InlineData(false, false, false)] + [InlineData(false, true, false)] + [InlineData(true, false, false)] + [InlineData(true, true, false)] + [InlineData(false, false, true)] + [InlineData(false, true, true)] + [InlineData(true, false, true)] + [InlineData(true, true, true)] + public async Task UnsentResponse_ReturnsOwnedHolderWithoutSecondCopy(bool observer, bool filtered, bool expired) + { + var counts = new Counts(); + var filter = filtered ? new CallbackFilter(context => context.Invoke()) : null; + await using var fixture = new SendFixture(counts, filter); + await fixture.Execute(new DirectRequest(new Payload { Values = [17] }, counts), observer, + expired ? Message.Directions.Request : Message.Directions.OneWay, expireAfterInvocation: expired); + Assert.False(fixture.HasResponse); + Assert.Equal(1, counts.PayloadCopies); + Assert.Equal(1, counts.Rents); + Assert.Equal(1, counts.Returns); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task FailedHandoff_ReturnsCurrentHolderAndSurfacesFailure(bool observer) + { + var counts = new Counts(); + var failure = new InvalidOperationException("response handoff failed"); + var marker = new SendFailureMarker(failure); + var filter = new CallbackFilter(context => context.Invoke()); + await using var fixture = new SendFixture(counts, filter) + { + HandoffFailure = observer ? failure : null, + InitialContext = observer ? null : new Dictionary { ["response-handoff-failure"] = marker }, + }; + using var response = await fixture.Invoke(new DirectRequest(new Payload { Values = [17] }, counts), observer); + Assert.Same(failure, response.Exception); + Assert.Equal(1, counts.PayloadCopies); + Assert.Equal(1, counts.Rents); + Assert.Equal(1, counts.Returns); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task ReplacementCopyFailure_ReturnsReplacementAndSupersededRoot(bool observer) + { + var counts = new Counts(); + var filter = new CallbackFilter(async context => + { + await context.Invoke(); + context.Response = CountedResponse.Rent(new Payload { Values = [47] }, counts, + Assert.IsAssignableFrom(context.Request).Codec); + counts.ThrowCopy = true; + }); + await using var fixture = new SendFixture(counts, filter); + using var response = await fixture.Invoke(new DirectRequest(new Payload { Values = [17] }, counts), observer); + Assert.Same(counts.CopyFailure, response.Exception); + Assert.Equal(2, counts.PayloadCopies); + Assert.Equal(2, counts.Rents); + Assert.Equal(2, counts.Returns); + } + + [Theory] + [InlineData(false, false)] + [InlineData(false, true)] + [InlineData(true, false)] + [InlineData(true, true)] + public async Task FilterReplacesThenThrows_ReturnsEveryOwnedWrapper(bool observer, bool invokeRoot) + { + var counts = new Counts(); + var failure = new InvalidOperationException("after replacing response"); + var filter = new CallbackFilter(async context => + { + if (invokeRoot) await context.Invoke(); + context.Response = CountedResponse.Rent(new Payload { Values = [47] }, counts, + Assert.IsAssignableFrom(context.Request).Codec); + throw failure; + }); + await using var fixture = new SendFixture(counts, filter); + using var response = await fixture.Invoke(new DirectRequest(new Payload { Values = [17] }, counts), observer); + Assert.Same(failure, response.Exception); + Assert.Equal(invokeRoot ? 1 : 0, counts.PayloadCopies); + Assert.Equal(invokeRoot ? 2 : 1, counts.Rents); + Assert.Equal(counts.Rents, counts.Returns); + } + + private sealed class SendFailureMarker(Exception failure) + { + public Exception Failure { get; } = failure; + public bool HasFailed { get; set; } + } + + private sealed class SendFailureCopier : IDeepCopier + { + [return: NotNullIfNotNull(nameof(input))] + public SendFailureMarker? DeepCopy(SendFailureMarker? input, CopyContext context) + { + if (input is null) return null; + if (!input.HasFailed) + { + input.HasFailed = true; + throw input.Failure; + } + + return input; + } + } + + [GenerateSerializer] + public sealed class Payload + { + [Id(0)] + public List Values { get; set; } = []; + } + + private sealed class Counts + { + public int PayloadCopies; + public int ResponseCopies; + public int Rents; + public int Returns; + public bool ThrowCopy; + public bool ReturnInput; + public Exception CopyFailure { get; } = new InvalidOperationException("payload copy failed"); + + public Payload Copy(Payload source) + { + PayloadCopies++; + if (ThrowCopy) throw CopyFailure; + return new Payload { Values = [.. source.Values] }; + } + } + + private sealed class CountedResponse : Response, IRawResponseWriter + { + private Counts? _counts; + private IFieldCodec _codec = null!; + private Payload _value = null!; + + public CountedResponse() { } + + public static CountedResponse Rent(Payload value, Counts counts, IFieldCodec codec) + { + var response = ResponsePool.GetGenerated(); + response._value = value; + response._counts = counts; + response._codec = codec; + counts.Rents++; + return response; + } + + public override object? Result { get => _value; set => _value = (Payload)value!; } + public override Exception? Exception { get => null; set => throw new NotSupportedException(); } + public override Type GetSimpleResultType() => typeof(Payload); + public override T GetResult() => (T)(object)_value; + + public void WriteRaw(ref Writer writer) where TBufferWriter : IBufferWriter + { + writer.WriteStartObject(0, null!, typeof(Payload)); + _codec.WriteField(ref writer, 0, typeof(Payload), _value); + writer.WriteEndObject(); + } + + public override void Dispose() + { + if (_counts is null) return; + _counts.Returns++; + _counts = null; + _codec = null!; + _value = null!; + ResponsePool.ReturnGenerated(this); + } + } + + private class LegacyRequest(Payload payload, Counts counts) : IInvokable + { + protected ICodecProvider Provider = null!; + protected Payload Payload => payload; + protected Counts Counters => counts; + public IFieldCodec Codec => Provider.GetCodec(); + public Response? ReturnedResponse { get; protected set; } + public Action? AfterInvocation { get; set; } + public object GetTarget() => payload; + public void SetTarget(ITargetHolder holder) { } + public int GetArgumentCount() => 0; + public object? GetArgument(int index) => throw new ArgumentOutOfRangeException(nameof(index)); + public void SetArgument(int index, object value) => throw new ArgumentOutOfRangeException(nameof(index)); + public string GetMethodName() => nameof(ToString); + public string GetInterfaceName() => nameof(IGrainObserver); + public string GetActivityName() => nameof(ToString); + public MethodInfo GetMethod() => typeof(object).GetMethod(nameof(ToString), Type.EmptyTypes)!; + public Type GetInterfaceType() => typeof(IGrainObserver); + public void Dispose() { } + public void Bind(ICodecProvider provider) => Provider = provider; + + public virtual ValueTask Invoke() + { + ReturnedResponse = CountedResponse.Rent(payload, counts, Provider.GetCodec()); + AfterInvocation?.Invoke(); + return ValueTask.FromResult(ReturnedResponse); + } + } + + private sealed class DirectRequest(Payload payload, Counts counts) : LegacyRequest(payload, counts), IResponseInvokable + { + public override ValueTask Invoke() => throw new InvalidOperationException("The direct request uses InvokeAndCopy."); + + public ValueTask InvokeAndCopy(ICodecProvider provider, CopyContextPool contexts, DeepCopier responseCopier) + { + ReturnedResponse = CountedResponse.Rent(Counters.Copy(Payload), Counters, provider.GetCodec()); + AfterInvocation?.Invoke(); + return ValueTask.FromResult(ReturnedResponse); + } + } + + private sealed class CountingResponseCopier(Counts counts, ICodecProvider provider) : IDeepCopier + { + [return: NotNullIfNotNull(nameof(input))] + public Response? DeepCopy(Response? input, CopyContext context) + { + if (input is null) return null; + counts.ResponseCopies++; + if (counts.ReturnInput) return input; + if (input.Exception is not null) return input; + return CountedResponse.Rent(counts.Copy(Assert.IsType(input.Result)), counts, provider.GetCodec()); + } + } + + private sealed class UnusedResponseCodec : IFieldCodec + { + public void WriteField(ref Writer writer, uint fieldIdDelta, Type? expectedType, Response? value) + where TBufferWriter : IBufferWriter => throw new NotSupportedException(); + public Response ReadValue(ref Reader reader, Orleans.Serialization.WireProtocol.Field field) => throw new NotSupportedException(); + } + + private sealed class CountingHolderCopier(Counts counts, ICodecProvider provider) : IDeepCopier + { + [return: NotNullIfNotNull(nameof(input))] + public CountedResponse? DeepCopy(CountedResponse? input, CopyContext context) + { + if (input is null) return null; + counts.ResponseCopies++; + return CountedResponse.Rent(counts.Copy(Assert.IsType(input.Result)), counts, provider.GetCodec()); + } + } + + private sealed class UnusedHolderCodec : IFieldCodec + { + public void WriteField(ref Writer writer, uint fieldIdDelta, Type? expectedType, CountedResponse? value) + where TBufferWriter : IBufferWriter => throw new NotSupportedException(); + public CountedResponse ReadValue(ref Reader reader, Orleans.Serialization.WireProtocol.Field field) => throw new NotSupportedException(); + } + + private sealed class CallbackFilter(Func callback) : IIncomingGrainCallFilter + { + public Task Invoke(IIncomingGrainCallContext context) => callback(context); + } + + private sealed class Observer : IGrainObserver + { + } + + private sealed class SendFixture : IAsyncDisposable, IResponseCompletionSource + { + private readonly ServiceProvider _services; + private readonly FakeTimeProvider _clock = new(); + private readonly InsideRuntimeClient _runtime; + private readonly HostedClient _hosted; + private readonly InvokableObjectManager _manager; + private readonly Observer _observer = new(); + private readonly ObserverGrainId _observerId = ObserverGrainId.Create(ClientGrainId.Create("response-copy"), IdSpan.Create("observer")); + private readonly TaskCompletionSource _completion = new(TaskCreationOptions.RunContinuationsAsynchronously); + private readonly SharedMemoryPool _memory = new(); + private readonly MessageSerializer _serializer; + private Message _request = null!; + private Response? _sentResponse; + public bool HasResponse => _sentResponse is not null; + public Exception? HandoffFailure { get; set; } + public Dictionary? InitialContext { get; set; } + + public SendFixture(Counts counts, IIncomingGrainCallFilter? filter) + { + var services = new ServiceCollection(); + services.AddSerializer(builder => builder.Configure(options => + { + options.AddSerializer(_ => new UnusedResponseCodec(), provider => new CountingResponseCopier(counts, provider)); + options.AddSerializer(_ => new UnusedHolderCodec(), provider => new CountingHolderCopier(counts, provider)); + options.AddCopier(typeof(SendFailureCopier)); + })); + services.AddLogging(); + services.AddMetrics(); + if (filter is not null) services.AddSingleton(filter); + _services = services.BuildServiceProvider(); + var copier = _services.GetRequiredService(); + var instruments = new OrleansInstruments(_services.GetRequiredService()); + var messaging = new MessagingInstruments(instruments); + var processing = new MessagingProcessingInstruments(instruments); + var trace = new MessagingTrace(NullLoggerFactory.Instance, messaging, processing); + var factory = new MessageFactory(copier, NullLogger.Instance, trace); + var options = Options.Create(new SiloMessagingOptions()); + var mapping = new InterfaceToImplementationMappingCache(); + var referenceRuntime = Substitute.For(); + var activator = new GrainReferenceActivator(_services, [new UntypedReferenceProvider(_services, referenceRuntime)]); + var silo = Substitute.For(); + silo.SiloAddress.Returns(SiloAddress.New(IPAddress.Loopback, 0, 1)); + silo.GatewayAddress.Returns((SiloAddress)null!); + _runtime = new InsideRuntimeClient(silo, _services, factory, NullLoggerFactory.Instance, options, trace, activator, + new GrainInterfaceTypeResolver([], _services.GetRequiredService()), + new GrainInterfaceTypeToGrainTypeResolver(Substitute.For()), + copier, _clock, mapping, instruments); + var messageCenter = new MessageCenter(silo, factory, null!, + _ => throw new InvalidOperationException("The response fixture has no gateway."), + NullLogger.Instance, Substitute.For(), null!, + new RuntimeMessagingTrace(NullLoggerFactory.Instance, messaging, processing), messaging, processing, + options, null!, null!, new NoOpMessageStatisticsSink()); + _hosted = new HostedClient(_runtime, silo, NullLogger.Instance, referenceRuntime, + Substitute.For(), messageCenter, trace, copier, activator, mapping); + messageCenter.SetHostedClient(_hosted); + typeof(InsideRuntimeClient).GetField("messageCenter", BindingFlags.Instance | BindingFlags.NonPublic)!.SetValue(_runtime, messageCenter); + typeof(InsideRuntimeClient).GetField("grainCallFilters", BindingFlags.Instance | BindingFlags.NonPublic)!.SetValue(_runtime, + _services.GetServices().ToList()); + var observerRuntime = Substitute.For(); + observerRuntime.ServiceProvider.Returns(_services); + observerRuntime.When(client => client.SendResponse(Arg.Any(), Arg.Any())) + .Do(call => + { + if (call.Arg() is CountedResponse && HandoffFailure is { } failure) + { + HandoffFailure = null; + throw failure; + } + + ((IResponseCompletionSource)this).Complete(call.Arg()); + }); + _manager = new InvokableObjectManager(Substitute.For(), observerRuntime, copier, trace, + _services.GetRequiredService>(), mapping, NullLogger.Instance); + Assert.True(_manager.TryRegister(_observer, _observerId)); + _serializer = new MessageSerializer(_services.GetRequiredService(), _memory, options.Value); + } + + public async Task Invoke(LegacyRequest request, bool observer) + { + await Execute(request, observer); + return await _completion.Task.WaitAsync(TimeSpan.FromSeconds(60), TestContext.Current.CancellationToken); + } + + public async Task Execute(LegacyRequest request, bool observer, + Message.Directions direction = Message.Directions.Request, bool expireAfterInvocation = false) + { + request.Bind(_services.GetRequiredService()); + _request = new Message + { + Id = new CorrelationId(7123), + Direction = direction, + SendingGrain = _hosted.GrainId, + SendingSilo = _hosted.Address.SiloAddress, + TargetGrain = observer ? _observerId.GrainId : GrainId.Create("response-copy", "target"), + TargetSilo = _hosted.Address.SiloAddress, + BodyObject = request, + RequestContextData = InitialContext, + }; + if (expireAfterInvocation) request.AfterInvocation = () => _request.TimeToLive = TimeSpan.FromMilliseconds(-1); + if (observer) + { + _manager.Dispatch(_request); + await _manager.StopAsync().WaitAsync(TimeSpan.FromSeconds(60), TestContext.Current.CancellationToken); + } + else + { + var callbacks = (ConcurrentDictionary<(GrainId, CorrelationId), CallbackData>)typeof(InsideRuntimeClient) + .GetField("callbacks", BindingFlags.Instance | BindingFlags.NonPublic)!.GetValue(_runtime)!; + var shared = new SharedCallbackData(message => callbacks.TryRemove((_request.SendingGrain, _request.Id), out _), + NullLogger.Instance, _clock, TimeSpan.FromMinutes(1), false, false, null!); + Assert.True(callbacks.TryAdd((_request.SendingGrain, _request.Id), + new CallbackData(shared, this, _request, new ApplicationRequestInstruments( + new OrleansInstruments(_services.GetRequiredService()))))); + var target = Substitute.For(); + target.GrainInstance.Returns(_observer); + target.GrainId.Returns(_request.TargetGrain); + target.ActivationServices.Returns(_services); + await _runtime.Invoke(target, _request); + } + } + + public async Task AssertFrameRoundTrip(Response response) + { + var message = new Message + { + Direction = Message.Directions.Response, + Id = _request.Id, + SendingGrain = _request.TargetGrain, + TargetGrain = _request.SendingGrain, + BodyObject = response, + }; + var pipe = new Pipe(new PipeOptions(pauseWriterThreshold: 0)); + try + { + var written = _serializer.Write(pipe.Writer, message); + await pipe.Writer.FlushAsync(TestContext.Current.CancellationToken); + Assert.True(pipe.Reader.TryRead(out var read)); + var bytes = read.Buffer.ToArray(); + pipe.Reader.AdvanceTo(read.Buffer.End); + var input = new ReadOnlySequence(bytes); + var (required, headers, body) = _serializer.TryRead(ref input, out var received); + Assert.Equal(0, required); + Assert.Equal(written.HeaderLength, headers); + Assert.Equal(written.BodyLength, body); + Assert.True(input.IsEmpty); + Assert.NotNull(received); + Assert.Equal(message.Direction, received.Direction); + Assert.Equal(message.Id, received.Id); + using var result = Assert.IsAssignableFrom(received.BodyObject); + Assert.Equal(Assert.IsType(response.Result).Values, Assert.IsType(result.Result).Values); + } + finally + { + await pipe.Writer.CompleteAsync(); + await pipe.Reader.CompleteAsync(); + } + } + + void IResponseCompletionSource.Complete(Response value) + { + Assert.Null(_sentResponse); + _sentResponse = value; + _completion.TrySetResult(value); + } + + void IResponseCompletionSource.Complete() => ((IResponseCompletionSource)this).Complete(Response.Completed); + + public async ValueTask DisposeAsync() + { + await _manager.StopAsync(); + _sentResponse?.Dispose(); + ((IDisposable)_hosted).Dispose(); + _serializer.Dispose(); + _memory.Pool.Dispose(); + await _services.DisposeAsync(); + GC.KeepAlive(_observer); + } + } + + private sealed class UntypedReferenceProvider(IServiceProvider services, IGrainReferenceRuntime runtime) : IGrainReferenceActivatorProvider + { + public bool TryGet(GrainType grainType, GrainInterfaceType interfaceType, [NotNullWhen(true)] out IGrainReferenceActivator? activator) + { + activator = new UntypedReferenceActivator(new GrainReferenceShared(grainType, interfaceType, 0, runtime, + InvokeMethodOptions.None, services.GetRequiredService(), services.GetRequiredService(), services)); + return true; + } + + private sealed class UntypedReferenceActivator(GrainReferenceShared shared) : IGrainReferenceActivator + { + public GrainReference CreateReference(GrainId grainId) => GrainReference.FromGrainId(shared, grainId); + } + } +} From 48af43a8a3f2fd3bc81078661c3661c142f4da1e Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Sat, 3 Oct 2026 02:44:07 -0700 Subject: [PATCH 30/54] fix(serialization): decline external dependencies in inferred graphs --- .../Configuration/TypeManifestOptions.cs | 4 +- .../Serializers/CodecProvider.cs | 3 +- .../DefaultFactoryDependencyAdmissionTests.cs | 165 ++++++++++++++++++ .../RpcResponseTests.cs | 4 +- 4 files changed, 170 insertions(+), 6 deletions(-) create mode 100644 test/Orleans.Serialization.UnitTests/DefaultFactoryDependencyAdmissionTests.cs diff --git a/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs b/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs index 445d2c05fef..fa0859be30a 100644 --- a/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs +++ b/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs @@ -195,8 +195,8 @@ public void AddDefaultSerializerService(Func /// The default service factory. /// Services required to construct the default graph. /// - /// The factory participates when its dependencies are available through closed service factories, - /// provider-owned services, or instance registrations. Explicit registrations take precedence. + /// The factory participates when its dependencies are supplied by closed service factories + /// and provider-owned services. Explicit registrations take precedence. /// /// or is null. public void AddDefaultSerializerService(Func factory, Type[] dependencies) where TService : class diff --git a/src/Orleans.Serialization/Serializers/CodecProvider.cs b/src/Orleans.Serialization/Serializers/CodecProvider.cs index 6964e96e6ea..f9834f58e91 100644 --- a/src/Orleans.Serialization/Serializers/CodecProvider.cs +++ b/src/Orleans.Serialization/Serializers/CodecProvider.cs @@ -702,8 +702,7 @@ private bool IsDefaultContractEligible(TypeManifestOptions.DefaultSerializerCont && !IsProviderService(dependency) && dependency != typeof(IServiceProvider) && dependency != typeof(IServiceProviderIsService) - && !(dependency == typeof(IServiceProviderIsKeyedService) && _serviceProvider is IKeyedServiceProvider) - && _serviceDescriptors.LastOrDefault(descriptor => !descriptor.IsKeyedService && descriptor.ServiceType == dependency)?.ImplementationInstance is null) + && !(dependency == typeof(IServiceProviderIsKeyedService) && _serviceProvider is IKeyedServiceProvider)) { return false; } diff --git a/test/Orleans.Serialization.UnitTests/DefaultFactoryDependencyAdmissionTests.cs b/test/Orleans.Serialization.UnitTests/DefaultFactoryDependencyAdmissionTests.cs new file mode 100644 index 00000000000..776c092691b --- /dev/null +++ b/test/Orleans.Serialization.UnitTests/DefaultFactoryDependencyAdmissionTests.cs @@ -0,0 +1,165 @@ +using System; +using Microsoft.Extensions.DependencyInjection; +using Orleans.Serialization.Buffers; +using Orleans.Serialization.Cloning; +using Orleans.Serialization.Codecs; +using Orleans.Serialization.Configuration; +using Orleans.Serialization.GeneratedCodeHelpers; +using Orleans.Serialization.Serializers; +using Orleans.Serialization.WireProtocol; + +namespace Orleans.Serialization.UnitTests; + +[Trait("Category", "BVT")] +[TestSuite("BVT")] +[TestProvider("None")] +[TestArea("Serialization")] +public sealed class DefaultFactoryDependencyAdmissionTests +{ + [Theory] + [InlineData("Instance", false)] + [InlineData("Instance", true)] + [InlineData("Factory", false)] + [InlineData("Factory", true)] + [InlineData("Type", false)] + [InlineData("Type", true)] + public void ExternalDependency_DeclinesDefaultGraphAndUsesBuiltProvider(string registration, bool mutateAfterBuild) + { + var original = new Dependency(); + var replacement = new Dependency(); + var state = new State(); + var collection = new ServiceCollection(); + if (registration == "Instance") collection.AddSingleton(original); + else if (registration == "Factory") collection.AddSingleton(_ => original); + else collection.AddSingleton(); + collection.AddSerializer(builder => builder.Configure(options => RegisterDefaults(options, state))); + using var services = collection.BuildServiceProvider(); + if (mutateAfterBuild) collection.AddSingleton(replacement); + var provider = services.GetRequiredService(); + + var codec = Assert.IsType(provider.GetCodec()); + var actual = services.GetRequiredService(); + + Assert.Equal(0, state.FactoryCalls); + Assert.Same(actual, codec.Dependency); + Assert.NotSame(replacement, codec.Dependency); + Assert.False(codec.ConstructionWasPending); + Assert.Same(actual, codec.Services.GetRequiredService()); + Assert.Same(codec, provider.GetCodec()); + Assert.False(provider.IsConstructionPending); + } + + [Fact] + public void ExplicitClosedDependency_PublishesCanonicalIdentity() + { + var dependency = new Dependency(); + var state = new State(); + using var services = new ServiceCollection().AddSerializer(builder => builder.Configure(options => + { + options.AddSerializerService(_ => dependency); + RegisterDefaults(options, state); + })).BuildServiceProvider(); + var provider = services.GetRequiredService(); + + var codec = Assert.IsType(provider.GetCodec()); + + Assert.Equal(1, state.FactoryCalls); + Assert.True(codec.ConstructionWasPending); + Assert.Same(dependency, codec.Dependency); + Assert.Same(dependency, OrleansGeneratedCodeHelper.GetService(null!, provider)); + Assert.Same(codec, OrleansGeneratedCodeHelper.GetService(null!, provider)); + Assert.Same(codec, provider.GetCodec()); + Assert.False(provider.IsConstructionPending); + } + + [Fact] + public void ExplicitClosedDependency_FailedGraphRollsBackBeforeCanonicalRetry() + { + var dependency = new Dependency(); + var dependencyCalls = 0; + var state = new State(); + var failure = new InvalidOperationException("graph failed after constructing codec"); + using var services = new ServiceCollection().AddSerializer(builder => builder.Configure(options => + { + options.AddSerializerService(_ => + { + dependencyCalls++; + return dependency; + }); + RegisterDefaults(options, state); + options.AddSerializerService(provider => + { + _ = provider.GetCodec(); + throw failure; + }); + })).BuildServiceProvider(); + var provider = services.GetRequiredService(); + + Assert.Same(failure, Assert.Throws( + () => OrleansGeneratedCodeHelper.GetService(null!, provider))); + Assert.False(provider.IsConstructionPending); + Assert.Equal(1, state.FactoryCalls); + Assert.Equal(1, dependencyCalls); + var rolledBack = state.LastCodec; + + var codec = Assert.IsType(provider.GetCodec()); + + Assert.Equal(2, state.FactoryCalls); + Assert.Equal(2, dependencyCalls); + Assert.NotSame(rolledBack, codec); + Assert.Same(dependency, codec.Dependency); + Assert.Same(codec, OrleansGeneratedCodeHelper.GetService(null!, provider)); + Assert.False(provider.IsConstructionPending); + } + + private static void RegisterDefaults(TypeManifestOptions options, State state) + { + options.AddSerializer(typeof(DependentCodec)); + options.AddDefaultSerializerService(provider => + { + state.FactoryCalls++; + return state.LastCodec = new DependentCodec( + OrleansGeneratedCodeHelper.GetService(null!, provider), ((CodecProvider)provider).Services); + }, dependencies: [typeof(Dependency), typeof(IServiceProvider)]); + options.AddDefaultSerializer>( + provider => OrleansGeneratedCodeHelper.GetService(null!, provider), + static _ => new ShallowCopier(), codecDependencies: [typeof(Dependency), typeof(IServiceProvider)]); + } + + private sealed class State + { + public int FactoryCalls; + public DependentCodec? LastCodec; + } + + public sealed class Dependency + { + } + + public sealed class Target + { + } + + private sealed class FailingRoot + { + } + + public sealed class DependentCodec : IFieldCodec + { + public DependentCodec(Dependency dependency, IServiceProvider services) + { + Dependency = dependency; + Services = services; + ConstructionWasPending = services.GetRequiredService().IsConstructionPending; + } + + public Dependency Dependency { get; } + public IServiceProvider Services { get; } + public bool ConstructionWasPending { get; } + + public void WriteField(ref Writer writer, uint fieldIdDelta, Type? expectedType, Target? value) + where TBufferWriter : System.Buffers.IBufferWriter => throw new NotSupportedException(); + + public Target ReadValue(ref Reader reader, Field field) => throw new NotSupportedException(); + } +} diff --git a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs index e9944d2b12b..a5d8de7cdf7 100644 --- a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs +++ b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs @@ -244,8 +244,8 @@ public void LegacyJitDictionaryResponsesPreserveCustomComparers() [InlineData("ImplementationType", false, true)] [InlineData("ImplementationFactory", false, false)] [InlineData("ImplementationFactory", false, true)] - [InlineData("Instance", true, false)] - [InlineData("Instance", true, true)] + [InlineData("Instance", false, false)] + [InlineData("Instance", false, true)] [InlineData("SerializerFactory", true, false)] [InlineData("SerializerFactory", true, true)] public void DefaultFactoryConstructorDependenciesRespectPublicationBoundary(string registration, bool eligible, bool bridgeFirst) From b0d237d2613fc6e2c9ae203f316c1a7b8ba8b3e4 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Sat, 3 Oct 2026 03:14:24 -0700 Subject: [PATCH 31/54] fix(codegen): release compatibility response leases --- .../InvokableGenerator.cs | 14 ++- .../OrleansSourceGeneratorTests.cs | 4 + ...ests.TestBasicGrain.DotNet10_0.verified.cs | 15 ++- ...Tests.TestBasicGrain.DotNet8_0.verified.cs | 15 ++- ...rializersAnnotation.DotNet10_0.verified.cs | 15 ++- ...erializersAnnotation.DotNet8_0.verified.cs | 15 ++- ...stGrainComplexGrain.DotNet10_0.verified.cs | 15 ++- ...estGrainComplexGrain.DotNet8_0.verified.cs | 15 ++- ...thInvokableBaseType.DotNet10_0.verified.cs | 15 ++- ...ithInvokableBaseType.DotNet8_0.verified.cs | 15 ++- ...WithResponseTimeout.DotNet10_0.verified.cs | 15 ++- ...dWithResponseTimeout.DotNet8_0.verified.cs | 15 ++- ...thDifferentKeyTypes.DotNet10_0.verified.cs | 60 ++++++++- ...ithDifferentKeyTypes.DotNet8_0.verified.cs | 60 ++++++++- ...hMultipleInterfaces.DotNet10_0.verified.cs | 30 ++++- ...thMultipleInterfaces.DotNet8_0.verified.cs | 30 ++++- .../SelfWritingResponseOwnershipTests.cs | 116 ++++++++++++++++-- 17 files changed, 434 insertions(+), 30 deletions(-) diff --git a/src/Orleans.CodeGenerator/InvokableGenerator.cs b/src/Orleans.CodeGenerator/InvokableGenerator.cs index 3db90b5b4f8..7a94047b7d2 100644 --- a/src/Orleans.CodeGenerator/InvokableGenerator.cs +++ b/src/Orleans.CodeGenerator/InvokableGenerator.cs @@ -173,7 +173,19 @@ private ClassDeclarationSyntax GetClassDeclarationSyntax( { var factory = {{factory}}.Resolve(provider); if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); + { + var original = await Invoke(); + global::Orleans.Serialization.Invocation.Response copy = null; + try + { + return copy = responseCopier.Copy(original); + } + finally + { + if (!global::System.Object.ReferenceEquals(original, copy)) + original.Dispose(); + } + } {{type}} value = await InvokeInner(); return factory.RentCopied(value, contexts); } diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index ef4284e3fdd..9a44e9f7652 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -3408,6 +3408,10 @@ public interface IWriter : IGrainWithIntegerKey { {{returnType}} Get(); } Assert.Contains("options.AddRawResponseReader", response); Assert.Contains("IResponseInvokable.InvokeAndCopy", proxy); Assert.Contains("factory.RentCopied(value, contexts)", proxy); + Assert.Contains("var original = await Invoke();", proxy); + Assert.Contains("return copy = responseCopier.Copy(original);", proxy); + Assert.Contains("if (!global::System.Object.ReferenceEquals(original, copy))", proxy); + Assert.Contains("original.Dispose();", proxy); Assert.DoesNotContain("MakeGenericType", response); var holders = CSharpSyntaxTree.ParseText(response, cancellationToken: TestContext.Current.CancellationToken) .GetCompilationUnitRoot(TestContext.Current.CancellationToken).DescendantNodes() diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs index 79284d3bcdb..1353e05b089 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs @@ -63,7 +63,20 @@ public override void SetArgument(int index, object value) { var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); + { + var original = await Invoke(); + global::Orleans.Serialization.Invocation.Response copy = null; + try + { + return copy = responseCopier.Copy(original); + } + finally + { + if (!global::System.Object.ReferenceEquals(original, copy)) + original.Dispose(); + } + } + string value = await InvokeInner(); return factory.RentCopied(value, contexts); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs index 5253130afae..083a0fa5927 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs @@ -63,7 +63,20 @@ public override void SetArgument(int index, object value) { var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); + { + var original = await Invoke(); + global::Orleans.Serialization.Invocation.Response copy = null; + try + { + return copy = responseCopier.Copy(original); + } + finally + { + if (!global::System.Object.ReferenceEquals(original, copy)) + original.Dispose(); + } + } + string value = await InvokeInner(); return factory.RentCopied(value, contexts); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs index 43b63e13263..b0eb7456911 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs @@ -63,7 +63,20 @@ public override void SetArgument(int index, object value) { var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); + { + var original = await Invoke(); + global::Orleans.Serialization.Invocation.Response copy = null; + try + { + return copy = responseCopier.Copy(original); + } + finally + { + if (!global::System.Object.ReferenceEquals(original, copy)) + original.Dispose(); + } + } + string value = await InvokeInner(); return factory.RentCopied(value, contexts); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs index 43368876901..7a7727d16da 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs @@ -63,7 +63,20 @@ public override void SetArgument(int index, object value) { var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); + { + var original = await Invoke(); + global::Orleans.Serialization.Invocation.Response copy = null; + try + { + return copy = responseCopier.Copy(original); + } + finally + { + if (!global::System.Object.ReferenceEquals(original, copy)) + original.Dispose(); + } + } + string value = await InvokeInner(); return factory.RentCopied(value, contexts); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs index bc06cdbeda8..c57d1e4f173 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs @@ -107,7 +107,20 @@ public override bool TryCancel() { var factory = global::OrleansCodeGen.TestProject.RpcResponse_FC7DD5BDFactory.Resolve(provider); if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); + { + var original = await Invoke(); + global::Orleans.Serialization.Invocation.Response copy = null; + try + { + return copy = responseCopier.Copy(original); + } + finally + { + if (!global::System.Object.ReferenceEquals(original, copy)) + original.Dispose(); + } + } + global::TestProject.ComplexData value = await InvokeInner(); return factory.RentCopied(value, contexts); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs index f5b74905d8d..c6ecb433671 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs @@ -106,7 +106,20 @@ public override bool TryCancel() { var factory = global::OrleansCodeGen.TestProject.RpcResponse_FC7DD5BDFactory.Resolve(provider); if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); + { + var original = await Invoke(); + global::Orleans.Serialization.Invocation.Response copy = null; + try + { + return copy = responseCopier.Copy(original); + } + finally + { + if (!global::System.Object.ReferenceEquals(original, copy)) + original.Dispose(); + } + } + global::TestProject.ComplexData value = await InvokeInner(); return factory.RentCopied(value, contexts); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs index d0530895d53..53a198828a7 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs @@ -68,7 +68,20 @@ public override void SetArgument(int index, object value) { var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); + { + var original = await Invoke(); + global::Orleans.Serialization.Invocation.Response copy = null; + try + { + return copy = responseCopier.Copy(original); + } + finally + { + if (!global::System.Object.ReferenceEquals(original, copy)) + original.Dispose(); + } + } + string value = await InvokeInner(); return factory.RentCopied(value, contexts); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs index e45ffd4dc65..7f6fd2c89af 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs @@ -68,7 +68,20 @@ public override void SetArgument(int index, object value) { var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); + { + var original = await Invoke(); + global::Orleans.Serialization.Invocation.Response copy = null; + try + { + return copy = responseCopier.Copy(original); + } + finally + { + if (!global::System.Object.ReferenceEquals(original, copy)) + original.Dispose(); + } + } + string value = await InvokeInner(); return factory.RentCopied(value, contexts); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs index 25034525a90..9895d058e02 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs @@ -65,7 +65,20 @@ public override void SetArgument(int index, object value) { var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); + { + var original = await Invoke(); + global::Orleans.Serialization.Invocation.Response copy = null; + try + { + return copy = responseCopier.Copy(original); + } + finally + { + if (!global::System.Object.ReferenceEquals(original, copy)) + original.Dispose(); + } + } + string value = await InvokeInner(); return factory.RentCopied(value, contexts); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs index b68e26faadf..9f179cd43cb 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs @@ -65,7 +65,20 @@ public override void SetArgument(int index, object value) { var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); + { + var original = await Invoke(); + global::Orleans.Serialization.Invocation.Response copy = null; + try + { + return copy = responseCopier.Copy(original); + } + finally + { + if (!global::System.Object.ReferenceEquals(original, copy)) + original.Dispose(); + } + } + string value = await InvokeInner(); return factory.RentCopied(value, contexts); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs index b8e11edb1e0..92de56a866f 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs @@ -36,7 +36,20 @@ public override void Dispose() { var factory = global::OrleansCodeGen.TestProject.RpcResponse_5C3A711CFactory.Resolve(provider); if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); + { + var original = await Invoke(); + global::Orleans.Serialization.Invocation.Response copy = null; + try + { + return copy = responseCopier.Copy(original); + } + finally + { + if (!global::System.Object.ReferenceEquals(original, copy)) + original.Dispose(); + } + } + global::System.Guid value = await InvokeInner(); return factory.RentCopied(value, contexts); } @@ -86,7 +99,20 @@ public override void Dispose() { var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); + { + var original = await Invoke(); + global::Orleans.Serialization.Invocation.Response copy = null; + try + { + return copy = responseCopier.Copy(original); + } + finally + { + if (!global::System.Object.ReferenceEquals(original, copy)) + original.Dispose(); + } + } + string value = await InvokeInner(); return factory.RentCopied(value, contexts); } @@ -136,7 +162,20 @@ public override void Dispose() { var factory = global::OrleansCodeGen.TestProject.RpcResponse_6A3EE8F4Factory.Resolve(provider); if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); + { + var original = await Invoke(); + global::Orleans.Serialization.Invocation.Response copy = null; + try + { + return copy = responseCopier.Copy(original); + } + finally + { + if (!global::System.Object.ReferenceEquals(original, copy)) + original.Dispose(); + } + } + global::System.Tuple value = await InvokeInner(); return factory.RentCopied(value, contexts); } @@ -186,7 +225,20 @@ public override void Dispose() { var factory = global::OrleansCodeGen.TestProject.RpcResponse_AFB713E4Factory.Resolve(provider); if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); + { + var original = await Invoke(); + global::Orleans.Serialization.Invocation.Response copy = null; + try + { + return copy = responseCopier.Copy(original); + } + finally + { + if (!global::System.Object.ReferenceEquals(original, copy)) + original.Dispose(); + } + } + global::System.Tuple value = await InvokeInner(); return factory.RentCopied(value, contexts); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs index 61ffbd20ad7..5213a5818ea 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs @@ -36,7 +36,20 @@ public override void Dispose() { var factory = global::OrleansCodeGen.TestProject.RpcResponse_5C3A711CFactory.Resolve(provider); if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); + { + var original = await Invoke(); + global::Orleans.Serialization.Invocation.Response copy = null; + try + { + return copy = responseCopier.Copy(original); + } + finally + { + if (!global::System.Object.ReferenceEquals(original, copy)) + original.Dispose(); + } + } + global::System.Guid value = await InvokeInner(); return factory.RentCopied(value, contexts); } @@ -86,7 +99,20 @@ public override void Dispose() { var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); + { + var original = await Invoke(); + global::Orleans.Serialization.Invocation.Response copy = null; + try + { + return copy = responseCopier.Copy(original); + } + finally + { + if (!global::System.Object.ReferenceEquals(original, copy)) + original.Dispose(); + } + } + string value = await InvokeInner(); return factory.RentCopied(value, contexts); } @@ -136,7 +162,20 @@ public override void Dispose() { var factory = global::OrleansCodeGen.TestProject.RpcResponse_6A3EE8F4Factory.Resolve(provider); if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); + { + var original = await Invoke(); + global::Orleans.Serialization.Invocation.Response copy = null; + try + { + return copy = responseCopier.Copy(original); + } + finally + { + if (!global::System.Object.ReferenceEquals(original, copy)) + original.Dispose(); + } + } + global::System.Tuple value = await InvokeInner(); return factory.RentCopied(value, contexts); } @@ -186,7 +225,20 @@ public override void Dispose() { var factory = global::OrleansCodeGen.TestProject.RpcResponse_AFB713E4Factory.Resolve(provider); if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); + { + var original = await Invoke(); + global::Orleans.Serialization.Invocation.Response copy = null; + try + { + return copy = responseCopier.Copy(original); + } + finally + { + if (!global::System.Object.ReferenceEquals(original, copy)) + original.Dispose(); + } + } + global::System.Tuple value = await InvokeInner(); return factory.RentCopied(value, contexts); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs index f4157010400..552ee117ca5 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs @@ -63,7 +63,20 @@ public override void SetArgument(int index, object value) { var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); + { + var original = await Invoke(); + global::Orleans.Serialization.Invocation.Response copy = null; + try + { + return copy = responseCopier.Copy(original); + } + finally + { + if (!global::System.Object.ReferenceEquals(original, copy)) + original.Dispose(); + } + } + string value = await InvokeInner(); return factory.RentCopied(value, contexts); } @@ -141,7 +154,20 @@ public override void SetArgument(int index, object value) { var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); + { + var original = await Invoke(); + global::Orleans.Serialization.Invocation.Response copy = null; + try + { + return copy = responseCopier.Copy(original); + } + finally + { + if (!global::System.Object.ReferenceEquals(original, copy)) + original.Dispose(); + } + } + string value = await InvokeInner(); return factory.RentCopied(value, contexts); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs index cc6bb7cd909..8c2dcca45d4 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs @@ -63,7 +63,20 @@ public override void SetArgument(int index, object value) { var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); + { + var original = await Invoke(); + global::Orleans.Serialization.Invocation.Response copy = null; + try + { + return copy = responseCopier.Copy(original); + } + finally + { + if (!global::System.Object.ReferenceEquals(original, copy)) + original.Dispose(); + } + } + string value = await InvokeInner(); return factory.RentCopied(value, contexts); } @@ -141,7 +154,20 @@ public override void SetArgument(int index, object value) { var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); + { + var original = await Invoke(); + global::Orleans.Serialization.Invocation.Response copy = null; + try + { + return copy = responseCopier.Copy(original); + } + finally + { + if (!global::System.Object.ReferenceEquals(original, copy)) + original.Dispose(); + } + } + string value = await InvokeInner(); return factory.RentCopied(value, contexts); } diff --git a/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs index 26b01a0ce05..598fe8cfeb4 100644 --- a/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs +++ b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs @@ -27,6 +27,7 @@ using Orleans.Serialization.Invocation; using Orleans.Serialization.Serializers; using Orleans.Serialization.Session; +using UnitTests.GrainInterfaces; using Xunit; namespace UnitTests.Serialization; @@ -37,6 +38,65 @@ namespace UnitTests.Serialization; [TestCategory("BVT"), TestCategory("Serialization")] public sealed class SelfWritingResponseOwnershipTests { + [Theory] + [InlineData(false, false, "Distinct")] + [InlineData(false, true, "Distinct")] + [InlineData(true, false, "Distinct")] + [InlineData(true, true, "Distinct")] + [InlineData(false, false, "Same")] + [InlineData(false, true, "Same")] + [InlineData(true, false, "Same")] + [InlineData(true, true, "Same")] + [InlineData(false, false, "Throw")] + [InlineData(false, true, "Throw")] + [InlineData(true, false, "Throw")] + [InlineData(true, true, "Throw")] + public async Task GeneratedCompatibilityFallback_TransfersOrReturnsOriginalExactlyOnce(bool observer, bool filtered, string behavior) + { + var counts = new Counts { ReturnInput = behavior == "Same", ThrowCopy = behavior == "Throw" }; + var values = new List { 17, 23, 41 }; + var target = Substitute.For(); + target.ModifyReturnList_Test().Returns(Task.FromResult(values)); + var request = typeof(IConcurrentGrain).Assembly.GetTypes() + .Where(static type => !type.IsAbstract && !type.ContainsGenericParameters && typeof(IInvokable).IsAssignableFrom(type) + && type.Name.StartsWith("Invokable_IConcurrentGrain_", StringComparison.Ordinal)) + .Select(static type => (IInvokable)Activator.CreateInstance(type)!) + .Single(static request => request.GetMethodName() == nameof(IConcurrentGrain.ModifyReturnList_Test)); + Assert.IsAssignableFrom(request); + var filter = filtered ? new CallbackFilter(context => context.Invoke()) : null; + await using var fixture = new SendFixture(counts, filter, target); + using var response = await fixture.Invoke(request, observer); + Assert.Equal(1, counts.ResponseCopies); + Assert.NotNull(counts.FallbackOriginal); + Assert.False(fixture.Provider.TryGetRawResponseReader(typeof(List), out _)); + if (behavior == "Same") + { + Assert.Same(counts.FallbackOriginal, response); + Assert.Same(values, response.Result); + Assert.Equal(0, counts.PayloadCopies); + Assert.False(counts.OriginalWasPooledAtSend); + } + else + { + Assert.Null(counts.FallbackOriginal.TypedResult); + Assert.True(counts.OriginalWasPooledAtSend); + Assert.True(counts.OriginalWasReturnedOnce); + Assert.Equal(1, counts.PayloadCopies); + if (behavior == "Throw") + { + Assert.Same(counts.CopyFailure, response.Exception); + } + else + { + Assert.Null(response.Exception); + Assert.NotSame(counts.FallbackOriginal, response); + Assert.NotSame(values, response.Result); + values.Clear(); + Assert.Equal(new[] { 17, 23, 41 }, Assert.IsType>(response.Result)); + } + } + } + [Theory] [InlineData(false, false)] [InlineData(false, true)] @@ -350,6 +410,9 @@ private sealed class Counts public bool ThrowCopy; public bool ReturnInput; public Exception CopyFailure { get; } = new InvalidOperationException("payload copy failed"); + public Response>? FallbackOriginal; + public bool OriginalWasPooledAtSend; + public bool OriginalWasReturnedOnce; public Payload Copy(Payload source) { @@ -447,6 +510,7 @@ private sealed class CountingResponseCopier(Counts counts, ICodecProvider provid public Response? DeepCopy(Response? input, CopyContext context) { if (input is null) return null; + if (input is Response> list) return CopyListResponse(list, counts); counts.ResponseCopies++; if (counts.ReturnInput) return input; if (input.Exception is not null) return input; @@ -454,6 +518,23 @@ private sealed class CountingResponseCopier(Counts counts, ICodecProvider provid } } + private static Response> CopyListResponse(Response> input, Counts counts) + { + counts.ResponseCopies++; + counts.FallbackOriginal = input; + if (counts.ReturnInput) return input; + counts.PayloadCopies++; + if (counts.ThrowCopy) throw counts.CopyFailure; + return (Response>)Response.FromResult(new List(input.TypedResult!)); + } + + private sealed class FallbackListCopier(Counts counts) : IDeepCopier>> + { + [return: NotNullIfNotNull(nameof(input))] + public Response>? DeepCopy(Response>? input, CopyContext context) + => input is null ? null : CopyListResponse(input, counts); + } + private sealed class UnusedResponseCodec : IFieldCodec { public void WriteField(ref Writer writer, uint fieldIdDelta, Type? expectedType, Response? value) @@ -495,7 +576,8 @@ private sealed class SendFixture : IAsyncDisposable, IResponseCompletionSource private readonly InsideRuntimeClient _runtime; private readonly HostedClient _hosted; private readonly InvokableObjectManager _manager; - private readonly Observer _observer = new(); + private readonly IAddressable _observer; + private readonly Counts _counts; private readonly ObserverGrainId _observerId = ObserverGrainId.Create(ClientGrainId.Create("response-copy"), IdSpan.Create("observer")); private readonly TaskCompletionSource _completion = new(TaskCreationOptions.RunContinuationsAsynchronously); private readonly SharedMemoryPool _memory = new(); @@ -505,15 +587,21 @@ private sealed class SendFixture : IAsyncDisposable, IResponseCompletionSource public bool HasResponse => _sentResponse is not null; public Exception? HandoffFailure { get; set; } public Dictionary? InitialContext { get; set; } + public CodecProvider Provider => _services.GetRequiredService(); - public SendFixture(Counts counts, IIncomingGrainCallFilter? filter) + public SendFixture(Counts counts, IIncomingGrainCallFilter? filter, IAddressable? target = null) { + _counts = counts; + _observer = target ?? new Observer(); var services = new ServiceCollection(); services.AddSerializer(builder => builder.Configure(options => { options.AddSerializer(_ => new UnusedResponseCodec(), provider => new CountingResponseCopier(counts, provider)); options.AddSerializer(_ => new UnusedHolderCodec(), provider => new CountingHolderCopier(counts, provider)); options.AddCopier(typeof(SendFailureCopier)); + options.AddSerializer>>( + provider => new PooledResponseCodec, IFieldCodec>>(provider.GetCodec>()), + _ => new FallbackListCopier(counts)); })); services.AddLogging(); services.AddMetrics(); @@ -566,16 +654,18 @@ public SendFixture(Counts counts, IIncomingGrainCallFilter? filter) _serializer = new MessageSerializer(_services.GetRequiredService(), _memory, options.Value); } - public async Task Invoke(LegacyRequest request, bool observer) + public async Task Invoke(IInvokable request, bool observer) { await Execute(request, observer); - return await _completion.Task.WaitAsync(TimeSpan.FromSeconds(60), TestContext.Current.CancellationToken); + var response = await _completion.Task.WaitAsync(TimeSpan.FromSeconds(60), TestContext.Current.CancellationToken); + _sentResponse = null; + return response; } - public async Task Execute(LegacyRequest request, bool observer, + public async Task Execute(IInvokable request, bool observer, Message.Directions direction = Message.Directions.Request, bool expireAfterInvocation = false) { - request.Bind(_services.GetRequiredService()); + if (request is LegacyRequest legacy) legacy.Bind(_services.GetRequiredService()); _request = new Message { Id = new CorrelationId(7123), @@ -587,7 +677,8 @@ public async Task Execute(LegacyRequest request, bool observer, BodyObject = request, RequestContextData = InitialContext, }; - if (expireAfterInvocation) request.AfterInvocation = () => _request.TimeToLive = TimeSpan.FromMilliseconds(-1); + if (expireAfterInvocation) + Assert.IsAssignableFrom(request).AfterInvocation = () => _request.TimeToLive = TimeSpan.FromMilliseconds(-1); if (observer) { _manager.Dispatch(_request); @@ -604,6 +695,7 @@ public async Task Execute(LegacyRequest request, bool observer, new OrleansInstruments(_services.GetRequiredService()))))); var target = Substitute.For(); target.GrainInstance.Returns(_observer); + target.GetTarget().Returns(_observer); target.GrainId.Returns(_request.TargetGrain); target.ActivationServices.Returns(_services); await _runtime.Invoke(target, _request); @@ -650,6 +742,16 @@ public async Task AssertFrameRoundTrip(Response response) void IResponseCompletionSource.Complete(Response value) { Assert.Null(_sentResponse); + if (_counts.FallbackOriginal is { } original && (!_counts.ReturnInput || _counts.ThrowCopy)) + { + var first = ResponsePool.Get>(); + var second = ResponsePool.Get>(); + _counts.OriginalWasPooledAtSend = ReferenceEquals(original, first); + _counts.OriginalWasReturnedOnce = !ReferenceEquals(original, second); + second.Dispose(); + first.Dispose(); + } + _sentResponse = value; _completion.TrySetResult(value); } From 89602d1706b64c19ff2d8c033446d327b433d8d7 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Mon, 5 Oct 2026 15:56:06 -0700 Subject: [PATCH 32/54] fix(rpc): restore post-filter isolation and close generic activators --- .../docs/implementation/serialization.md | 6 +- .../SerializerFactoryGenerator.cs | 2 + src/Orleans.Core/Core/GrainMethodInvoker.cs | 27 +++--- .../Runtime/InvokableObjectManager.cs | 4 +- .../Core/InsideRuntimeClient.cs | 4 +- .../OrleansSourceGeneratorTests.cs | 13 ++- .../SelfWritingResponseOwnershipTests.cs | 97 ++++++++++++++----- 7 files changed, 103 insertions(+), 50 deletions(-) diff --git a/docs/site/src/content/docs/implementation/serialization.md b/docs/site/src/content/docs/implementation/serialization.md index 6b9c79629e0..fbcbbc6d44a 100644 --- a/docs/site/src/content/docs/implementation/serialization.md +++ b/docs/site/src/content/docs/implementation/serialization.md @@ -135,6 +135,8 @@ Arguments and result values use normal Orleans.Serialization codecs and copiers. For supported non-generic methods using the built-in task and value-task request bases, generated invokables also implement . The runtime selects this contract in the ordinary, incoming-filter, and observer paths. The invokable binds the selected serialization dependencies and rents a concrete, non-generic response holder after copying a mutable result. Immutable results retain their existing copy semantics. Isolation completes before incoming filters resume, and this path creates one pooled envelope for the successful result. +Incoming filters receive an isolated result and can transform its envelope or nested payload references. After the filter chain completes, the runtime copies the selected result for delivery, preserving isolation for both local callers and deferred message serialization. Calls with no incoming filters transfer their invocation-time copy directly to the messaging pipeline. Expired and one-way requests release their owned response without an outgoing copy. + Generated holders implement . The message serializer selects their direct writer before runtime-type codec lookup. Primitive holders call the existing static primitive codecs; reference holders use their bound concrete result codec and the message's serialization session. The wire representation retains the result-type header, field zero, end marker, null behavior, cycles, and shared references. Returning a holder to its pool clears both its result and its provider-owned factory binding. The receiving message serializer first consults using the result type from the wire header. Generated registrations reconstruct a bound holder directly. Compatibility paths retain ordinary response codecs for custom response/payload implementations, custom invokable bases, and unresolved generic contracts. Generated direct factories activate only when the selected result and response codecs/copiers match the canonical implementations, so explicit application behavior retains precedence. @@ -149,9 +151,9 @@ The finite response graph supplies successful typed results and completed-respon These supplemental registrations are defaults: explicit closed factory registrations take precedence in either configuration order. Generated factories and registered metadata use one resolution pipeline, with closed services selected first. Direct-holder factories and raw-reader registrations bind the selected provider implementations in both JIT and native execution. Custom application codec/copier selection uses the compatibility invocation and serialization path. -Generated metadata also supplies static response factories for closed generated result models. These factories construct the model's canonical generated codec and copier using their actual constructor signatures, including available generated activators from referenced assemblies. Source-known arrays, tuples, collections, and surrogate value serializers contribute their closed construction services. Interface contracts retain registered metadata dispatch and propagate their dependency requirements. Reference-assembly construction uses the producer's available constructor contracts and explicitly identified members. +Generated metadata also supplies static response factories for closed generated result models. These factories construct the model's canonical generated codec and copier using their actual constructor signatures, including closed generic generated activators and available generated activators from referenced assemblies. Source-known arrays, tuples, collections, and surrogate value serializers contribute their closed construction services. Interface contracts retain registered metadata dispatch and propagate their dependency requirements. Reference-assembly construction uses the producer's available constructor contracts and explicitly identified members. -Inferred defaults participate when their complete construction graph uses closed service factories, provider-owned services, or explicit instance registrations. Constructor dependencies supplied by ordinary dependency-injection factories or implementation types select canonical metadata activation before the provider starts a serialization construction transaction. carries these dependency edges, preserving explicit registration priority, canonical service identity, and graph rollback. Default activation uses the existing reference- or value-type activator implementation, and custom activation retains its declared contract. Serializer contexts contribute their complete finite dependency graphs and validate each declared member shape. +Inferred defaults participate when their complete construction graph uses closed service factories and provider-owned services. Constructor dependencies supplied by ordinary dependency-injection registrations select canonical metadata activation before the provider starts a serialization construction transaction. carries these dependency edges, preserving explicit registration priority, canonical service identity, and graph rollback. Default activation uses the existing reference- or value-type activator implementation, and custom activation retains its declared contract. Serializer contexts contribute their complete finite dependency graphs and validate each declared member shape. The same collector closes source-known argument construction dependencies selected by generated proxy constructors. Reference and value tuples use their existing closed codec and copier implementations with their declared element services. Parameter-only one-way contracts register the required construction services while completion and result contracts also register their response graphs. diff --git a/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs b/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs index 901026f59da..80ef3cb9a69 100644 --- a/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs +++ b/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs @@ -199,6 +199,8 @@ internal sealed record Failure(ITypeSymbol Type, string Reason); && SymbolEqualityComparer.Default.Equals(type.ContainingAssembly, services.Compilation.Assembly)) { var activatorName = $"global::{constructionModel.GeneratedNamespace}.{ActivatorGenerator.GetSimpleClassName(constructionModel)}"; + if (type.IsGenericType) + activatorName += $"<{string.Join(", ", type.TypeArguments.Select(Name))}>"; var activatorModel = type.IsGenericType ? SerializableSourceOutputGenerator.CreateSerializableTypeDescription(services, type.OriginalDefinition)! : constructionModel; diff --git a/src/Orleans.Core/Core/GrainMethodInvoker.cs b/src/Orleans.Core/Core/GrainMethodInvoker.cs index 99259e30862..61e2b0a072a 100644 --- a/src/Orleans.Core/Core/GrainMethodInvoker.cs +++ b/src/Orleans.Core/Core/GrainMethodInvoker.cs @@ -25,8 +25,7 @@ internal sealed class GrainMethodInvoker : IIncomingGrainCallContext, IDisposabl private readonly ICodecProvider codecProvider; private readonly CopyContextPool copyContexts; private Response? ownedResponse; - private bool ownedResponseIsCopied; - private List<(Response Response, bool IsCopied)>? otherOwnedResponses; + private List? otherOwnedResponses; private int stage; /// @@ -80,13 +79,11 @@ public object? Result public Response? Response { get; set; } - internal (Response Response, bool IsCopied) TakeResponse() + internal Response TakeResponse() { var response = Response!; - var isCopied = false; if (ReferenceEquals(response, ownedResponse)) { - isCopied = ownedResponseIsCopied; ownedResponse = null; } @@ -94,16 +91,15 @@ public object? Result { for (var i = others.Count - 1; i >= 0; i--) { - if (ReferenceEquals(response, others[i].Response)) + if (ReferenceEquals(response, others[i])) { - isCopied = others[i].IsCopied; others.RemoveAt(i); } } } Response = null; - return (response, isCopied); + return response; } public void Dispose() @@ -115,7 +111,7 @@ public void Dispose() try { if (current is not null && !ReferenceEquals(current, response) - && (otherOwnedResponses is null || !otherOwnedResponses.Exists(entry => ReferenceEquals(current, entry.Response)))) + && (otherOwnedResponses is null || !otherOwnedResponses.Exists(entry => ReferenceEquals(current, entry)))) { current.Dispose(); } @@ -131,29 +127,28 @@ public void Dispose() if (otherOwnedResponses is { } others) { otherOwnedResponses = null; - foreach (var entry in others) entry.Response.Dispose(); + foreach (var entry in others) entry.Dispose(); } } } } - private void SetOwnedResponse(Response response, bool isCopied) + private void SetOwnedResponse(Response response) { if (ownedResponse is { } previous && !ReferenceEquals(previous, response)) { - (otherOwnedResponses ??= []).Add((previous, ownedResponseIsCopied)); + (otherOwnedResponses ??= []).Add(previous); } if (otherOwnedResponses is { } others) { for (var i = others.Count - 1; i >= 0; i--) { - if (ReferenceEquals(response, others[i].Response)) others.RemoveAt(i); + if (ReferenceEquals(response, others[i])) others.RemoveAt(i); } } ownedResponse = Response = response; - ownedResponseIsCopied = isCopied; } public GrainId? SourceId => message.SendingGrain is { IsDefault: false } source ? source : null; @@ -220,14 +215,14 @@ public async Task Invoke() // Propagate exceptions to other filters. if (response.Exception is { } exception) { - SetOwnedResponse(response, isCopied: false); + SetOwnedResponse(response); ExceptionDispatchInfo.Capture(exception).Throw(); } if (request is not IResponseInvokable) response = ResponseCopyBoundary.CopyAndDispose(response, this.responseCopier); - SetOwnedResponse(response, isCopied: true); + SetOwnedResponse(response); return; } diff --git a/src/Orleans.Core/Runtime/InvokableObjectManager.cs b/src/Orleans.Core/Runtime/InvokableObjectManager.cs index 7dee0df5766..3374b3c3db0 100644 --- a/src/Orleans.Core/Runtime/InvokableObjectManager.cs +++ b/src/Orleans.Core/Runtime/InvokableObjectManager.cs @@ -390,7 +390,9 @@ private async Task ProcessMessageAsync(Message message) _manager._responseCopier, _manager.runtimeClient.ServiceProvider.GetRequiredService(), _manager.runtimeClient.ServiceProvider.GetRequiredService()); await invoker.Invoke(); - (response, isCopied) = invoker.TakeResponse(); + response = invoker.TakeResponse(); + // Filters can introduce grain-owned references anywhere in the result graph. + isCopied = false; } else { diff --git a/src/Orleans.Runtime/Core/InsideRuntimeClient.cs b/src/Orleans.Runtime/Core/InsideRuntimeClient.cs index b2bb5d579de..d265576225f 100644 --- a/src/Orleans.Runtime/Core/InsideRuntimeClient.cs +++ b/src/Orleans.Runtime/Core/InsideRuntimeClient.cs @@ -326,7 +326,7 @@ public async Task Invoke(IGrainContext target, Message message) using var invoker = new GrainMethodInvoker(message, target, invokable, GrainCallFilters, this.interfaceToImplementationMapping, this.responseCopier, this.responseCodecProvider, this.responseCopyContexts); await invoker.Invoke(); - (response, isCopied) = invoker.TakeResponse(); + response = invoker.TakeResponse(); } else { @@ -405,7 +405,7 @@ private void SafeSendResponse(Message message, Response response, bool isCopied) Response? ownedResponse = response; try { - if (!isCopied) + if (!isCopied && !message.IsExpired) { ownedResponse = null; ownedResponse = ResponseCopyBoundary.CopyAndDispose(response, this._deepCopier); diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index 9a44e9f7652..2a1c45eb01f 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -2441,17 +2441,20 @@ public interface IContract : IGrainWithIntegerKey } [Theory] - [InlineData("string")] - [InlineData("int")] - public async Task RpcClosedGenericModelFactoriesUseDefinitionConstructorContracts(string argument) + [InlineData("string", false)] + [InlineData("int", false)] + [InlineData("string", true)] + [InlineData("int", true)] + public async Task RpcClosedGenericModelFactoriesUseDefinitionConstructorContracts(string argument, bool generatedActivator) { - var compilation = await CreateCompilation(""" + var compilation = await CreateCompilation($$""" using Orleans; namespace GenericConstruction; [GenerateSerializer] public sealed class Payload { [Id(0)] private T _value; + {{(generatedActivator ? "[GeneratedActivatorConstructor]" : "")}} public Payload(T value) => _value = value; public T Value => _value; } @@ -2464,6 +2467,8 @@ public sealed class Payload Assert.Contains($"IActivator>", graph.ConfigurationStatements); Assert.Contains("provider), provider)", graph.ConfigurationStatements); Assert.DoesNotContain("Payload", graph.ConfigurationStatements); + if (generatedActivator) + Assert.Contains($"new global::OrleansCodeGen.GenericConstruction.Activator_Payload<{argument}>(", graph.ConfigurationStatements); var generated = RunSourceGenerator(compilation); Assert.Empty(generated.Diagnostics); var exercise = $$""" diff --git a/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs index 598fe8cfeb4..802b5a7bea1 100644 --- a/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs +++ b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs @@ -66,7 +66,7 @@ public async Task GeneratedCompatibilityFallback_TransfersOrReturnsOriginalExact var filter = filtered ? new CallbackFilter(context => context.Invoke()) : null; await using var fixture = new SendFixture(counts, filter, target); using var response = await fixture.Invoke(request, observer); - Assert.Equal(1, counts.ResponseCopies); + Assert.Equal(filtered && behavior != "Throw" ? 2 : 1, counts.ResponseCopies); Assert.NotNull(counts.FallbackOriginal); Assert.False(fixture.Provider.TryGetRawResponseReader(typeof(List), out _)); if (behavior == "Same") @@ -81,7 +81,7 @@ public async Task GeneratedCompatibilityFallback_TransfersOrReturnsOriginalExact Assert.Null(counts.FallbackOriginal.TypedResult); Assert.True(counts.OriginalWasPooledAtSend); Assert.True(counts.OriginalWasReturnedOnce); - Assert.Equal(1, counts.PayloadCopies); + Assert.Equal(filtered && behavior != "Throw" ? 2 : 1, counts.PayloadCopies); if (behavior == "Throw") { Assert.Same(counts.CopyFailure, response.Exception); @@ -102,7 +102,7 @@ public async Task GeneratedCompatibilityFallback_TransfersOrReturnsOriginalExact [InlineData(false, true)] [InlineData(true, false)] [InlineData(true, true)] - public async Task DirectResponse_ReachesSendWithOneCopyAndOneOwnedHolder(bool observer, bool filtered) + public async Task DirectResponse_CopiesAtInvocationAndAfterFiltersWithOwnedHolders(bool observer, bool filtered) { var counts = new Counts(); var payload = new Payload { Values = [17, 23, 41] }; @@ -120,11 +120,12 @@ public async Task DirectResponse_ReachesSendWithOneCopyAndOneOwnedHolder(bool ob using var response = await fixture.Invoke(request, observer); Assert.Null(response.Exception); - Assert.Equal(1, counts.PayloadCopies); - Assert.Equal(1, counts.Rents); - Assert.Same(request.ReturnedResponse, response); - Assert.Equal(0, counts.Returns); - Assert.Equal(0, counts.ResponseCopies); + Assert.Equal(filtered ? 2 : 1, counts.PayloadCopies); + Assert.Equal(filtered ? 2 : 1, counts.Rents); + if (filtered) Assert.NotSame(request.ReturnedResponse, response); + else Assert.Same(request.ReturnedResponse, response); + Assert.Equal(filtered ? 1 : 0, counts.Returns); + Assert.Equal(filtered ? 1 : 0, counts.ResponseCopies); Assert.NotSame(payload, response.Result); var result = Assert.IsType(response.Result); Assert.Equal(new[] { 17, 23, 41 }, result.Values); @@ -132,7 +133,7 @@ public async Task DirectResponse_ReachesSendWithOneCopyAndOneOwnedHolder(bool ob Assert.Equal(new[] { 17, 23, 41 }, result.Values); await fixture.AssertFrameRoundTrip(response); response.Dispose(); - Assert.Equal(1, counts.Returns); + Assert.Equal(counts.Rents, counts.Returns); } [Theory] @@ -140,7 +141,7 @@ public async Task DirectResponse_ReachesSendWithOneCopyAndOneOwnedHolder(bool ob [InlineData(false, true)] [InlineData(true, false)] [InlineData(true, true)] - public async Task LegacyResponse_CopiesOnceAndReturnsBothOwnedWrappers(bool observer, bool filtered) + public async Task LegacyResponse_CopiesAtInvocationAndAfterFiltersAndReturnsOwnedWrappers(bool observer, bool filtered) { var counts = new Counts(); var payload = new Payload { Values = [17, 23, 41] }; @@ -158,13 +159,59 @@ public async Task LegacyResponse_CopiesOnceAndReturnsBothOwnedWrappers(bool obse Assert.Null(response.Exception); Assert.NotSame(request.ReturnedResponse, response); - Assert.Equal(1, counts.PayloadCopies); - Assert.Equal(1, counts.ResponseCopies); - Assert.Equal(2, counts.Rents); - Assert.Equal(1, counts.Returns); + Assert.Equal(filtered ? 2 : 1, counts.PayloadCopies); + Assert.Equal(filtered ? 2 : 1, counts.ResponseCopies); + Assert.Equal(filtered ? 3 : 2, counts.Rents); + Assert.Equal(filtered ? 2 : 1, counts.Returns); Assert.Equal(new[] { 17, 23, 41 }, Assert.IsType(response.Result).Values); response.Dispose(); - Assert.Equal(2, counts.Returns); + Assert.Equal(counts.Rents, counts.Returns); + } + + [Theory] + [InlineData(false, false, false)] + [InlineData(false, false, true)] + [InlineData(false, true, false)] + [InlineData(false, true, true)] + [InlineData(true, false, false)] + [InlineData(true, false, true)] + [InlineData(true, true, false)] + [InlineData(true, true, true)] + public async Task FilterMutatesExistingResponse_IsolatesEnvelopeAndNestedReferences(bool observer, bool direct, bool replaceResult) + { + var counts = new Counts(); + var original = new Payload { Values = [17, 23, 41] }; + var replacement = new Payload { Values = [5, 8, 13] }; + Payload filterResult = null!; + var filter = new CallbackFilter(async context => + { + await context.Invoke(); + var response = context.Response; + if (replaceResult) response!.Result = replacement; + else Assert.IsType(context.Result).Values = replacement.Values; + Assert.Same(response, context.Response); + filterResult = Assert.IsType(context.Result); + Assert.Same(replacement.Values, filterResult.Values); + }); + await using var fixture = new SendFixture(counts, filter); + LegacyRequest request = direct ? new DirectRequest(original, counts) : new LegacyRequest(original, counts); + + using var response = await fixture.Invoke(request, observer); + + Assert.Null(response.Exception); + var result = Assert.IsType(response.Result); + Assert.NotSame(filterResult, result); + Assert.NotSame(replacement.Values, result.Values); + Assert.Equal(new[] { 5, 8, 13 }, result.Values); + Assert.Equal(2, counts.PayloadCopies); + Assert.Equal(direct ? 1 : 2, counts.ResponseCopies); + Assert.Equal(direct ? 2 : 3, counts.Rents); + Assert.Equal(counts.Rents - 1, counts.Returns); + replacement.Values.Clear(); + Assert.Equal(new[] { 5, 8, 13 }, result.Values); + await fixture.AssertFrameRoundTrip(response); + response.Dispose(); + Assert.Equal(counts.Rents, counts.Returns); } [Theory] @@ -203,7 +250,7 @@ public async Task FilterSelectedResponse_IsCopiedAndReleasesSupersededRoot(bool [Theory] [InlineData(false)] [InlineData(true)] - public async Task FilterRestoresEarlierRoot_ReusesItsIsolationAndDisposesOtherRoot(bool observer) + public async Task FilterRestoresEarlierRoot_IsolatesSelectedResultAndDisposesOtherRoot(bool observer) { var counts = new Counts(); var filter = new CallbackFilter(async context => @@ -217,12 +264,12 @@ public async Task FilterRestoresEarlierRoot_ReusesItsIsolationAndDisposesOtherRo await using var fixture = new SendFixture(counts, filter); using var response = await fixture.Invoke(new DirectRequest(new Payload { Values = [17] }, counts), observer); Assert.Null(response.Exception); - Assert.Equal(2, counts.PayloadCopies); - Assert.Equal(0, counts.ResponseCopies); - Assert.Equal(2, counts.Rents); - Assert.Equal(1, counts.Returns); - response.Dispose(); + Assert.Equal(3, counts.PayloadCopies); + Assert.Equal(1, counts.ResponseCopies); + Assert.Equal(3, counts.Rents); Assert.Equal(2, counts.Returns); + response.Dispose(); + Assert.Equal(counts.Rents, counts.Returns); } [Theory] @@ -276,7 +323,7 @@ public async Task CustomCopierReturnsInput_PreservesSelectionAndTransfersOneOwne using var response = await fixture.Invoke(request, observer); Assert.Null(response.Exception); Assert.Same(request.ReturnedResponse, response); - Assert.Equal(1, counts.ResponseCopies); + Assert.Equal(filtered ? 2 : 1, counts.ResponseCopies); Assert.Equal(0, counts.PayloadCopies); Assert.Equal(1, counts.Rents); Assert.Equal(0, counts.Returns); @@ -322,9 +369,9 @@ public async Task FailedHandoff_ReturnsCurrentHolderAndSurfacesFailure(bool obse }; using var response = await fixture.Invoke(new DirectRequest(new Payload { Values = [17] }, counts), observer); Assert.Same(failure, response.Exception); - Assert.Equal(1, counts.PayloadCopies); - Assert.Equal(1, counts.Rents); - Assert.Equal(1, counts.Returns); + Assert.Equal(2, counts.PayloadCopies); + Assert.Equal(2, counts.Rents); + Assert.Equal(2, counts.Returns); } [Theory] From cb8a886a35bc2049b0d0870a6d849f3c14c05e95 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Mon, 5 Oct 2026 16:24:23 -0700 Subject: [PATCH 33/54] fix(nativeaot): integrate rebased response factories and transport --- .../docs/implementation/serialization.md | 2 +- .../Serializers/CodecProvider.cs | 25 +++-- src/api/Orleans.Core/Orleans.Core.cs | 52 +++++++--- .../Orleans.Serialization.cs | 67 +++++++++++++ .../SelfWritingResponseMessageTests.cs | 94 ++++++------------- .../SelfWritingResponseOwnershipTests.cs | 44 +++------ .../RpcResponseTests.cs | 44 +++++++++ 7 files changed, 209 insertions(+), 119 deletions(-) diff --git a/docs/site/src/content/docs/implementation/serialization.md b/docs/site/src/content/docs/implementation/serialization.md index fbcbbc6d44a..8296c77fe48 100644 --- a/docs/site/src/content/docs/implementation/serialization.md +++ b/docs/site/src/content/docs/implementation/serialization.md @@ -153,7 +153,7 @@ These supplemental registrations are defaults: explicit closed factory registrat Generated metadata also supplies static response factories for closed generated result models. These factories construct the model's canonical generated codec and copier using their actual constructor signatures, including closed generic generated activators and available generated activators from referenced assemblies. Source-known arrays, tuples, collections, and surrogate value serializers contribute their closed construction services. Interface contracts retain registered metadata dispatch and propagate their dependency requirements. Reference-assembly construction uses the producer's available constructor contracts and explicitly identified members. -Inferred defaults participate when their complete construction graph uses closed service factories and provider-owned services. Constructor dependencies supplied by ordinary dependency-injection registrations select canonical metadata activation before the provider starts a serialization construction transaction. carries these dependency edges, preserving explicit registration priority, canonical service identity, and graph rollback. Default activation uses the existing reference- or value-type activator implementation, and custom activation retains its declared contract. Serializer contexts contribute their complete finite dependency graphs and validate each declared member shape. +Inferred defaults participate when their complete construction graph uses closed service factories and provider-owned services. Admission compares matching metadata implementation identities, and the closed factories supply the executable services. Constructor dependencies supplied by ordinary dependency-injection registrations select canonical metadata activation before the provider starts a serialization construction transaction. carries these dependency edges, preserving explicit registration priority, canonical service identity, and graph rollback. Default activation uses the existing reference- or value-type activator implementation, and custom activation retains its declared contract. Serializer contexts contribute their complete finite dependency graphs and validate each declared member shape. The same collector closes source-known argument construction dependencies selected by generated proxy constructors. Reference and value tuples use their existing closed codec and copier implementations with their declared element services. Parameter-only one-way contracts register the required construction services while completion and result contracts also register their response graphs. diff --git a/src/Orleans.Serialization/Serializers/CodecProvider.cs b/src/Orleans.Serialization/Serializers/CodecProvider.cs index f9834f58e91..c2d4f002a2b 100644 --- a/src/Orleans.Serialization/Serializers/CodecProvider.cs +++ b/src/Orleans.Serialization/Serializers/CodecProvider.cs @@ -689,7 +689,8 @@ private bool IsDefaultContractEligible(TypeManifestOptions.DefaultSerializerCont var role = contract.Service.IsConstructedGenericType ? contract.Service.GetGenericTypeDefinition() : null; var target = role is null ? contract.Service : contract.Service.GenericTypeArguments[0]; if (role is not null && contract.Implementation is { } implementation - && TrySelectImplementation(role, target, target.IsConstructedGenericType ? target.GetGenericTypeDefinition() : target, out var selected) + && TrySelectImplementation(role, target, target.IsConstructedGenericType ? target.GetGenericTypeDefinition() : target, + out var selected, out _, materializeImplementation: false) && !MatchesDefaultImplementation(selected, implementation, contract.CompatibleImplementation, target)) return false; foreach (var dependency in contract.Dependencies) @@ -713,15 +714,20 @@ private bool IsDefaultContractEligible(TypeManifestOptions.DefaultSerializerCont private static bool MatchesDefaultImplementation(Type selected, Type expected, Type? compatible, Type target) { if (selected == expected || selected == compatible) return true; - if (!selected.IsGenericTypeDefinition) return false; - if (expected.IsConstructedGenericType && selected == expected.GetGenericTypeDefinition()) return true; - if (compatible is { IsConstructedGenericType: true } && selected == compatible.GetGenericTypeDefinition()) return true; + if (!selected.IsGenericType) return false; + if (selected.IsGenericTypeDefinition) + { + if (expected.IsConstructedGenericType && selected == expected.GetGenericTypeDefinition()) return true; + if (compatible is { IsConstructedGenericType: true } && selected == compatible.GetGenericTypeDefinition()) return true; + } if (target.IsConstructedGenericType && target.GetGenericTypeDefinition() == typeof(Invocation.Response<>) - && expected.IsConstructedGenericType && expected.GenericTypeArguments[0] == target.GenericTypeArguments[0]) + && expected.IsConstructedGenericType && expected.GenericTypeArguments[0] == target.GenericTypeArguments[0] + && (!selected.IsConstructedGenericType || selected.GenericTypeArguments[0] == target.GenericTypeArguments[0])) { + var selectedDefinition = selected.GetGenericTypeDefinition(); var definition = expected.GetGenericTypeDefinition(); - return selected == typeof(Invocation.PooledResponseCodec<>) && definition == typeof(Invocation.PooledResponseCodec<,>) - || selected == typeof(Invocation.PooledResponseCopier<>) && definition == typeof(Invocation.PooledResponseCopier<,>); + return selectedDefinition == typeof(Invocation.PooledResponseCodec<>) && definition == typeof(Invocation.PooledResponseCodec<,>) + || selectedDefinition == typeof(Invocation.PooledResponseCopier<>) && definition == typeof(Invocation.PooledResponseCopier<,>); } return false; } @@ -1217,7 +1223,8 @@ private bool TrySelectImplementation( Type targetType, Type searchType, [NotNullWhen(true)] out Type? implementation, - out SerializationContract registration) + out SerializationContract registration, + bool materializeImplementation = true) { if (targetType != searchType && TrySelect(targetType, out implementation, out registration)) { @@ -1244,7 +1251,7 @@ bool TrySelect(Type? key, [NotNullWhen(true)] out Type? result, out Serializatio } var closed = candidate.Implementation; - if (closed.IsGenericTypeDefinition) + if (closed.IsGenericTypeDefinition && materializeImplementation) { var arguments = bindings is null ? targetType.GetGenericArguments() : new Type[bindings.Length]; if (bindings is not null) diff --git a/src/api/Orleans.Core/Orleans.Core.cs b/src/api/Orleans.Core/Orleans.Core.cs index 1f6279a1391..53b8ae3a3ff 100644 --- a/src/api/Orleans.Core/Orleans.Core.cs +++ b/src/api/Orleans.Core/Orleans.Core.cs @@ -3106,7 +3106,7 @@ public Copier_MembershipTableData(global::Orleans.Serialization.Activators.IActi [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - public sealed partial class Invokable_IMembershipTable_GrainReference_00BCE16F : global::Orleans.Runtime.TaskRequest + public sealed partial class Invokable_IMembershipTable_GrainReference_00BCE16F : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable { public override void Dispose() { } @@ -3124,6 +3124,8 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) { } } @@ -3131,7 +3133,7 @@ public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetH [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::Orleans.CompoundTypeAlias(new[] { "inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::Orleans.IMembershipTable), "00BCE16F" })] - public sealed partial class Invokable_IMembershipTable_GrainReference_4115A4B4 : global::Orleans.Runtime.TaskRequest + public sealed partial class Invokable_IMembershipTable_GrainReference_4115A4B4 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable { public System.Threading.CancellationToken arg0; public override bool IsCancellable { get { throw null; } } @@ -3158,6 +3160,8 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + public override void SetArgument(int index, object value) { } public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) { } @@ -3169,7 +3173,7 @@ public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetH [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::Orleans.CompoundTypeAlias(new[] { "inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::Orleans.IMembershipTable), "E06D3DBC" })] - public sealed partial class Invokable_IMembershipTable_GrainReference_47733EA8 : global::Orleans.Runtime.TaskRequest + public sealed partial class Invokable_IMembershipTable_GrainReference_47733EA8 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable { public global::Orleans.MembershipEntry arg0; public string arg1; @@ -3199,6 +3203,8 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + public override void SetArgument(int index, object value) { } public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) { } @@ -3210,7 +3216,7 @@ public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetH [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::Orleans.CompoundTypeAlias(new[] { "inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::Orleans.IMembershipTable), "FEF3AC5A" })] - public sealed partial class Invokable_IMembershipTable_GrainReference_60723C98 : global::Orleans.Runtime.TaskRequest + public sealed partial class Invokable_IMembershipTable_GrainReference_60723C98 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable { public global::Orleans.MembershipEntry arg0; public global::Orleans.TableVersion arg1; @@ -3239,6 +3245,8 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + public override void SetArgument(int index, object value) { } public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) { } @@ -3281,7 +3289,7 @@ public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetH [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::Orleans.CompoundTypeAlias(new[] { "inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::Orleans.IMembershipTable), "D851FB33" })] - public sealed partial class Invokable_IMembershipTable_GrainReference_92AB4F4C : global::Orleans.Runtime.TaskRequest + public sealed partial class Invokable_IMembershipTable_GrainReference_92AB4F4C : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable { public global::Orleans.Runtime.SiloAddress arg0; public System.Threading.CancellationToken arg1; @@ -3309,6 +3317,8 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + public override void SetArgument(int index, object value) { } public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) { } @@ -3498,7 +3508,7 @@ public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetH [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - public sealed partial class Invokable_IMembershipTable_GrainReference_D851FB33 : global::Orleans.Runtime.TaskRequest + public sealed partial class Invokable_IMembershipTable_GrainReference_D851FB33 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable { public global::Orleans.Runtime.SiloAddress arg0; public override void Dispose() { } @@ -3521,6 +3531,8 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + public override void SetArgument(int index, object value) { } public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) { } @@ -3529,7 +3541,7 @@ public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetH [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - public sealed partial class Invokable_IMembershipTable_GrainReference_E06D3DBC : global::Orleans.Runtime.TaskRequest + public sealed partial class Invokable_IMembershipTable_GrainReference_E06D3DBC : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable { public global::Orleans.MembershipEntry arg0; public string arg1; @@ -3554,6 +3566,8 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + public override void SetArgument(int index, object value) { } public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) { } @@ -3632,7 +3646,7 @@ public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetH [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - public sealed partial class Invokable_IMembershipTable_GrainReference_FEF3AC5A : global::Orleans.Runtime.TaskRequest + public sealed partial class Invokable_IMembershipTable_GrainReference_FEF3AC5A : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable { public global::Orleans.MembershipEntry arg0; public global::Orleans.TableVersion arg1; @@ -3656,6 +3670,8 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + public override void SetArgument(int index, object value) { } public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) { } @@ -4258,7 +4274,7 @@ public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetH [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::Orleans.CompoundTypeAlias(new[] { "inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::Orleans.Placement.Rebalancing.IActivationRebalancer), "D7EB6469" })] - public sealed partial class Invokable_IActivationRebalancer_GrainReference_D7EB6469 : global::Orleans.Runtime.Request + public sealed partial class Invokable_IActivationRebalancer_GrainReference_D7EB6469 : global::Orleans.Runtime.Request, global::Orleans.Serialization.Invocation.IResponseInvokable { public bool arg0; public override void Dispose() { } @@ -4281,6 +4297,8 @@ public override void Dispose() { } protected override System.Threading.Tasks.ValueTask InvokeInner() { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + public override void SetArgument(int index, object value) { } public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) { } @@ -5972,7 +5990,7 @@ public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetH [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::Orleans.CompoundTypeAlias(new[] { "inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::Orleans.Runtime.IManagementGrain), "AEDE93F6" })] - public sealed partial class Invokable_IManagementGrain_GrainReference_4C2438F7 : global::Orleans.Runtime.TaskRequest + public sealed partial class Invokable_IManagementGrain_GrainReference_4C2438F7 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable { public global::Orleans.Runtime.GrainReference arg0; public System.Threading.CancellationToken arg1; @@ -6000,6 +6018,8 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + public override void SetArgument(int index, object value) { } public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) { } @@ -6327,7 +6347,7 @@ public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetH [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::Orleans.CompoundTypeAlias(new[] { "inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::Orleans.Runtime.IManagementGrain), "GetGrainActivationCount" })] - public sealed partial class Invokable_IManagementGrain_GrainReference_AEDE93F6 : global::Orleans.Runtime.TaskRequest + public sealed partial class Invokable_IManagementGrain_GrainReference_AEDE93F6 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable { public global::Orleans.Runtime.GrainReference arg0; public override void Dispose() { } @@ -6350,6 +6370,8 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + public override void SetArgument(int index, object value) { } public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) { } @@ -6359,7 +6381,7 @@ public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetH [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::Orleans.CompoundTypeAlias(new[] { "inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::Orleans.Runtime.IManagementGrain), "D7365B43" })] - public sealed partial class Invokable_IManagementGrain_GrainReference_B15A0F47 : global::Orleans.Runtime.TaskRequest + public sealed partial class Invokable_IManagementGrain_GrainReference_B15A0F47 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable { public System.Threading.CancellationToken arg0; public override bool IsCancellable { get { throw null; } } @@ -6386,6 +6408,8 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + public override void SetArgument(int index, object value) { } public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) { } @@ -6501,7 +6525,7 @@ public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetH [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::Orleans.CompoundTypeAlias(new[] { "inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::Orleans.Runtime.IManagementGrain), "GetTotalActivationCount" })] - public sealed partial class Invokable_IManagementGrain_GrainReference_D7365B43 : global::Orleans.Runtime.TaskRequest + public sealed partial class Invokable_IManagementGrain_GrainReference_D7365B43 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable { public override void Dispose() { } @@ -6519,6 +6543,8 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) { } } diff --git a/src/api/Orleans.Serialization/Orleans.Serialization.cs b/src/api/Orleans.Serialization/Orleans.Serialization.cs index 3c9837841ef..b02b4141c45 100644 --- a/src/api/Orleans.Serialization/Orleans.Serialization.cs +++ b/src/api/Orleans.Serialization/Orleans.Serialization.cs @@ -3435,6 +3435,20 @@ public void AddCopier(System.Type type, System.Type targetType) { } public void AddCopier(System.Type type) { } + public void AddDefaultSerializer(System.Func> codecFactory, System.Func> copierFactory) { } + + public void AddDefaultSerializer(System.Func> codecFactory, System.Func> copierFactory, System.Type? compatibleCodecType = null, System.Type? compatibleCopierType = null, System.Type[]? codecDependencies = null, System.Type[]? copierDependencies = null) + where TCodec : class, Codecs.IFieldCodec where TCopier : class, Cloning.IDeepCopier { } + + public void AddDefaultSerializerService(System.Func factory, System.Type[] dependencies) + where TService : class { } + + public void AddDefaultSerializerService(System.Func factory) + where TService : class { } + + public void AddDefaultSerializerService(System.Func factory, System.Type? compatibleImplementationType = null, System.Type[]? dependencies = null) + where TService : class where TImplementation : class, TService { } + public void AddFieldCodec(System.Type type, System.Type targetType) { } public void AddFieldCodec(System.Type type) { } @@ -3445,6 +3459,8 @@ public void AddInterfaceImplementation(System.Type type) { } public void AddInterfaceProxy(System.Type type) { } + public void AddRawResponseReader(System.Func factory) { } + public void AddSerializationContract(System.Type type, System.Type contractType, SerializationType targetType, SerializationType? surrogateType = null) { } public void AddSerializer(System.Type type, System.Type targetType) { } @@ -3601,18 +3617,61 @@ public static void Return(T obj) where T : class, IInvokable, new() { } } + public partial interface IRawResponseReader + { + bool IsSupported { get; } + + Response ReadRaw(ref Buffers.Reader reader, scoped ref WireProtocol.Field field); + } + + public partial interface IRawResponseWriter + { + void WriteRaw(ref Buffers.Writer writer) + where TBufferWriter : System.Buffers.IBufferWriter; + } + public partial interface IResponseCompletionSource { void Complete(); void Complete(Response value); } + public partial interface IResponseInvokable + { + System.Threading.Tasks.ValueTask InvokeAndCopy(Serializers.ICodecProvider codecProvider, Cloning.CopyContextPool copyContextPool, DeepCopier responseCopier); + } + public partial interface ITargetHolder { object? GetComponent(System.Type componentType); object? GetTarget(); } + public partial class PooledResponseCodec : ResponseCodec, Codecs.IFieldCodec>, Codecs.IFieldCodec where TResultCodec : class, Codecs.IFieldCodec + { + public PooledResponseCodec(TResultCodec codec) { } + + public PooledResponseCodec(System.Func codecFactory) { } + + public override object ReadRaw(ref Buffers.Reader reader, scoped ref WireProtocol.Field field) { throw null; } + + public Response ReadValue(ref Buffers.Reader reader, WireProtocol.Field field) { throw null; } + + public void WriteField(ref Buffers.Writer writer, uint fieldIdDelta, System.Type expectedType, Response value) + where TBufferWriter : System.Buffers.IBufferWriter { } + + public override void WriteRaw(ref Buffers.Writer writer, object value) { } + } + + public partial class PooledResponseCopier : Cloning.IDeepCopier>, Cloning.IDeepCopier where TResultCopier : class, Cloning.IDeepCopier + { + public PooledResponseCopier(TResultCopier copier) { } + + public PooledResponseCopier(System.Func copierFactory) { } + + public Response? DeepCopy(Response? input, Cloning.CopyContext context) { throw null; } + } + [SerializerTransparent] public abstract partial class Response : System.IDisposable { @@ -3711,7 +3770,13 @@ public static partial class ResponsePool { public static Response Get() { throw null; } + public static TResponse GetGenerated() + where TResponse : Response, new() { throw null; } + public static void Return(Response obj) { } + + public static void ReturnGenerated(TResponse response) + where TResponse : Response, new() { } } [UseActivator] @@ -3793,6 +3858,8 @@ public IValueSerializer GetValueSerializer() public Cloning.IDeepCopier? TryGetDeepCopier(System.Type fieldType) { throw null; } public Cloning.IDeepCopier? TryGetDeepCopier() { throw null; } + + public bool TryGetRawResponseReader(System.Type resultType, out Invocation.IRawResponseReader? reader) { throw null; } } public sealed partial class ConcreteTypeSerializer : Codecs.IFieldCodec, Codecs.IFieldCodec where TField : class where TBaseCodec : IBaseCodec diff --git a/test/Orleans.Core.Tests/Serialization/SelfWritingResponseMessageTests.cs b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseMessageTests.cs index 8ad7339f409..9e95bc04cc1 100644 --- a/test/Orleans.Core.Tests/Serialization/SelfWritingResponseMessageTests.cs +++ b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseMessageTests.cs @@ -1,10 +1,8 @@ using System.Buffers; using System.Buffers.Binary; using System.Collections.Generic; -using System.IO.Pipelines; using System.Net; using Microsoft.Extensions.DependencyInjection; -using Orleans.Networking.Shared; using Orleans.Configuration; using Orleans.Runtime; using Orleans.Runtime.Messaging; @@ -136,22 +134,10 @@ public void Write_NonNoneResponseType_DoesNotInvokeRawWriter(int responseTypeVal var holder = new Int32Response(42); var message = CreateMessage(holder); message.Result = responseType; - var pipe = new Pipe(new PipeOptions(pauseWriterThreshold: 0)); - - try - { - // Act - Assert.Throws(() => environment.Serializer.Write(pipe.Writer, message)); - - // Assert - Assert.Equal(0, holder.WriteCount); - Assert.Equal(responseType, message.Result); - } - finally - { - pipe.Writer.Complete(); - pipe.Reader.Complete(); - } + using var buffer = new ArcBufferWriter(); + Assert.Throws(() => environment.Serializer.Write(buffer, message)); + Assert.Equal(0, holder.WriteCount); + Assert.Equal(responseType, message.Result); } [Fact] @@ -161,24 +147,17 @@ public void Write_OversizedRawBody_EnforcesLimitAndSerializerCanBeReused() using var environment = new SerializationEnvironment( messagingOptions: new SiloMessagingOptions { MaxMessageBodySize = 32 }); var oversized = new StringResponse(new string('x', 128)); - var pipe = new Pipe(new PipeOptions(pauseWriterThreshold: 0)); - - try + using (var buffer = new ArcBufferWriter()) { // Act var exception = Assert.Throws( - () => environment.Serializer.Write(pipe.Writer, CreateMessage(oversized))); + () => environment.Serializer.Write(buffer, CreateMessage(oversized))); // Assert Assert.Contains("Invalid body size:", exception.Message); Assert.Contains(nameof(MessagingOptions.MaxMessageBodySize), exception.Message); Assert.Equal(1, oversized.WriteCount); } - finally - { - pipe.Writer.Complete(); - pipe.Reader.Complete(); - } AssertSuccessfulReuse(environment); } @@ -189,23 +168,16 @@ public void Write_RawWriterThrows_PropagatesExceptionAndSerializerCanBeReused() // Arrange using var environment = new SerializationEnvironment(); var holder = new ThrowingResponse(); - var pipe = new Pipe(new PipeOptions(pauseWriterThreshold: 0)); - - try + using (var buffer = new ArcBufferWriter()) { // Act var exception = Assert.Throws( - () => environment.Serializer.Write(pipe.Writer, CreateMessage(holder))); + () => environment.Serializer.Write(buffer, CreateMessage(holder))); // Assert Assert.Same(holder.Failure, exception); Assert.Equal(1, holder.WriteCount); } - finally - { - pipe.Writer.Complete(); - pipe.Reader.Complete(); - } AssertSuccessfulReuse(environment); } @@ -293,34 +265,31 @@ private static Message CreateMessage(Response body) }; } - private static (byte[] Bytes, int HeaderLength, int BodyLength) WriteFrame(MessageSerializer serializer, Message message) + internal static (byte[] Bytes, int HeaderLength, int BodyLength) WriteFrame(MessageSerializer serializer, Message message) { - var pipe = new Pipe(new PipeOptions(pauseWriterThreshold: 0)); - try - { - var (headerLength, bodyLength) = serializer.Write(pipe.Writer, message); - pipe.Writer.FlushAsync().GetAwaiter().GetResult(); - Assert.True(pipe.Reader.TryRead(out var result)); - var bytes = result.Buffer.ToArray(); - pipe.Reader.AdvanceTo(result.Buffer.End); - return (bytes, headerLength, bodyLength); - } - finally - { - pipe.Writer.Complete(); - pipe.Reader.Complete(); - } + using var buffer = new ArcBufferWriter(); + buffer.Write(new byte[Message.LENGTH_HEADER_SIZE]); + var (headerLength, bodyLength) = serializer.Write(buffer, message); + Span lengths = stackalloc byte[Message.LENGTH_HEADER_SIZE]; + BinaryPrimitives.WriteInt32LittleEndian(lengths, headerLength); + BinaryPrimitives.WriteInt32LittleEndian(lengths[sizeof(int)..], bodyLength); + buffer.WriteAt(0, lengths); + using var frame = buffer.ConsumeSlice(buffer.Length); + return (frame.ToArray(), headerLength, bodyLength); } - private static Message ReadFrame(MessageSerializer serializer, (byte[] Bytes, int HeaderLength, int BodyLength) frame) + internal static Message ReadFrame(MessageSerializer serializer, (byte[] Bytes, int HeaderLength, int BodyLength) frame) { - var input = new ReadOnlySequence(frame.Bytes); - var (requiredBytes, headerLength, bodyLength) = serializer.TryRead(ref input, out var message); - Assert.Equal(0, requiredBytes); - Assert.Equal(frame.HeaderLength, headerLength); - Assert.Equal(frame.BodyLength, bodyLength); - Assert.True(input.IsEmpty); - return Assert.IsType(message); + using var buffer = new ArcBufferWriter(); + buffer.Write(frame.Bytes.AsSpan(Message.LENGTH_HEADER_SIZE)); + using var shared = new MessageHandlerShared(null!, null!, () => serializer, null!, null!, null!); + using var request = shared.GetReceiveMessageHandler(); + request.Headers = buffer.ConsumeSlice(frame.HeaderLength); + request.Body = buffer.ConsumeSlice(frame.BodyLength); + serializer.ReadHeaders(request, out var message); + serializer.ReadBodyObject(message, request); + Assert.Equal(0, buffer.Length); + return message; } private static void AssertFrame( @@ -379,8 +348,6 @@ private static void AssertSuccessfulReuse(SerializationEnvironment environment) private sealed class SerializationEnvironment : IDisposable { - private readonly SharedMemoryPool _memoryPool = new(); - public SerializationEnvironment(Action? configure = null, MessagingOptions? messagingOptions = null) { var services = new ServiceCollection(); @@ -395,7 +362,7 @@ public SerializationEnvironment(Action? configure = null, M Services = services.BuildServiceProvider(); CodecProvider = Services.GetRequiredService(); Serializer = new MessageSerializer( - Services.GetRequiredService(), _memoryPool, messagingOptions ?? new SiloMessagingOptions()); + Services.GetRequiredService(), messagingOptions ?? new SiloMessagingOptions()); } public ServiceProvider Services { get; } @@ -406,7 +373,6 @@ public void Dispose() { Serializer.Dispose(); Services.Dispose(); - _memoryPool.Pool.Dispose(); } } diff --git a/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs index 802b5a7bea1..820de2c29dd 100644 --- a/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs +++ b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs @@ -2,7 +2,6 @@ using System.Collections.Concurrent; using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Metrics; -using System.IO.Pipelines; using System.Net; using System.Reflection; using Microsoft.Extensions.DependencyInjection; @@ -15,7 +14,6 @@ using Orleans.Configuration; using Orleans.GrainReferences; using Orleans.Metadata; -using Orleans.Networking.Shared; using Orleans.Placement.Repartitioning; using Orleans.Runtime; using Orleans.Runtime.Messaging; @@ -158,7 +156,7 @@ public async Task LegacyResponse_CopiesAtInvocationAndAfterFiltersAndReturnsOwne using var response = await fixture.Invoke(request, observer); Assert.Null(response.Exception); - Assert.NotSame(request.ReturnedResponse, response); + if (!filtered) Assert.NotSame(request.ReturnedResponse, response); Assert.Equal(filtered ? 2 : 1, counts.PayloadCopies); Assert.Equal(filtered ? 2 : 1, counts.ResponseCopies); Assert.Equal(filtered ? 3 : 2, counts.Rents); @@ -596,6 +594,7 @@ private sealed class CountingHolderCopier(Counts counts, ICodecProvider provider { if (input is null) return null; counts.ResponseCopies++; + if (counts.ReturnInput) return input; return CountedResponse.Rent(counts.Copy(Assert.IsType(input.Result)), counts, provider.GetCodec()); } } @@ -627,7 +626,6 @@ private sealed class SendFixture : IAsyncDisposable, IResponseCompletionSource private readonly Counts _counts; private readonly ObserverGrainId _observerId = ObserverGrainId.Create(ClientGrainId.Create("response-copy"), IdSpan.Create("observer")); private readonly TaskCompletionSource _completion = new(TaskCreationOptions.RunContinuationsAsynchronously); - private readonly SharedMemoryPool _memory = new(); private readonly MessageSerializer _serializer; private Message _request = null!; private Response? _sentResponse; @@ -698,7 +696,7 @@ public SendFixture(Counts counts, IIncomingGrainCallFilter? filter, IAddressable _manager = new InvokableObjectManager(Substitute.For(), observerRuntime, copier, trace, _services.GetRequiredService>(), mapping, NullLogger.Instance); Assert.True(_manager.TryRegister(_observer, _observerId)); - _serializer = new MessageSerializer(_services.GetRequiredService(), _memory, options.Value); + _serializer = new MessageSerializer(_services.GetRequiredService(), options.Value); } public async Task Invoke(IInvokable request, bool observer) @@ -749,7 +747,7 @@ public async Task Execute(IInvokable request, bool observer, } } - public async Task AssertFrameRoundTrip(Response response) + public Task AssertFrameRoundTrip(Response response) { var message = new Message { @@ -759,31 +757,14 @@ public async Task AssertFrameRoundTrip(Response response) TargetGrain = _request.SendingGrain, BodyObject = response, }; - var pipe = new Pipe(new PipeOptions(pauseWriterThreshold: 0)); - try - { - var written = _serializer.Write(pipe.Writer, message); - await pipe.Writer.FlushAsync(TestContext.Current.CancellationToken); - Assert.True(pipe.Reader.TryRead(out var read)); - var bytes = read.Buffer.ToArray(); - pipe.Reader.AdvanceTo(read.Buffer.End); - var input = new ReadOnlySequence(bytes); - var (required, headers, body) = _serializer.TryRead(ref input, out var received); - Assert.Equal(0, required); - Assert.Equal(written.HeaderLength, headers); - Assert.Equal(written.BodyLength, body); - Assert.True(input.IsEmpty); - Assert.NotNull(received); - Assert.Equal(message.Direction, received.Direction); - Assert.Equal(message.Id, received.Id); - using var result = Assert.IsAssignableFrom(received.BodyObject); - Assert.Equal(Assert.IsType(response.Result).Values, Assert.IsType(result.Result).Values); - } - finally - { - await pipe.Writer.CompleteAsync(); - await pipe.Reader.CompleteAsync(); - } + var frame = SelfWritingResponseMessageTests.WriteFrame(_serializer, message); + using var received = SelfWritingResponseMessageTests.ReadFrame(_serializer, frame); + Assert.Equal(message.Direction, received.Direction); + Assert.Equal(message.Id, received.Id); + using var result = Assert.IsAssignableFrom(received.BodyObject); + Assert.Equal(Assert.IsType(response.Result).Values, Assert.IsType(result.Result).Values); + received.BodyObject = null; + return Task.CompletedTask; } void IResponseCompletionSource.Complete(Response value) @@ -811,7 +792,6 @@ public async ValueTask DisposeAsync() _sentResponse?.Dispose(); ((IDisposable)_hosted).Dispose(); _serializer.Dispose(); - _memory.Pool.Dispose(); await _services.DisposeAsync(); GC.KeepAlive(_observer); } diff --git a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs index a5d8de7cdf7..f4858639f0e 100644 --- a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs +++ b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs @@ -188,6 +188,50 @@ public void CompoundResponseAliasesResolveAndRoundTrip() Assert.Equal(89, nestedResult[0].Value); } + [Fact] + public void GeneratedResponseFactoriesPreserveCanonicalClosedImplementations() + { + var provider = _services.GetRequiredService(); + Assert.IsType>(provider.GetCodec>()); + Assert.IsType>>(provider.GetDeepCopier>()); + } + + [Fact] + public void InferredResponseFactoriesInspectDefinitionsWithoutMaterializingLegacyImplementations() + { + var codecDefinition = new DefinitionOnlyType(typeof(PooledResponseCodec<>)); + var copierDefinition = new DefinitionOnlyType(typeof(PooledResponseCopier<>)); + var options = new TypeManifestOptions(); + options.AddSerializer(codecDefinition, typeof(Response<>)); + options.AddCopier(copierDefinition, typeof(Response<>)); + options.AddDefaultSerializer, PooledResponseCodec, PooledResponseCopier>>( + static _ => new PooledResponseCodec(new Int32Codec()), + static _ => new PooledResponseCopier>(new ShallowCopier())); + using var services = new ServiceCollection().BuildServiceProvider(); + var provider = new CodecProvider(services, Microsoft.Extensions.Options.Options.Create(options)); + + Assert.IsType>(provider.GetCodec>()); + Assert.IsType>>(provider.GetDeepCopier>()); + Assert.Equal(0, codecDefinition.MaterializationCalls); + Assert.Equal(0, copierDefinition.MaterializationCalls); + } + + private sealed class DefinitionOnlyType(Type definition) : System.Reflection.TypeDelegator(definition) + { + public int MaterializationCalls { get; private set; } + public override bool IsGenericType => typeImpl.IsGenericType; + public override bool IsGenericTypeDefinition => typeImpl.IsGenericTypeDefinition; + public override bool IsConstructedGenericType => typeImpl.IsConstructedGenericType; + public override Type GetGenericTypeDefinition() => typeImpl.GetGenericTypeDefinition(); + public override Type[] GetGenericArguments() => typeImpl.GetGenericArguments(); + + public override Type MakeGenericType(params Type[] typeArguments) + { + MaterializationCalls++; + throw new InvalidOperationException("The inferred factory supplies its closed executable implementation."); + } + } + [Fact] public void AutomaticResponseFactoriesPreserveCustomJitPayloadCopier() { From 74fbad9509d35927ddd0cd8fc78e4a3676f74107 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Tue, 6 Oct 2026 12:23:15 -0700 Subject: [PATCH 34/54] fix(rpc): retain superseded filter response leases --- .../docs/implementation/serialization.md | 2 +- src/Orleans.Core/Core/GrainMethodInvoker.cs | 85 +++++++------------ .../SelfWritingResponseOwnershipTests.cs | 72 ++++++++++++++++ 3 files changed, 102 insertions(+), 57 deletions(-) diff --git a/docs/site/src/content/docs/implementation/serialization.md b/docs/site/src/content/docs/implementation/serialization.md index 8296c77fe48..450fa4d44dd 100644 --- a/docs/site/src/content/docs/implementation/serialization.md +++ b/docs/site/src/content/docs/implementation/serialization.md @@ -135,7 +135,7 @@ Arguments and result values use normal Orleans.Serialization codecs and copiers. For supported non-generic methods using the built-in task and value-task request bases, generated invokables also implement . The runtime selects this contract in the ordinary, incoming-filter, and observer paths. The invokable binds the selected serialization dependencies and rents a concrete, non-generic response holder after copying a mutable result. Immutable results retain their existing copy semantics. Isolation completes before incoming filters resume, and this path creates one pooled envelope for the successful result. -Incoming filters receive an isolated result and can transform its envelope or nested payload references. After the filter chain completes, the runtime copies the selected result for delivery, preserving isolation for both local callers and deferred message serialization. Calls with no incoming filters transfer their invocation-time copy directly to the messaging pipeline. Expired and one-way requests release their owned response without an outgoing copy. +Incoming filters receive an isolated result and can transform its envelope or nested payload references. The invocation context retains each superseded response until completion, allowing filters to restore an earlier selection and releasing every unselected wrapper exactly once. After the filter chain completes, the runtime copies the selected result for delivery, preserving isolation for both local callers and deferred message serialization. Calls with no incoming filters transfer their invocation-time copy directly to the messaging pipeline. Expired and one-way requests release their owned response without an outgoing copy. Generated holders implement . The message serializer selects their direct writer before runtime-type codec lookup. Primitive holders call the existing static primitive codecs; reference holders use their bound concrete result codec and the message's serialization session. The wire representation retains the result-type header, field zero, end marker, null behavior, cycles, and shared references. Returning a holder to its pool clears both its result and its provider-owned factory binding. diff --git a/src/Orleans.Core/Core/GrainMethodInvoker.cs b/src/Orleans.Core/Core/GrainMethodInvoker.cs index 61e2b0a072a..333ab5c95e4 100644 --- a/src/Orleans.Core/Core/GrainMethodInvoker.cs +++ b/src/Orleans.Core/Core/GrainMethodInvoker.cs @@ -24,7 +24,7 @@ internal sealed class GrainMethodInvoker : IIncomingGrainCallContext, IDisposabl private readonly IGrainContext grainContext; private readonly ICodecProvider codecProvider; private readonly CopyContextPool copyContexts; - private Response? ownedResponse; + private Response? response; private List? otherOwnedResponses; private int stage; @@ -77,78 +77,51 @@ public object? Result set => Response = Response.FromResult(value); } - public Response? Response { get; set; } - - internal Response TakeResponse() + public Response? Response { - var response = Response!; - if (ReferenceEquals(response, ownedResponse)) + get => response; + set { - ownedResponse = null; - } + if (ReferenceEquals(response, value)) return; + if (response is { } previous) + { + (otherOwnedResponses ??= []).Add(previous); + } - if (otherOwnedResponses is { } others) - { - for (var i = others.Count - 1; i >= 0; i--) + if (value is not null && otherOwnedResponses is { } others) { - if (ReferenceEquals(response, others[i])) + for (var i = others.Count - 1; i >= 0; i--) { - others.RemoveAt(i); + if (ReferenceEquals(value, others[i])) others.RemoveAt(i); } } + + response = value; } + } - Response = null; - return response; + internal Response TakeResponse() + { + var result = response!; + response = null; + return result; } public void Dispose() { - var response = ownedResponse; - ownedResponse = null; - var current = Response; - Response = null; + var current = response; + response = null; + var others = otherOwnedResponses; + otherOwnedResponses = null; try { - if (current is not null && !ReferenceEquals(current, response) - && (otherOwnedResponses is null || !otherOwnedResponses.Exists(entry => ReferenceEquals(current, entry)))) - { - current.Dispose(); - } + current?.Dispose(); } finally { - try - { - response?.Dispose(); - } - finally - { - if (otherOwnedResponses is { } others) - { - otherOwnedResponses = null; - foreach (var entry in others) entry.Dispose(); - } - } - } - } - - private void SetOwnedResponse(Response response) - { - if (ownedResponse is { } previous && !ReferenceEquals(previous, response)) - { - (otherOwnedResponses ??= []).Add(previous); + if (others is not null) + foreach (var entry in others) entry.Dispose(); } - - if (otherOwnedResponses is { } others) - { - for (var i = others.Count - 1; i >= 0; i--) - { - if (ReferenceEquals(response, others[i])) others.RemoveAt(i); - } - } - - ownedResponse = Response = response; } public GrainId? SourceId => message.SendingGrain is { IsDefault: false } source ? source : null; @@ -215,14 +188,14 @@ public async Task Invoke() // Propagate exceptions to other filters. if (response.Exception is { } exception) { - SetOwnedResponse(response); + Response = response; ExceptionDispatchInfo.Capture(exception).Throw(); } if (request is not IResponseInvokable) response = ResponseCopyBoundary.CopyAndDispose(response, this.responseCopier); - SetOwnedResponse(response); + Response = response; return; } diff --git a/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs index 820de2c29dd..9094e7805f7 100644 --- a/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs +++ b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs @@ -245,6 +245,78 @@ public async Task FilterSelectedResponse_IsCopiedAndReleasesSupersededRoot(bool Assert.Equal(counts.Rents, counts.Returns); } + [Theory] + [InlineData(false, false, false, false)] + [InlineData(false, false, false, true)] + [InlineData(false, false, true, false)] + [InlineData(false, false, true, true)] + [InlineData(false, true, false, false)] + [InlineData(false, true, false, true)] + [InlineData(false, true, true, false)] + [InlineData(false, true, true, true)] + [InlineData(true, false, false, false)] + [InlineData(true, false, false, true)] + [InlineData(true, false, true, false)] + [InlineData(true, false, true, true)] + [InlineData(true, true, false, false)] + [InlineData(true, true, false, true)] + [InlineData(true, true, true, false)] + [InlineData(true, true, true, true)] + public async Task FilterReplacesMultipleResponses_ReturnsEveryLease(bool observer, bool invokeRoot, bool restoreFirst, bool throwAfterSelection) + { + var counts = new Counts(); + var failure = new InvalidOperationException("after selecting multiple responses"); + var filter = new CallbackFilter(async context => + { + if (invokeRoot) await context.Invoke(); + var codec = Assert.IsAssignableFrom(context.Request).Codec; + var first = CountedResponse.Rent(new Payload { Values = [47] }, counts, codec); + var second = CountedResponse.Rent(new Payload { Values = [59] }, counts, codec); + context.Response = first; + context.Response = first; + context.Response = second; + context.Response = null; + context.Response = restoreFirst ? first : second; + if (throwAfterSelection) throw failure; + }); + await using var fixture = new SendFixture(counts, filter); + var request = new DirectRequest(new Payload { Values = [17] }, counts); + + using var response = await fixture.Invoke(request, observer); + + Assert.Equal((invokeRoot ? 1 : 0) + (throwAfterSelection ? 0 : 1), counts.PayloadCopies); + Assert.Equal(throwAfterSelection ? 0 : 1, counts.ResponseCopies); + Assert.Equal((invokeRoot ? 1 : 0) + 2 + (throwAfterSelection ? 0 : 1), counts.Rents); + Assert.Equal(counts.Rents - (throwAfterSelection ? 0 : 1), counts.Returns); + if (throwAfterSelection) + { + Assert.Same(failure, response.Exception); + } + else + { + Assert.Null(response.Exception); + Assert.Equal(new[] { restoreFirst ? 47 : 59 }, Assert.IsType(response.Result).Values); + await fixture.AssertFrameRoundTrip(response); + response.Dispose(); + } + Assert.Equal(counts.Rents, counts.Returns); + + var rented = new List(); + try + { + for (var i = 0; i < counts.Rents; i++) + { + var holder = ResponsePool.GetGenerated(); + Assert.DoesNotContain(rented, existing => ReferenceEquals(existing, holder)); + rented.Add(holder); + } + } + finally + { + foreach (var holder in rented) ResponsePool.ReturnGenerated(holder); + } + } + [Theory] [InlineData(false)] [InlineData(true)] From b6a66d32c0f6e7f560c2fcb515761bfc444ece1f Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Tue, 6 Oct 2026 12:30:20 -0700 Subject: [PATCH 35/54] fix(nativeaot): preserve rooted serializer materialization --- .../Serializers/CodecProvider.cs | 59 ++++++++----------- .../ManifestContractTests.cs | 14 +++++ .../RpcResponseTests.cs | 27 +++++++++ 3 files changed, 66 insertions(+), 34 deletions(-) diff --git a/src/Orleans.Serialization/Serializers/CodecProvider.cs b/src/Orleans.Serialization/Serializers/CodecProvider.cs index c2d4f002a2b..6d8f50a8388 100644 --- a/src/Orleans.Serialization/Serializers/CodecProvider.cs +++ b/src/Orleans.Serialization/Serializers/CodecProvider.cs @@ -241,8 +241,12 @@ void AddFromMetadata( var target = legacyDescription is { } shape ? shape.Type : genericArgument; + var surrogateDescription = genericType == typeof(IConverter<,>) + ? SerializationType.FromType(@interface.GetGenericArguments()[1], type.GetGenericArguments()) + : null; candidates.Add((target, type, - new SerializationContract(genericType, target, null, TargetDescription: legacyDescription), legacyOrders[i])); + new SerializationContract(genericType, target, null, + SurrogateDescription: surrogateDescription, TargetDescription: legacyDescription), legacyOrders[i])); } } } @@ -1159,43 +1163,17 @@ private void ThrowResolutionFailure(Exception exception) return codecType != null ? (IFieldCodec)GetServiceOrCreateInstance(codecType, constructorArguments) : null; } -#if NET5_0_OR_GREATER - [UnconditionalSuppressMessage("Trimming", "IL2070", - Justification = "Legacy converter registrations preserve implementation interfaces through AddConverter(Type). The selected implementation boundary erases that annotation; explicit contracts use their stored surrogate descriptions instead.")] - [UnconditionalSuppressMessage("Trimming", "IL2075", - Justification = "Legacy converter registrations preserve implementation interfaces through AddConverter(Type). Materialization erases the registration annotation; explicit contracts use their stored surrogate descriptions instead.")] -#endif private bool TryGetSurrogateCodec(Type fieldType, Type searchType, [NotNullWhen(true)] out Type? surrogateCodecType, [NotNullWhen(true)] out object[]? constructorArguments) { if (TrySelectImplementation(typeof(IConverter<,>), fieldType, searchType, out var converterType, out var registration)) { - Type? surrogate = null; - if (registration.RegistrationOrder is not null) - { - var arguments = converterType.IsGenericType ? converterType.GetGenericArguments() : Array.Empty(); - surrogate = registration.SurrogateDescription is { } description - ? ResolveSerializationType(description, arguments) - : registration.SurrogateType!; - if (surrogate.IsGenericTypeDefinition) - { - surrogate = ConstructGenericImplementation(surrogate, arguments); - } - } - else - { - foreach (var @interface in converterType.GetInterfaces()) - { - if (@interface.IsConstructedGenericType && @interface.GetGenericTypeDefinition() == typeof(IConverter<,>) - && @interface.GenericTypeArguments[0] == fieldType) - { - surrogate = @interface.GenericTypeArguments[1]; - } - } - } - - if (surrogate is null) + var arguments = converterType.IsGenericType ? converterType.GetGenericArguments() : Array.Empty(); + var surrogate = registration.SurrogateDescription is { } description + ? ResolveSerializationTypeCore(description, arguments, allowArrayShapes: registration.RegistrationOrder is null) + : registration.SurrogateType!; + if (surrogate.IsGenericTypeDefinition) { - throw new InvalidOperationException($"A registered type converter {converterType} does not implement {typeof(IConverter<,>)}"); + surrogate = ConstructGenericImplementation(surrogate, arguments); } constructorArguments = new object[] { GetServiceOrCreateInstance(converterType) }; @@ -1354,6 +1332,9 @@ static bool BindParameter(int index, Type target, Type?[] arguments) } private Type ResolveSerializationType(SerializationType description, Type[] parameters) + => ResolveSerializationTypeCore(description, parameters, allowArrayShapes: false); + + private Type ResolveSerializationTypeCore(SerializationType description, Type[] parameters, bool allowArrayShapes) { if (description.ParameterIndex >= 0) { @@ -1367,6 +1348,16 @@ private Type ResolveSerializationType(SerializationType description, Type[] para if (description.ArrayRank > 0) { + if (allowArrayShapes +#if NET7_0_OR_GREATER + && RuntimeFeature.IsDynamicCodeSupported +#endif + ) + { + var element = ResolveSerializationTypeCore(description.Arguments[0], parameters, allowArrayShapes); + return description.ArrayRank == 1 ? element.MakeArrayType() : element.MakeArrayType(description.ArrayRank); + } + throw new NotSupportedException( "Supply a source-known closed array type using SerializationType.Create(typeof(ClosedArray)) or an explicit closed converter registration when resolving executable serialization metadata. Array descriptions are structural matching patterns."); } @@ -1380,7 +1371,7 @@ private Type ResolveSerializationType(SerializationType description, Type[] para var arguments = new Type[description.Arguments.Length]; for (var i = 0; i < arguments.Length; i++) { - arguments[i] = ResolveSerializationType(description.Arguments[i], parameters); + arguments[i] = ResolveSerializationTypeCore(description.Arguments[i], parameters, allowArrayShapes); } return ConstructGenericImplementation(type, arguments); diff --git a/test/Orleans.Serialization.UnitTests/ManifestContractTests.cs b/test/Orleans.Serialization.UnitTests/ManifestContractTests.cs index 206883fcfe1..9a68eea954a 100644 --- a/test/Orleans.Serialization.UnitTests/ManifestContractTests.cs +++ b/test/Orleans.Serialization.UnitTests/ManifestContractTests.cs @@ -430,6 +430,20 @@ public void ClosedConverterRegistrationOverridesAnUnresolvedArraySurrogateRecipe Assert.IsType>(Assert.Single(Assert.IsType(arguments[3]))); } + [Fact] + public void LegacyOpenConverterDiscoveryPreservesItsParameterizedArraySurrogate() + { + var options = new TypeManifestOptions(); + options.AddConverter(typeof(GenericConverter<,>)); + using var services = new ServiceCollection().BuildServiceProvider(); + var provider = new CodecProvider(services, Options.Create(options)); + object?[] arguments = [typeof(GenericTarget), typeof(GenericTarget<,>), null, null]; + + Assert.Equal(true, typeof(CodecProvider).GetMethod("TryGetSurrogateCodec", BindingFlags.Instance | BindingFlags.NonPublic)!.Invoke(provider, arguments)); + Assert.Equal(typeof(GenericSurrogate<(int, string)[]>), Assert.IsAssignableFrom(arguments[2]).GetGenericArguments()[1]); + Assert.IsType>(Assert.Single(Assert.IsType(arguments[3]))); + } + [Fact] public void LegacyClosedConverterDiscoveryPreservesItsArraySurrogate() { diff --git a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs index f4858639f0e..ce4feed446e 100644 --- a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs +++ b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs @@ -146,6 +146,33 @@ private sealed class EmptyContext : SerializerContext protected override void ConfigureInner(TypeManifestOptions options) { } } + [Fact] + public void MultidimensionalArrayTransportAndCopyPreserveConcreteTypeCyclesAndAliases() + { + var shared = new List { 47, 59 }; + var original = new object[1, 3]; + original[0, 0] = original; + original[0, 1] = shared; + original[0, 2] = shared; + + var copy = _services.GetRequiredService().Copy(original); + var serializer = _services.GetRequiredService(); + var result = Assert.IsType(serializer.Deserialize(serializer.SerializeToArray(original))); + + Assert.NotSame(original, copy); + Assert.Same(copy, copy[0, 0]); + Assert.NotSame(shared, copy[0, 1]); + Assert.Same(copy[0, 1], copy[0, 2]); + Assert.Equal(new[] { 47, 59 }, Assert.IsType>(copy[0, 1])); + Assert.NotSame(original, result); + Assert.Same(result, result[0, 0]); + Assert.Same(result[0, 1], result[0, 2]); + Assert.Equal(new[] { 47, 59 }, Assert.IsType>(result[0, 1])); + shared.Clear(); + Assert.Equal(new[] { 47, 59 }, Assert.IsType>(copy[0, 1])); + Assert.Equal(new[] { 47, 59 }, Assert.IsType>(result[0, 1])); + } + [Fact] public void CompoundAliasTraversalPreservesPrefixesAndAddClearsThem() { From 65709ca7f196fb9e10c5eefcd5a2daccf8faf714 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Tue, 6 Oct 2026 13:11:20 -0700 Subject: [PATCH 36/54] fix(codegen): integrate runtime-independent RPC registrations --- .../docs/implementation/serialization.md | 2 +- .../RpcResponseGenerator.cs | 4 - .../SerializerFactoryGenerator.cs | 24 +- .../OrleansSourceGeneratorTests.cs | 54 +- ...eGeneratorTests.TestBasicGrain.verified.cs | 497 ------ ...ateMethodSerializersAnnotation.verified.cs | 399 ----- ...stGrainComplexGrain.DotNet10_0.verified.cs | 2 + ...estGrainComplexGrain.DotNet8_0.verified.cs | 2 + ...torTests.TestGrainComplexGrain.verified.cs | 699 -------- ...AnnotatedWithInvokableBaseType.verified.cs | 502 ------ ...odAnnotatedWithResponseTimeout.verified.cs | 399 ----- ...TestGrainWithDifferentKeyTypes.verified.cs | 1553 ----------------- ...estGrainWithMultipleInterfaces.verified.cs | 557 ------ 13 files changed, 65 insertions(+), 4629 deletions(-) delete mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.verified.cs delete mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.verified.cs delete mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.verified.cs delete mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.verified.cs delete mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.verified.cs delete mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.verified.cs delete mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.verified.cs diff --git a/docs/site/src/content/docs/implementation/serialization.md b/docs/site/src/content/docs/implementation/serialization.md index 450fa4d44dd..a9f4d5ce685 100644 --- a/docs/site/src/content/docs/implementation/serialization.md +++ b/docs/site/src/content/docs/implementation/serialization.md @@ -141,7 +141,7 @@ Generated holders implement using the result type from the wire header. Generated registrations reconstruct a bound holder directly. Compatibility paths retain ordinary response codecs for custom response/payload implementations, custom invokable bases, and unresolved generic contracts. Generated direct factories activate only when the selected result and response codecs/copiers match the canonical implementations, so explicit application behavior retains precedence. -For concrete `Task` and `ValueTask` method results, generated metadata supplies a closed response codec and copier graph in JIT and NativeAOT execution. The graph uses the concrete result implementations in and . Recursive result dependencies resolve with a construction caller after the response implementation has been allocated. Reference payload codecs and copiers preserve payload cycles and shared references, and the pooled response envelope retains the existing field and raw-message encoding. +For concrete `Task` and `ValueTask` method results, the generator emits identical invocation code and closed response registrations for JIT and NativeAOT execution. Provider registration precedence selects the services in both execution modes. The graph uses the concrete result implementations in and . Recursive result dependencies resolve with a construction caller after the response implementation has been allocated. Reference payload codecs and copiers preserve payload cycles and shared references, and the pooled response envelope retains the existing field and raw-message encoding. The graph also registers polymorphic codec and copier dispatch for the non-generic boundary used by the runtime client. That dispatch selects the closed implementation for the actual response type and preserves the identity of immutable completed and exception responses. The native smoke uses with `Response`, matching the runtime's response-copy boundary. diff --git a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs index 1f7deb40d53..2e70fc575c2 100644 --- a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs +++ b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs @@ -224,14 +224,10 @@ internal static ImmutableArray Generate( if (metadataModelRoots.Count > 0) { - source.AppendLine("if (!options.RequireExplicitTypeRegistration)"); - source.AppendLine("{"); foreach (var metadataRoot in metadataModelRoots) { source.AppendLine(metadataRoot.ConfigurationStatements); } - - source.AppendLine("}"); } if (hasResponseRoots) { diff --git a/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs b/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs index 80ef3cb9a69..c65204832db 100644 --- a/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs +++ b/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs @@ -530,12 +530,22 @@ internal static bool TryCreate( if (hasBaseCodec) { result.Append("options.").Append(addService).Append(">(static provider => ").Append(Resolve(registration.Codec)).AppendLine(");"); + .Append(typeName).Append('>'); + if (useDefaultFactories) result.Append(", ").Append(registration.Codec); + result.Append(">(static provider => ").Append(Resolve(registration.Codec)); + if (useDefaultFactories) + result.Append(", dependencies: ").Append(DefaultDependencyServices(registration.Dependencies, codec: true)); + result.AppendLine(");"); } if (hasBaseCopier) { result.Append("options.").Append(addService).Append(">(static provider => ").Append(Resolve(registration.Copier)).AppendLine(");"); + .Append(typeName).Append('>'); + if (useDefaultFactories) result.Append(", ").Append(registration.Copier); + result.Append(">(static provider => ").Append(Resolve(registration.Copier)); + if (useDefaultFactories) + result.Append(", dependencies: ").Append(DefaultDependencyServices(registration.Dependencies, codec: false)); + result.AppendLine(");"); } foreach (var array in registration.CanonicalArrays) @@ -905,16 +915,6 @@ private static bool TryGetConstructionCollectionServices(IGeneratorServices serv return true; } - private static void ConstructGeneratedModel(Registration registration, IGeneratorServices services) - { - var codecDeclaration = new SerializerGenerator(services).Generate(registration.Model!); - var copierDeclaration = new CopierGenerator(services).GenerateCopier(registration.Model!, new()); - registration.CodecConstruction = ConstructGenerated(registration.Codec, codecDeclaration); - registration.CopierConstruction = copierDeclaration is null - ? $"new {registration.Copier}()" - : ConstructGenerated(registration.Copier, copierDeclaration); - } - private static string ConstructReferenced(string name, INamedTypeSymbol implementation, bool preferCompleteConstructor = false) { var constructor = GetReferencedConstructor(implementation, preferCompleteConstructor); diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index 2a1c45eb01f..34d8d30d02c 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -2241,6 +2241,49 @@ public sealed record PrimaryCtorRecord( Assert.Equal(1, CountOccurrences(serializerText, "if (id == 2U)")); } + [Fact] + public async Task RpcResponseFactoriesEmitIdenticalSourcesForManagedAndNativePublishing() + { + var compilation = await CreateCompilation(""" + using Orleans; + using System.Collections.Generic; + using System.Threading.Tasks; + namespace TestProject; + public interface IResponses : IGrainWithIntegerKey + { + Task Reference(); + ValueTask Integer(); + Task> Collection(); + Task Done(); + } + [GenerateSerializer] + public sealed class Payload + { + [Id(0)] public int Value { get; set; } + [Id(1)] public Payload Next { get; set; } + } + [GenerateSerializerContext] + public partial class Context : Orleans.Serialization.SerializerContext { } + """); + var managed = RunSourceGenerator(compilation, new Dictionary { ["build_property.publishaot"] = "false" }); + var native = RunSourceGenerator(compilation, new Dictionary { ["build_property.publishaot"] = "true" }); + + Assert.Empty(managed.Diagnostics); + Assert.Empty(native.Diagnostics); + Assert.Equal( + managed.GeneratedSources.OrderBy(static source => source.HintName, StringComparer.Ordinal) + .Select(static source => (source.HintName, Source: source.SourceText.ToString())), + native.GeneratedSources.OrderBy(static source => source.HintName, StringComparer.Ordinal) + .Select(static source => (source.HintName, Source: source.SourceText.ToString()))); + var source = ConcatenateGeneratedSources(managed); + Assert.Contains("IResponseInvokable", source); + Assert.Contains("IRawResponseWriter", source); + Assert.Contains("AddRawResponseReader", source); + Assert.DoesNotContain("RuntimeFeature", source); + Assert.DoesNotContain("UseGeneratedSerializerContexts", source); + Assert.DoesNotContain("RequireExplicitTypeRegistration", source); + } + [Fact] public async Task RpcResponseFactoriesGenerateConcreteClosedGraph() { @@ -2257,7 +2300,7 @@ public interface IResponses : IGrainWithIntegerKey Task> Pair(); } [GenerateSerializer, Alias("rpc.payload")] - public sealed class Payload + public class Payload { [Id(0)] public int Value { get; set; } [Id(1)] public Payload Next { get; set; } @@ -2271,6 +2314,8 @@ public sealed class Payload Assert.Contains("new global::Orleans.Serialization.Invocation.PooledResponseCopier>", source); Assert.Contains("PooledResponseCodec", source); Assert.Contains("new global::OrleansCodeGen.TestProject.Codec_Payload(provider)", source); + Assert.Contains("AddDefaultSerializerService, global::OrleansCodeGen.TestProject.Codec_Payload>", source); + Assert.Contains("AddDefaultSerializerService, global::OrleansCodeGen.TestProject.Copier_Payload>", source); Assert.Contains("new global::Orleans.Serialization.Codecs.KeyValuePairCodec", source); Assert.Contains("new global::Orleans.Serialization.Codecs.KeyValuePairCopier", source); Assert.Contains("caller => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(caller, provider)", source); @@ -2284,7 +2329,7 @@ public sealed class Payload Assert.DoesNotContain("RequireExplicitTypeRegistration", source); Assert.DoesNotContain("MakeGenericType", source); Assert.DoesNotContain("WellKnownTypeAliases", source); - Assert.Contains("WellKnownTypeAliases.Add(\"rpc.payload\"", ConcatenateGeneratedSources(result)); + Assert.Contains("WellKnownTypeAliases.TryGetValue(\"rpc.payload\"", ConcatenateGeneratedSources(result)); Assert.Contains("options.AddDefaultSerializer", source); Assert.Contains("AbstractTypeSerializer", source); Assert.Contains("global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context)", source); @@ -2745,10 +2790,7 @@ public static bool Run(bool includeActivator) Assert.True(emit.Success, string.Join(Environment.NewLine, emit.Diagnostics)); var assembly = System.Reflection.Assembly.Load(image.ToArray()); var run = assembly.GetType("RootProof")!.GetMethod("Run")!; - var rejected = Assert.Throws(() => run.Invoke(null, [false])); - var error = Assert.IsType(rejected.InnerException); - Assert.Contains("Dependency injection cannot resolve", error.Message); - Assert.Contains("graph is unpublished", error.Message); + Assert.Equal(true, run.Invoke(null, [false])); Assert.Equal(true, run.Invoke(null, [true])); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.verified.cs deleted file mode 100644 index 4848ba692dc..00000000000 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.verified.cs +++ /dev/null @@ -1,497 +0,0 @@ -[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] -#pragma warning disable -[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] -[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] -[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] -[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] -[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] -[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] -namespace OrleansCodeGen.TestProject -{ - using global::Orleans.Serialization.Codecs; - using global::Orleans.Serialization.GeneratedCodeHelpers; - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IBasicGrain), "6B0E24A1")] - public sealed class Invokable_IBasicGrain_GrainReference_6B0E24A1 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable - { - public string arg0; - global::TestProject.IBasicGrain _target; - private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IBasicGrain).GetMethod("SayHello", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new[] { typeof(string) }, null); - public override int GetArgumentCount() => 1; - public override string GetMethodName() => "SayHello"; - public override string GetInterfaceName() => "TestProject.IBasicGrain"; - public override string GetActivityName() => "IBasicGrain/SayHello"; - public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IBasicGrain); - public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; - public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = (global::TestProject.IBasicGrain)holder.GetTarget(); - public override object GetTarget() => _target; - public override void Dispose() - { - arg0 = default; - _target = default; - } - - public override object GetArgument(int index) - { - switch (index) - { - case 0: - return arg0; - default: - return OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); - } - } - - public override void SetArgument(int index, object value) - { - switch (index) - { - case 0: - arg0 = (string)value; - return; - default: - OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); - return; - } - } - - protected override global::System.Threading.Tasks.Task InvokeInner() => _target.SayHello(arg0); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) - { - try - { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); - if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); - string value = await InvokeInner(); - return factory.RentCopied(value, contexts); - } - catch (global::System.Exception exception) - { - return global::Orleans.Serialization.Invocation.Response.FromException(exception); - } - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class Proxy_IBasicGrain : global::Orleans.Runtime.GrainReference, global::TestProject.IBasicGrain - { - public Proxy_IBasicGrain(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) - { - } - - global::System.Threading.Tasks.Task global::TestProject.IBasicGrain.SayHello(string arg0) - { - var request = new OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1(); - request.arg0 = arg0; - return base.InvokeAsync(request).AsTask(); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Codec_Invokable_IBasicGrain_GrainReference_6B0E24A1 : global::Orleans.Serialization.Codecs.IFieldCodec - { - private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1); - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1 instance) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.arg0); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1 instance) - { - uint id = 0U; - global::Orleans.Serialization.WireProtocol.Field header = default; - while (true) - { - reader.ReadFieldHeader(ref header); - if (header.IsEndBaseOrEndObject) - break; - id += header.FieldIdDelta; - if (id == 0U) - { - instance.arg0 = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); - reader.ReadFieldHeader(ref header); - } - - reader.ConsumeEndBaseOrEndObject(ref header); - break; - } - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1 @value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (@value is null) - { - ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); - return; - } - - ReferenceCodec.MarkValueField(writer.Session); - writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); - Serialize(ref writer, @value); - writer.WriteEndObject(); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) - { - if (field.IsReference) - return ReferenceCodec.ReadReference(ref reader, field); - field.EnsureWireTypeTagDelimited(); - var result = new OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1(); - ReferenceCodec.MarkValueField(reader.Session); - Deserialize(ref reader, result); - return result; - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Copier_Invokable_IBasicGrain_GrainReference_6B0E24A1 : global::Orleans.Serialization.Cloning.IDeepCopier - { - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1 DeepCopy(OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1 original, global::Orleans.Serialization.Cloning.CopyContext context) - { - if (original is null) - return null; - var result = new OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1(); - result.arg0 = original.arg0; - return result; - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Codec_BasicGrain : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec - { - private readonly global::System.Type _codecFieldType = typeof(global::TestProject.BasicGrain); - private readonly global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer; - public Codec_BasicGrain(global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer) - { - this._baseTypeSerializer = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeSerializer); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.BasicGrain instance) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - _baseTypeSerializer.Serialize(ref writer, instance); - writer.WriteEndBase(); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.BasicGrain instance) - { - _baseTypeSerializer.Deserialize(ref reader, instance); - reader.ConsumeEndBaseOrEndObject(); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.BasicGrain @value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (@value is null || @value.GetType() == typeof(global::TestProject.BasicGrain)) - { - if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) - return; - writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); - Serialize(ref writer, @value); - writer.WriteEndObject(); - } - else - writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public global::TestProject.BasicGrain ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) - { - if (field.IsReference) - return ReferenceCodec.ReadReference(ref reader, field); - field.EnsureWireTypeTagDelimited(); - global::System.Type valueType = field.FieldType; - if (valueType is null || valueType == _codecFieldType) - { - var result = new global::TestProject.BasicGrain(); - ReferenceCodec.RecordObject(reader.Session, result); - Deserialize(ref reader, result); - return result; - } - - return reader.DeserializeUnexpectedType(ref field); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Copier_BasicGrain : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier - { - private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public global::TestProject.BasicGrain DeepCopy(global::TestProject.BasicGrain original, global::Orleans.Serialization.Cloning.CopyContext context) - { - if (context.TryGetCopy(original, out global::TestProject.BasicGrain existing)) - return existing; - if (original.GetType() != typeof(global::TestProject.BasicGrain)) - return context.DeepCopy(original); - var result = new global::TestProject.BasicGrain(); - context.RecordCopy(original, result); - DeepCopy(original, result, context); - return result; - } - - public Copier_BasicGrain(global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier) - { - this._baseTypeCopier = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeCopier); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void DeepCopy(global::TestProject.BasicGrain input, global::TestProject.BasicGrain output, global::Orleans.Serialization.Cloning.CopyContext context) - { - _baseTypeCopier.DeepCopy(input, output, context); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class Activator_BasicGrain : global::Orleans.Serialization.Activators.IActivator - { - public global::TestProject.BasicGrain Create() => new global::TestProject.BasicGrain(); - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class RpcResponseFactories : global::Orleans.Serialization.SerializerContext - { - protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) - { - options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); - options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); - options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); -#if NET5_0_OR_GREATER - if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) - return; - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); - options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); - options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); - options.AddAllowedType(typeof(string)); - options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); - options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); - options.AddDefaultSerializerService(static provider => new CompletedResponseActivator()); - options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); - options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); -#endif - } - - private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator - { - public CompletedResponseActivator() - { - } - - public global::Orleans.Serialization.Invocation.CompletedResponse Create() => global::Orleans.Serialization.Invocation.CompletedResponse.Instance; - } - - private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer - { - public ResponseFieldCodec() - { - } - } - - private sealed class ResponseFieldCopier : global::Orleans.Serialization.Cloning.IDeepCopier - { - public ResponseFieldCopier() - { - } - - [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] - public global::Orleans.Serialization.Invocation.Response DeepCopy(global::Orleans.Serialization.Invocation.Response input, global::Orleans.Serialization.Cloning.CopyContext context) - { - if (context is null) - throw new global::System.ArgumentNullException(nameof(context)); - if (input is global::Orleans.Serialization.Invocation.CompletedResponse or global::Orleans.Serialization.Invocation.ExceptionResponse) - return input; - return (global::Orleans.Serialization.Invocation.Response)global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context); - } - } - } - - internal sealed class RpcResponse_9146C7E3 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter - { - internal string Value; - private RpcResponse_9146C7E3Factory _factory; - public RpcResponse_9146C7E3() - { - } - - internal static RpcResponse_9146C7E3 Rent(string value, RpcResponse_9146C7E3Factory factory) - { - var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); - result.Value = value; - result._factory = factory; - return result; - } - - public override object Result { get => Value; set => Value = (string)value; } - public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } - - public override global::System.Type GetSimpleResultType() => typeof(string); - public override T GetResult() - { - if (typeof(T) == typeof(string)) - return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); - return (T)(object)Value; - } - - public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (_factory is null) - throw new global::System.ObjectDisposedException(GetType().Name); - writer.WriteStartObject(0, null, typeof(string)); - if (Value is not null) - { - global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, Value); - } - - writer.WriteEndObject(); - } - - public override void Dispose() - { - if (_factory is null) - return; - Value = default; - _factory = null; - global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); - } - } - - internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader - { - private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; - private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; - public bool IsSupported { get; } - - internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) - { - provider.GetCodec(); - provider.GetDeepCopier(); - provider.GetCodec>(); - provider.GetDeepCopier>(); - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); - } - - public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) - { - _codec = provider.GetCodec() as global::Orleans.Serialization.Codecs.StringCodec; - _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; - var responseCodec = provider.GetCodec>(); - var responseCopier = provider.GetDeepCopier>(); - IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); - } - - internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) - { - return RpcResponse_9146C7E3.Rent(value, this); - } - - [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] - public RpcResponse_9146C7E3 DeepCopy(RpcResponse_9146C7E3 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_9146C7E3.Rent(input.Value, this); - internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, string value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - writer.WriteStartObject(0, null, typeof(string)); - if (value is not null) - { - global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value); - } - - writer.WriteEndObject(); - } - - public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); - public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) - { - field.EnsureWireTypeTagDelimited(); - var result = RpcResponse_9146C7E3.Rent(default, this); - try - { - reader.ReadFieldHeader(ref field); - if (!field.IsEndBaseOrEndObject) - { - result.Value = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, field); - reader.ReadFieldHeader(ref field); - reader.ConsumeEndBaseOrEndObject(ref field); - } - - return result; - } - catch - { - result.Dispose(); - throw; - } - } - - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_9146C7E3 value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (value is null) - { - global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); - return; - } - - global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); - writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); - if (value.Value is not null) - { - global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value.Value); - } - - writer.WriteEndObject(); - } - - public RpcResponse_9146C7E3 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) - { - if (field.IsReference) - return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); - global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); - return ReadResult(ref reader, ref field); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase - { - protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) - { - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IBasicGrain_GrainReference_6B0E24A1), typeof(OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_BasicGrain), typeof(global::TestProject.BasicGrain)); - config.AddBaseCodec(typeof(OrleansCodeGen.TestProject.Codec_BasicGrain), typeof(global::TestProject.BasicGrain)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IBasicGrain_GrainReference_6B0E24A1), typeof(OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_BasicGrain), typeof(global::TestProject.BasicGrain)); - config.AddBaseCopier(typeof(OrleansCodeGen.TestProject.Copier_BasicGrain), typeof(global::TestProject.BasicGrain)); - config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IBasicGrain)); - config.AddInterface(typeof(global::TestProject.IBasicGrain)); - config.AddInterfaceImplementation(typeof(global::TestProject.BasicGrain)); - config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_BasicGrain), typeof(global::TestProject.BasicGrain)); - var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); - var n2 = n1.GetOrAdd(typeof(global::Orleans.Runtime.GrainReference)); - var n3 = n2.GetOrAdd(typeof(global::TestProject.IBasicGrain)); - n3.Add("6B0E24A1", typeof(OrleansCodeGen.TestProject.Invokable_IBasicGrain_GrainReference_6B0E24A1)); - } - } -} -#pragma warning restore \ No newline at end of file diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.verified.cs deleted file mode 100644 index e23ddea832f..00000000000 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.verified.cs +++ /dev/null @@ -1,399 +0,0 @@ -[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] -#pragma warning disable -[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] -[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] -[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] -[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] -[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] -[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] -namespace OrleansCodeGen -{ - using global::Orleans.Serialization.Codecs; - using global::Orleans.Serialization.GeneratedCodeHelpers; - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::IMyGrain), "6D39E404")] - public sealed class Invokable_IMyGrain_GrainReference_6D39E404 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable - { - public string arg0; - global::IMyGrain _target; - private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::IMyGrain).GetMethod("SayHello", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new[] { typeof(string) }, null); - public override int GetArgumentCount() => 1; - public override string GetMethodName() => "SayHello"; - public override string GetInterfaceName() => "IMyGrain"; - public override string GetActivityName() => "IMyGrain/SayHello"; - public override global::System.Type GetInterfaceType() => typeof(global::IMyGrain); - public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; - public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = (global::IMyGrain)holder.GetTarget(); - public override object GetTarget() => _target; - public override void Dispose() - { - arg0 = default; - _target = default; - } - - public override object GetArgument(int index) - { - switch (index) - { - case 0: - return arg0; - default: - return OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); - } - } - - public override void SetArgument(int index, object value) - { - switch (index) - { - case 0: - arg0 = (string)value; - return; - default: - OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); - return; - } - } - - protected override global::System.Threading.Tasks.Task InvokeInner() => _target.SayHello(arg0); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) - { - try - { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); - if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); - string value = await InvokeInner(); - return factory.RentCopied(value, contexts); - } - catch (global::System.Exception exception) - { - return global::Orleans.Serialization.Invocation.Response.FromException(exception); - } - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class Proxy_IMyGrain : global::Orleans.Runtime.GrainReference, global::IMyGrain - { - public Proxy_IMyGrain(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) - { - } - - global::System.Threading.Tasks.Task global::IMyGrain.SayHello(string arg0) - { - var request = new OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404(); - request.arg0 = arg0; - return base.InvokeAsync(request).AsTask(); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Codec_Invokable_IMyGrain_GrainReference_6D39E404 : global::Orleans.Serialization.Codecs.IFieldCodec - { - private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404); - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404 instance) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.arg0); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404 instance) - { - uint id = 0U; - global::Orleans.Serialization.WireProtocol.Field header = default; - while (true) - { - reader.ReadFieldHeader(ref header); - if (header.IsEndBaseOrEndObject) - break; - id += header.FieldIdDelta; - if (id == 0U) - { - instance.arg0 = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); - reader.ReadFieldHeader(ref header); - } - - reader.ConsumeEndBaseOrEndObject(ref header); - break; - } - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404 @value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (@value is null) - { - ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); - return; - } - - ReferenceCodec.MarkValueField(writer.Session); - writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); - Serialize(ref writer, @value); - writer.WriteEndObject(); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) - { - if (field.IsReference) - return ReferenceCodec.ReadReference(ref reader, field); - field.EnsureWireTypeTagDelimited(); - var result = new OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404(); - ReferenceCodec.MarkValueField(reader.Session); - Deserialize(ref reader, result); - return result; - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Copier_Invokable_IMyGrain_GrainReference_6D39E404 : global::Orleans.Serialization.Cloning.IDeepCopier - { - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404 DeepCopy(OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404 original, global::Orleans.Serialization.Cloning.CopyContext context) - { - if (original is null) - return null; - var result = new OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404(); - result.arg0 = original.arg0; - return result; - } - } -} - -namespace OrleansCodeGen.TestProject -{ - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class RpcResponseFactories : global::Orleans.Serialization.SerializerContext - { - protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) - { - options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); - options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); - options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); -#if NET5_0_OR_GREATER - if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) - return; - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); - options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); - options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); - options.AddAllowedType(typeof(string)); - options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); - options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); - options.AddDefaultSerializerService(static provider => new CompletedResponseActivator()); - options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); - options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); -#endif - } - - private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator - { - public CompletedResponseActivator() - { - } - - public global::Orleans.Serialization.Invocation.CompletedResponse Create() => global::Orleans.Serialization.Invocation.CompletedResponse.Instance; - } - - private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer - { - public ResponseFieldCodec() - { - } - } - - private sealed class ResponseFieldCopier : global::Orleans.Serialization.Cloning.IDeepCopier - { - public ResponseFieldCopier() - { - } - - [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] - public global::Orleans.Serialization.Invocation.Response DeepCopy(global::Orleans.Serialization.Invocation.Response input, global::Orleans.Serialization.Cloning.CopyContext context) - { - if (context is null) - throw new global::System.ArgumentNullException(nameof(context)); - if (input is global::Orleans.Serialization.Invocation.CompletedResponse or global::Orleans.Serialization.Invocation.ExceptionResponse) - return input; - return (global::Orleans.Serialization.Invocation.Response)global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context); - } - } - } - - internal sealed class RpcResponse_9146C7E3 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter - { - internal string Value; - private RpcResponse_9146C7E3Factory _factory; - public RpcResponse_9146C7E3() - { - } - - internal static RpcResponse_9146C7E3 Rent(string value, RpcResponse_9146C7E3Factory factory) - { - var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); - result.Value = value; - result._factory = factory; - return result; - } - - public override object Result { get => Value; set => Value = (string)value; } - public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } - - public override global::System.Type GetSimpleResultType() => typeof(string); - public override T GetResult() - { - if (typeof(T) == typeof(string)) - return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); - return (T)(object)Value; - } - - public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (_factory is null) - throw new global::System.ObjectDisposedException(GetType().Name); - writer.WriteStartObject(0, null, typeof(string)); - if (Value is not null) - { - global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, Value); - } - - writer.WriteEndObject(); - } - - public override void Dispose() - { - if (_factory is null) - return; - Value = default; - _factory = null; - global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); - } - } - - internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader - { - private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; - private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; - public bool IsSupported { get; } - - internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) - { - provider.GetCodec(); - provider.GetDeepCopier(); - provider.GetCodec>(); - provider.GetDeepCopier>(); - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); - } - - public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) - { - _codec = provider.GetCodec() as global::Orleans.Serialization.Codecs.StringCodec; - _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; - var responseCodec = provider.GetCodec>(); - var responseCopier = provider.GetDeepCopier>(); - IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); - } - - internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) - { - return RpcResponse_9146C7E3.Rent(value, this); - } - - [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] - public RpcResponse_9146C7E3 DeepCopy(RpcResponse_9146C7E3 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_9146C7E3.Rent(input.Value, this); - internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, string value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - writer.WriteStartObject(0, null, typeof(string)); - if (value is not null) - { - global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value); - } - - writer.WriteEndObject(); - } - - public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); - public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) - { - field.EnsureWireTypeTagDelimited(); - var result = RpcResponse_9146C7E3.Rent(default, this); - try - { - reader.ReadFieldHeader(ref field); - if (!field.IsEndBaseOrEndObject) - { - result.Value = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, field); - reader.ReadFieldHeader(ref field); - reader.ConsumeEndBaseOrEndObject(ref field); - } - - return result; - } - catch - { - result.Dispose(); - throw; - } - } - - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_9146C7E3 value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (value is null) - { - global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); - return; - } - - global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); - writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); - if (value.Value is not null) - { - global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value.Value); - } - - writer.WriteEndObject(); - } - - public RpcResponse_9146C7E3 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) - { - if (field.IsReference) - return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); - global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); - return ReadResult(ref reader, ref field); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase - { - protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) - { - config.AddSerializer(typeof(OrleansCodeGen.Codec_Invokable_IMyGrain_GrainReference_6D39E404), typeof(OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404)); - config.AddCopier(typeof(OrleansCodeGen.Copier_Invokable_IMyGrain_GrainReference_6D39E404), typeof(OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404)); - config.AddInterfaceProxy(typeof(OrleansCodeGen.Proxy_IMyGrain)); - config.AddInterface(typeof(global::IMyGrain)); - var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); - var n2 = n1.GetOrAdd(typeof(global::Orleans.Runtime.GrainReference)); - var n3 = n2.GetOrAdd(typeof(global::IMyGrain)); - n3.Add("6D39E404", typeof(OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404)); - } - } -} -#pragma warning restore \ No newline at end of file diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs index c57d1e4f173..7cf5715b388 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs @@ -483,6 +483,8 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Codec_ComplexData(), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Copier_ComplexData(), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); + options.AddDefaultSerializerService, global::OrleansCodeGen.TestProject.Codec_ComplexData>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); + options.AddDefaultSerializerService, global::OrleansCodeGen.TestProject.Copier_ComplexData>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::TestProject.ComplexData)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.Int32Codec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs index c6ecb433671..80f59fc84f1 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs @@ -482,6 +482,8 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Codec_ComplexData(), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Copier_ComplexData(), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); + options.AddDefaultSerializerService, global::OrleansCodeGen.TestProject.Codec_ComplexData>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); + options.AddDefaultSerializerService, global::OrleansCodeGen.TestProject.Copier_ComplexData>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); options.AddAllowedType(typeof(global::TestProject.ComplexData)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.Int32Codec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.verified.cs deleted file mode 100644 index 2868b676f37..00000000000 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.verified.cs +++ /dev/null @@ -1,699 +0,0 @@ -[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] -#pragma warning disable -[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] -[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] -[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] -[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] -[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] -[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] -namespace OrleansCodeGen.TestProject -{ - using global::Orleans.Serialization.Codecs; - using global::Orleans.Serialization.GeneratedCodeHelpers; - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IComplexGrain), "67FE5808")] - public sealed class Invokable_IComplexGrain_GrainReference_67FE5808 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable - { - public int arg0; - public string arg1; - public global::TestProject.ComplexData arg2; - public global::System.Threading.CancellationToken arg3; - global::TestProject.IComplexGrain _target; - private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IComplexGrain).GetMethod("ProcessData", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new[] { typeof(int), typeof(string), typeof(global::TestProject.ComplexData), typeof(global::System.Threading.CancellationToken) }, null); - global::System.Threading.CancellationTokenSource _cts; - public override int GetArgumentCount() => 4; - public override string GetMethodName() => "ProcessData"; - public override string GetInterfaceName() => "TestProject.IComplexGrain"; - public override string GetActivityName() => "IComplexGrain/ProcessData"; - public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IComplexGrain); - public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; - public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) - { - _target = (global::TestProject.IComplexGrain)holder.GetTarget(); - _cts = new(); - arg3 = _cts.Token; - } - - public override object GetTarget() => _target; - public override void Dispose() - { - arg0 = default; - arg1 = default; - arg2 = default; - arg3 = default; - _target = default; - _cts?.Dispose(); - _cts = default; - } - - public override object GetArgument(int index) - { - switch (index) - { - case 0: - return arg0; - case 1: - return arg1; - case 2: - return arg2; - case 3: - return arg3; - default: - return OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 3); - } - } - - public override void SetArgument(int index, object value) - { - switch (index) - { - case 0: - arg0 = (int)value; - return; - case 1: - arg1 = (string)value; - return; - case 2: - arg2 = (global::TestProject.ComplexData)value; - return; - case 3: - arg3 = (global::System.Threading.CancellationToken)value; - return; - default: - OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 3); - return; - } - } - - protected override global::System.Threading.Tasks.Task InvokeInner() => _target.ProcessData(arg0, arg1, arg2, arg3); - public override global::System.Threading.CancellationToken GetCancellationToken() => arg3; - public override bool TryCancel() - { - if (_cts is { } cts) - { - cts.Cancel(false); - return true; - } - - return false; - } - - public override bool IsCancellable => true; - - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) - { - try - { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_FC7DD5BDFactory.Resolve(provider); - if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); - global::TestProject.ComplexData value = await InvokeInner(); - return factory.RentCopied(value, contexts); - } - catch (global::System.Exception exception) - { - return global::Orleans.Serialization.Invocation.Response.FromException(exception); - } - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class Proxy_IComplexGrain : global::Orleans.Runtime.GrainReference, global::TestProject.IComplexGrain - { - private readonly OrleansCodeGen.TestProject.Copier_ComplexData _copier_ComplexData_765A40ED2309AF35; - public Proxy_IComplexGrain(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) - { - _copier_ComplexData_765A40ED2309AF35 = OrleansGeneratedCodeHelper.GetService(this, CodecProvider); - } - - global::System.Threading.Tasks.Task global::TestProject.IComplexGrain.ProcessData(int arg0, string arg1, global::TestProject.ComplexData arg2, global::System.Threading.CancellationToken arg3) - { - var request = new OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808(); - request.arg0 = arg0; - request.arg1 = arg1; - using var copyContext = base.CopyContextPool.GetContext(); - request.arg2 = _copier_ComplexData_765A40ED2309AF35.DeepCopy(arg2, copyContext); - request.arg3 = arg3; - return base.InvokeAsync(request).AsTask(); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Codec_ComplexData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec - { - private readonly global::System.Type _codecFieldType = typeof(global::TestProject.ComplexData); - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.ComplexData instance) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - global::Orleans.Serialization.Codecs.Int32Codec.WriteField(ref writer, 0U, instance.IntValue); - global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 1U, instance.StringValue); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.ComplexData instance) - { - uint id = 0U; - global::Orleans.Serialization.WireProtocol.Field header = default; - while (true) - { - reader.ReadFieldHeader(ref header); - if (header.IsEndBaseOrEndObject) - break; - id += header.FieldIdDelta; - if (id == 0U) - { - instance.IntValue = global::Orleans.Serialization.Codecs.Int32Codec.ReadValue(ref reader, header); - reader.ReadFieldHeader(ref header); - if (header.IsEndBaseOrEndObject) - break; - id += header.FieldIdDelta; - } - - if (id == 1U) - { - instance.StringValue = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); - reader.ReadFieldHeader(ref header); - } - - reader.ConsumeEndBaseOrEndObject(ref header); - break; - } - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.ComplexData @value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (@value is null || @value.GetType() == typeof(global::TestProject.ComplexData)) - { - if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) - return; - writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); - Serialize(ref writer, @value); - writer.WriteEndObject(); - } - else - writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public global::TestProject.ComplexData ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) - { - if (field.IsReference) - return ReferenceCodec.ReadReference(ref reader, field); - field.EnsureWireTypeTagDelimited(); - global::System.Type valueType = field.FieldType; - if (valueType is null || valueType == _codecFieldType) - { - var result = new global::TestProject.ComplexData(); - ReferenceCodec.RecordObject(reader.Session, result); - Deserialize(ref reader, result); - return result; - } - - return reader.DeserializeUnexpectedType(ref field); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Copier_ComplexData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier - { - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public global::TestProject.ComplexData DeepCopy(global::TestProject.ComplexData original, global::Orleans.Serialization.Cloning.CopyContext context) - { - if (context.TryGetCopy(original, out global::TestProject.ComplexData existing)) - return existing; - if (original.GetType() != typeof(global::TestProject.ComplexData)) - return context.DeepCopy(original); - var result = new global::TestProject.ComplexData(); - context.RecordCopy(original, result); - DeepCopy(original, result, context); - return result; - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void DeepCopy(global::TestProject.ComplexData input, global::TestProject.ComplexData output, global::Orleans.Serialization.Cloning.CopyContext context) - { - output.IntValue = input.IntValue; - output.StringValue = input.StringValue; - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class Activator_ComplexData : global::Orleans.Serialization.Activators.IActivator - { - public global::TestProject.ComplexData Create() => new global::TestProject.ComplexData(); - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Codec_Invokable_IComplexGrain_GrainReference_67FE5808 : global::Orleans.Serialization.Codecs.IFieldCodec - { - private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808); - private readonly global::System.Type _type_ComplexData_765A40ED2309AF35 = typeof(global::TestProject.ComplexData); - private readonly OrleansCodeGen.TestProject.Codec_ComplexData _codec_ComplexData_765A40ED2309AF35; - public Codec_Invokable_IComplexGrain_GrainReference_67FE5808(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) - { - _codec_ComplexData_765A40ED2309AF35 = OrleansGeneratedCodeHelper.GetService(this, codecProvider); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808 instance) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - global::Orleans.Serialization.Codecs.Int32Codec.WriteField(ref writer, 0U, instance.arg0); - global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 1U, instance.arg1); - _codec_ComplexData_765A40ED2309AF35.WriteField(ref writer, 1U, _type_ComplexData_765A40ED2309AF35, instance.arg2); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808 instance) - { - uint id = 0U; - global::Orleans.Serialization.WireProtocol.Field header = default; - while (true) - { - reader.ReadFieldHeader(ref header); - if (header.IsEndBaseOrEndObject) - break; - id += header.FieldIdDelta; - if (id == 0U) - { - instance.arg0 = global::Orleans.Serialization.Codecs.Int32Codec.ReadValue(ref reader, header); - reader.ReadFieldHeader(ref header); - if (header.IsEndBaseOrEndObject) - break; - id += header.FieldIdDelta; - } - - if (id == 1U) - { - instance.arg1 = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); - reader.ReadFieldHeader(ref header); - if (header.IsEndBaseOrEndObject) - break; - id += header.FieldIdDelta; - } - - if (id == 2U) - { - instance.arg2 = _codec_ComplexData_765A40ED2309AF35.ReadValue(ref reader, header); - reader.ReadFieldHeader(ref header); - } - - reader.ConsumeEndBaseOrEndObject(ref header); - break; - } - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808 @value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (@value is null) - { - ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); - return; - } - - ReferenceCodec.MarkValueField(writer.Session); - writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); - Serialize(ref writer, @value); - writer.WriteEndObject(); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) - { - if (field.IsReference) - return ReferenceCodec.ReadReference(ref reader, field); - field.EnsureWireTypeTagDelimited(); - var result = new OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808(); - ReferenceCodec.MarkValueField(reader.Session); - Deserialize(ref reader, result); - return result; - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Copier_Invokable_IComplexGrain_GrainReference_67FE5808 : global::Orleans.Serialization.Cloning.IDeepCopier - { - private readonly OrleansCodeGen.TestProject.Copier_ComplexData _copier_ComplexData_765A40ED2309AF35; - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808 DeepCopy(OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808 original, global::Orleans.Serialization.Cloning.CopyContext context) - { - if (original is null) - return null; - var result = new OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808(); - result.arg0 = original.arg0; - result.arg1 = original.arg1; - result.arg2 = _copier_ComplexData_765A40ED2309AF35.DeepCopy(original.arg2, context); - result.arg3 = original.arg3; - return result; - } - - public Copier_Invokable_IComplexGrain_GrainReference_67FE5808(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) - { - _copier_ComplexData_765A40ED2309AF35 = OrleansGeneratedCodeHelper.GetService(this, codecProvider); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Codec_ComplexGrain : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec - { - private readonly global::System.Type _codecFieldType = typeof(global::TestProject.ComplexGrain); - private readonly global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer; - public Codec_ComplexGrain(global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer) - { - this._baseTypeSerializer = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeSerializer); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.ComplexGrain instance) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - _baseTypeSerializer.Serialize(ref writer, instance); - writer.WriteEndBase(); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.ComplexGrain instance) - { - _baseTypeSerializer.Deserialize(ref reader, instance); - reader.ConsumeEndBaseOrEndObject(); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.ComplexGrain @value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (@value is null || @value.GetType() == typeof(global::TestProject.ComplexGrain)) - { - if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) - return; - writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); - Serialize(ref writer, @value); - writer.WriteEndObject(); - } - else - writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public global::TestProject.ComplexGrain ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) - { - if (field.IsReference) - return ReferenceCodec.ReadReference(ref reader, field); - field.EnsureWireTypeTagDelimited(); - global::System.Type valueType = field.FieldType; - if (valueType is null || valueType == _codecFieldType) - { - var result = new global::TestProject.ComplexGrain(); - ReferenceCodec.RecordObject(reader.Session, result); - Deserialize(ref reader, result); - return result; - } - - return reader.DeserializeUnexpectedType(ref field); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Copier_ComplexGrain : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier - { - private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public global::TestProject.ComplexGrain DeepCopy(global::TestProject.ComplexGrain original, global::Orleans.Serialization.Cloning.CopyContext context) - { - if (context.TryGetCopy(original, out global::TestProject.ComplexGrain existing)) - return existing; - if (original.GetType() != typeof(global::TestProject.ComplexGrain)) - return context.DeepCopy(original); - var result = new global::TestProject.ComplexGrain(); - context.RecordCopy(original, result); - DeepCopy(original, result, context); - return result; - } - - public Copier_ComplexGrain(global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier) - { - this._baseTypeCopier = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeCopier); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void DeepCopy(global::TestProject.ComplexGrain input, global::TestProject.ComplexGrain output, global::Orleans.Serialization.Cloning.CopyContext context) - { - _baseTypeCopier.DeepCopy(input, output, context); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class Activator_ComplexGrain : global::Orleans.Serialization.Activators.IActivator - { - public global::TestProject.ComplexGrain Create() => new global::TestProject.ComplexGrain(); - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class RpcResponseFactories : global::Orleans.Serialization.SerializerContext - { - protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) - { - options.AddDefaultSerializerService(static provider => new RpcResponse_FC7DD5BDFactory(provider)); - options.AddDefaultSerializer(static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider), static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider)); - options.AddRawResponseReader(static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider)); -#if NET5_0_OR_GREATER - if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) - return; - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); - options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); - options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Codec_ComplexData()); - options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Copier_ComplexData()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); - options.AddAllowedType(typeof(global::TestProject.ComplexData)); - options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.Int32Codec()); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); - options.AddAllowedType(typeof(int)); - options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); - options.AddAllowedType(typeof(string)); - options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); - options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); - options.AddDefaultSerializerService(static provider => new CompletedResponseActivator()); - options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); - options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); -#endif - } - - private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator - { - public CompletedResponseActivator() - { - } - - public global::Orleans.Serialization.Invocation.CompletedResponse Create() => global::Orleans.Serialization.Invocation.CompletedResponse.Instance; - } - - private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer - { - public ResponseFieldCodec() - { - } - } - - private sealed class ResponseFieldCopier : global::Orleans.Serialization.Cloning.IDeepCopier - { - public ResponseFieldCopier() - { - } - - [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] - public global::Orleans.Serialization.Invocation.Response DeepCopy(global::Orleans.Serialization.Invocation.Response input, global::Orleans.Serialization.Cloning.CopyContext context) - { - if (context is null) - throw new global::System.ArgumentNullException(nameof(context)); - if (input is global::Orleans.Serialization.Invocation.CompletedResponse or global::Orleans.Serialization.Invocation.ExceptionResponse) - return input; - return (global::Orleans.Serialization.Invocation.Response)global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context); - } - } - } - - internal sealed class RpcResponse_FC7DD5BD : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter - { - internal global::TestProject.ComplexData Value; - private RpcResponse_FC7DD5BDFactory _factory; - public RpcResponse_FC7DD5BD() - { - } - - internal static RpcResponse_FC7DD5BD Rent(global::TestProject.ComplexData value, RpcResponse_FC7DD5BDFactory factory) - { - var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); - result.Value = value; - result._factory = factory; - return result; - } - - public override object Result { get => Value; set => Value = (global::TestProject.ComplexData)value; } - public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } - - public override global::System.Type GetSimpleResultType() => typeof(global::TestProject.ComplexData); - public override T GetResult() - { - if (typeof(T) == typeof(global::TestProject.ComplexData)) - return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); - return (T)(object)Value; - } - - public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (_factory is null) - throw new global::System.ObjectDisposedException(GetType().Name); - _factory.WriteResult(ref writer, Value); - } - - public override void Dispose() - { - if (_factory is null) - return; - Value = default; - _factory = null; - global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); - } - } - - internal sealed class RpcResponse_FC7DD5BDFactory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader - { - private readonly global::OrleansCodeGen.TestProject.Codec_ComplexData _codec; - private readonly global::OrleansCodeGen.TestProject.Copier_ComplexData _copier; - public bool IsSupported { get; } - - internal static RpcResponse_FC7DD5BDFactory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) - { - provider.GetCodec(); - provider.GetDeepCopier(); - provider.GetCodec>(); - provider.GetDeepCopier>(); - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); - } - - public RpcResponse_FC7DD5BDFactory(global::Orleans.Serialization.Serializers.ICodecProvider provider) - { - _codec = provider.GetCodec() as global::OrleansCodeGen.TestProject.Codec_ComplexData; - _copier = provider.GetDeepCopier() as global::OrleansCodeGen.TestProject.Copier_ComplexData; - var responseCodec = provider.GetCodec>(); - var responseCopier = provider.GetDeepCopier>(); - IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); - } - - internal global::Orleans.Serialization.Invocation.Response RentCopied(global::TestProject.ComplexData value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) - { - using var context = contexts.GetContext(); - return RpcResponse_FC7DD5BD.Rent(_copier.DeepCopy(value, context), this); - } - - [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] - public RpcResponse_FC7DD5BD DeepCopy(RpcResponse_FC7DD5BD input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_FC7DD5BD.Rent(_copier.DeepCopy(input.Value, context), this); - internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.ComplexData value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - writer.WriteStartObject(0, null, typeof(global::TestProject.ComplexData)); - if (value is not null) - { - _codec.WriteField(ref writer, 0, typeof(global::TestProject.ComplexData), value); - } - - writer.WriteEndObject(); - } - - public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_FC7DD5BD)value).Value); - public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - private RpcResponse_FC7DD5BD ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) - { - field.EnsureWireTypeTagDelimited(); - var result = RpcResponse_FC7DD5BD.Rent(default, this); - try - { - reader.ReadFieldHeader(ref field); - if (!field.IsEndBaseOrEndObject) - { - result.Value = _codec.ReadValue(ref reader, field); - reader.ReadFieldHeader(ref field); - reader.ConsumeEndBaseOrEndObject(ref field); - } - - return result; - } - catch - { - result.Dispose(); - throw; - } - } - - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_FC7DD5BD value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (value is null) - { - global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); - return; - } - - global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); - writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); - if (value.Value is not null) - { - _codec.WriteField(ref writer, 0, typeof(global::TestProject.ComplexData), value.Value); - } - - writer.WriteEndObject(); - } - - public RpcResponse_FC7DD5BD ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) - { - if (field.IsReference) - return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); - global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); - return ReadResult(ref reader, ref field); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase - { - protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) - { - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_ComplexData), typeof(global::TestProject.ComplexData)); - config.AddBaseCodec(typeof(OrleansCodeGen.TestProject.Codec_ComplexData), typeof(global::TestProject.ComplexData)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IComplexGrain_GrainReference_67FE5808), typeof(OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_ComplexGrain), typeof(global::TestProject.ComplexGrain)); - config.AddBaseCodec(typeof(OrleansCodeGen.TestProject.Codec_ComplexGrain), typeof(global::TestProject.ComplexGrain)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_ComplexData), typeof(global::TestProject.ComplexData)); - config.AddBaseCopier(typeof(OrleansCodeGen.TestProject.Copier_ComplexData), typeof(global::TestProject.ComplexData)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IComplexGrain_GrainReference_67FE5808), typeof(OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_ComplexGrain), typeof(global::TestProject.ComplexGrain)); - config.AddBaseCopier(typeof(OrleansCodeGen.TestProject.Copier_ComplexGrain), typeof(global::TestProject.ComplexGrain)); - config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IComplexGrain)); - config.AddInterface(typeof(global::TestProject.IComplexGrain)); - config.AddInterfaceImplementation(typeof(global::TestProject.ComplexGrain)); - config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_ComplexData), typeof(global::TestProject.ComplexData)); - config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_ComplexGrain), typeof(global::TestProject.ComplexGrain)); - var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); - var n2 = n1.GetOrAdd(typeof(global::Orleans.Runtime.GrainReference)); - var n3 = n2.GetOrAdd(typeof(global::TestProject.IComplexGrain)); - n3.Add("67FE5808", typeof(OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808)); - } - } -} -#pragma warning restore \ No newline at end of file diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.verified.cs deleted file mode 100644 index 59bbe4aab27..00000000000 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.verified.cs +++ /dev/null @@ -1,502 +0,0 @@ -[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] -#pragma warning disable -[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] -[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] -[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] -[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] -[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] -[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] -namespace OrleansCodeGen.TestProject -{ - using global::Orleans.Serialization.Codecs; - using global::Orleans.Serialization.GeneratedCodeHelpers; - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IHelloGrain), "5336307F")] - public sealed class Invokable_IHelloGrain_GrainReference_5336307F : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable - { - public string arg0; - global::TestProject.IHelloGrain _target; - private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IHelloGrain).GetMethod("SayHello", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new[] { typeof(string) }, null); - public Invokable_IHelloGrain_GrainReference_5336307F() : base() - { - SetLoggingOptions("Hello"); - } - - public override int GetArgumentCount() => 1; - public override string GetMethodName() => "SayHello"; - public override string GetInterfaceName() => "TestProject.IHelloGrain"; - public override string GetActivityName() => "IHelloGrain/SayHello"; - public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IHelloGrain); - public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; - public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = (global::TestProject.IHelloGrain)holder.GetTarget(); - public override object GetTarget() => _target; - public override void Dispose() - { - arg0 = default; - _target = default; - } - - public override object GetArgument(int index) - { - switch (index) - { - case 0: - return arg0; - default: - return OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); - } - } - - public override void SetArgument(int index, object value) - { - switch (index) - { - case 0: - arg0 = (string)value; - return; - default: - OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); - return; - } - } - - protected override global::System.Threading.Tasks.Task InvokeInner() => _target.SayHello(arg0); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) - { - try - { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); - if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); - string value = await InvokeInner(); - return factory.RentCopied(value, contexts); - } - catch (global::System.Exception exception) - { - return global::Orleans.Serialization.Invocation.Response.FromException(exception); - } - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class Proxy_IHelloGrain : global::Orleans.Runtime.GrainReference, global::TestProject.IHelloGrain - { - public Proxy_IHelloGrain(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) - { - } - - global::System.Threading.Tasks.Task global::TestProject.IHelloGrain.SayHello(string arg0) - { - var request = new OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F(); - request.arg0 = arg0; - return base.InvokeAsync(request).AsTask(); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Codec_Invokable_IHelloGrain_GrainReference_5336307F : global::Orleans.Serialization.Codecs.IFieldCodec - { - private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F); - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F instance) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.arg0); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F instance) - { - uint id = 0U; - global::Orleans.Serialization.WireProtocol.Field header = default; - while (true) - { - reader.ReadFieldHeader(ref header); - if (header.IsEndBaseOrEndObject) - break; - id += header.FieldIdDelta; - if (id == 0U) - { - instance.arg0 = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); - reader.ReadFieldHeader(ref header); - } - - reader.ConsumeEndBaseOrEndObject(ref header); - break; - } - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F @value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (@value is null) - { - ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); - return; - } - - ReferenceCodec.MarkValueField(writer.Session); - writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); - Serialize(ref writer, @value); - writer.WriteEndObject(); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) - { - if (field.IsReference) - return ReferenceCodec.ReadReference(ref reader, field); - field.EnsureWireTypeTagDelimited(); - var result = new OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F(); - ReferenceCodec.MarkValueField(reader.Session); - Deserialize(ref reader, result); - return result; - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Copier_Invokable_IHelloGrain_GrainReference_5336307F : global::Orleans.Serialization.Cloning.IDeepCopier - { - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F DeepCopy(OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F original, global::Orleans.Serialization.Cloning.CopyContext context) - { - if (original is null) - return null; - var result = new OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F(); - result.arg0 = original.arg0; - return result; - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Codec_HelloGrain : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec - { - private readonly global::System.Type _codecFieldType = typeof(global::TestProject.HelloGrain); - private readonly global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer; - public Codec_HelloGrain(global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer) - { - this._baseTypeSerializer = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeSerializer); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.HelloGrain instance) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - _baseTypeSerializer.Serialize(ref writer, instance); - writer.WriteEndBase(); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.HelloGrain instance) - { - _baseTypeSerializer.Deserialize(ref reader, instance); - reader.ConsumeEndBaseOrEndObject(); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.HelloGrain @value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (@value is null || @value.GetType() == typeof(global::TestProject.HelloGrain)) - { - if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) - return; - writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); - Serialize(ref writer, @value); - writer.WriteEndObject(); - } - else - writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public global::TestProject.HelloGrain ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) - { - if (field.IsReference) - return ReferenceCodec.ReadReference(ref reader, field); - field.EnsureWireTypeTagDelimited(); - global::System.Type valueType = field.FieldType; - if (valueType is null || valueType == _codecFieldType) - { - var result = new global::TestProject.HelloGrain(); - ReferenceCodec.RecordObject(reader.Session, result); - Deserialize(ref reader, result); - return result; - } - - return reader.DeserializeUnexpectedType(ref field); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Copier_HelloGrain : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier - { - private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public global::TestProject.HelloGrain DeepCopy(global::TestProject.HelloGrain original, global::Orleans.Serialization.Cloning.CopyContext context) - { - if (context.TryGetCopy(original, out global::TestProject.HelloGrain existing)) - return existing; - if (original.GetType() != typeof(global::TestProject.HelloGrain)) - return context.DeepCopy(original); - var result = new global::TestProject.HelloGrain(); - context.RecordCopy(original, result); - DeepCopy(original, result, context); - return result; - } - - public Copier_HelloGrain(global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier) - { - this._baseTypeCopier = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeCopier); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void DeepCopy(global::TestProject.HelloGrain input, global::TestProject.HelloGrain output, global::Orleans.Serialization.Cloning.CopyContext context) - { - _baseTypeCopier.DeepCopy(input, output, context); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class Activator_HelloGrain : global::Orleans.Serialization.Activators.IActivator - { - public global::TestProject.HelloGrain Create() => new global::TestProject.HelloGrain(); - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class RpcResponseFactories : global::Orleans.Serialization.SerializerContext - { - protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) - { - options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); - options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); - options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); -#if NET5_0_OR_GREATER - if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) - return; - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); - options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); - options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); - options.AddAllowedType(typeof(string)); - options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); - options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); - options.AddDefaultSerializerService(static provider => new CompletedResponseActivator()); - options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); - options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); -#endif - } - - private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator - { - public CompletedResponseActivator() - { - } - - public global::Orleans.Serialization.Invocation.CompletedResponse Create() => global::Orleans.Serialization.Invocation.CompletedResponse.Instance; - } - - private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer - { - public ResponseFieldCodec() - { - } - } - - private sealed class ResponseFieldCopier : global::Orleans.Serialization.Cloning.IDeepCopier - { - public ResponseFieldCopier() - { - } - - [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] - public global::Orleans.Serialization.Invocation.Response DeepCopy(global::Orleans.Serialization.Invocation.Response input, global::Orleans.Serialization.Cloning.CopyContext context) - { - if (context is null) - throw new global::System.ArgumentNullException(nameof(context)); - if (input is global::Orleans.Serialization.Invocation.CompletedResponse or global::Orleans.Serialization.Invocation.ExceptionResponse) - return input; - return (global::Orleans.Serialization.Invocation.Response)global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context); - } - } - } - - internal sealed class RpcResponse_9146C7E3 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter - { - internal string Value; - private RpcResponse_9146C7E3Factory _factory; - public RpcResponse_9146C7E3() - { - } - - internal static RpcResponse_9146C7E3 Rent(string value, RpcResponse_9146C7E3Factory factory) - { - var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); - result.Value = value; - result._factory = factory; - return result; - } - - public override object Result { get => Value; set => Value = (string)value; } - public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } - - public override global::System.Type GetSimpleResultType() => typeof(string); - public override T GetResult() - { - if (typeof(T) == typeof(string)) - return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); - return (T)(object)Value; - } - - public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (_factory is null) - throw new global::System.ObjectDisposedException(GetType().Name); - writer.WriteStartObject(0, null, typeof(string)); - if (Value is not null) - { - global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, Value); - } - - writer.WriteEndObject(); - } - - public override void Dispose() - { - if (_factory is null) - return; - Value = default; - _factory = null; - global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); - } - } - - internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader - { - private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; - private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; - public bool IsSupported { get; } - - internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) - { - provider.GetCodec(); - provider.GetDeepCopier(); - provider.GetCodec>(); - provider.GetDeepCopier>(); - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); - } - - public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) - { - _codec = provider.GetCodec() as global::Orleans.Serialization.Codecs.StringCodec; - _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; - var responseCodec = provider.GetCodec>(); - var responseCopier = provider.GetDeepCopier>(); - IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); - } - - internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) - { - return RpcResponse_9146C7E3.Rent(value, this); - } - - [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] - public RpcResponse_9146C7E3 DeepCopy(RpcResponse_9146C7E3 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_9146C7E3.Rent(input.Value, this); - internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, string value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - writer.WriteStartObject(0, null, typeof(string)); - if (value is not null) - { - global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value); - } - - writer.WriteEndObject(); - } - - public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); - public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) - { - field.EnsureWireTypeTagDelimited(); - var result = RpcResponse_9146C7E3.Rent(default, this); - try - { - reader.ReadFieldHeader(ref field); - if (!field.IsEndBaseOrEndObject) - { - result.Value = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, field); - reader.ReadFieldHeader(ref field); - reader.ConsumeEndBaseOrEndObject(ref field); - } - - return result; - } - catch - { - result.Dispose(); - throw; - } - } - - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_9146C7E3 value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (value is null) - { - global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); - return; - } - - global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); - writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); - if (value.Value is not null) - { - global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value.Value); - } - - writer.WriteEndObject(); - } - - public RpcResponse_9146C7E3 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) - { - if (field.IsReference) - return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); - global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); - return ReadResult(ref reader, ref field); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase - { - protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) - { - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IHelloGrain_GrainReference_5336307F), typeof(OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_HelloGrain), typeof(global::TestProject.HelloGrain)); - config.AddBaseCodec(typeof(OrleansCodeGen.TestProject.Codec_HelloGrain), typeof(global::TestProject.HelloGrain)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IHelloGrain_GrainReference_5336307F), typeof(OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_HelloGrain), typeof(global::TestProject.HelloGrain)); - config.AddBaseCopier(typeof(OrleansCodeGen.TestProject.Copier_HelloGrain), typeof(global::TestProject.HelloGrain)); - config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IHelloGrain)); - config.AddInterface(typeof(global::TestProject.IHelloGrain)); - config.AddInterfaceImplementation(typeof(global::TestProject.HelloGrain)); - config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_HelloGrain), typeof(global::TestProject.HelloGrain)); - var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); - var n2 = n1.GetOrAdd(typeof(global::Orleans.Runtime.GrainReference)); - var n3 = n2.GetOrAdd(typeof(global::TestProject.IHelloGrain)); - n3.Add("5336307F", typeof(OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F)); - } - } -} -#pragma warning restore \ No newline at end of file diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.verified.cs deleted file mode 100644 index f7184cfd5e5..00000000000 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.verified.cs +++ /dev/null @@ -1,399 +0,0 @@ -[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] -#pragma warning disable -[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] -[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] -[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] -[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] -[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] -[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] -namespace OrleansCodeGen.TestProject -{ - using global::Orleans.Serialization.Codecs; - using global::Orleans.Serialization.GeneratedCodeHelpers; - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IResponseTimeoutGrain), "6BE752C8")] - public sealed class Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable - { - public string arg0; - global::TestProject.IResponseTimeoutGrain _target; - private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IResponseTimeoutGrain).GetMethod("LongRunningMethod", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new[] { typeof(string) }, null); - private static readonly global::System.TimeSpan _responseTimeoutValue = global::System.TimeSpan.FromTicks(100000000L); - public override global::System.TimeSpan? GetDefaultResponseTimeout() => _responseTimeoutValue; - public override int GetArgumentCount() => 1; - public override string GetMethodName() => "LongRunningMethod"; - public override string GetInterfaceName() => "TestProject.IResponseTimeoutGrain"; - public override string GetActivityName() => "IResponseTimeoutGrain/LongRunningMethod"; - public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IResponseTimeoutGrain); - public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; - public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = (global::TestProject.IResponseTimeoutGrain)holder.GetTarget(); - public override object GetTarget() => _target; - public override void Dispose() - { - arg0 = default; - _target = default; - } - - public override object GetArgument(int index) - { - switch (index) - { - case 0: - return arg0; - default: - return OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); - } - } - - public override void SetArgument(int index, object value) - { - switch (index) - { - case 0: - arg0 = (string)value; - return; - default: - OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); - return; - } - } - - protected override global::System.Threading.Tasks.Task InvokeInner() => _target.LongRunningMethod(arg0); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) - { - try - { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); - if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); - string value = await InvokeInner(); - return factory.RentCopied(value, contexts); - } - catch (global::System.Exception exception) - { - return global::Orleans.Serialization.Invocation.Response.FromException(exception); - } - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class Proxy_IResponseTimeoutGrain : global::Orleans.Runtime.GrainReference, global::TestProject.IResponseTimeoutGrain - { - public Proxy_IResponseTimeoutGrain(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) - { - } - - global::System.Threading.Tasks.Task global::TestProject.IResponseTimeoutGrain.LongRunningMethod(string arg0) - { - var request = new OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8(); - request.arg0 = arg0; - return base.InvokeAsync(request).AsTask(); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Codec_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 : global::Orleans.Serialization.Codecs.IFieldCodec - { - private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8); - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 instance) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.arg0); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 instance) - { - uint id = 0U; - global::Orleans.Serialization.WireProtocol.Field header = default; - while (true) - { - reader.ReadFieldHeader(ref header); - if (header.IsEndBaseOrEndObject) - break; - id += header.FieldIdDelta; - if (id == 0U) - { - instance.arg0 = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); - reader.ReadFieldHeader(ref header); - } - - reader.ConsumeEndBaseOrEndObject(ref header); - break; - } - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 @value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (@value is null) - { - ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); - return; - } - - ReferenceCodec.MarkValueField(writer.Session); - writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); - Serialize(ref writer, @value); - writer.WriteEndObject(); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) - { - if (field.IsReference) - return ReferenceCodec.ReadReference(ref reader, field); - field.EnsureWireTypeTagDelimited(); - var result = new OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8(); - ReferenceCodec.MarkValueField(reader.Session); - Deserialize(ref reader, result); - return result; - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Copier_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 : global::Orleans.Serialization.Cloning.IDeepCopier - { - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 DeepCopy(OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 original, global::Orleans.Serialization.Cloning.CopyContext context) - { - if (original is null) - return null; - var result = new OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8(); - result.arg0 = original.arg0; - return result; - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class RpcResponseFactories : global::Orleans.Serialization.SerializerContext - { - protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) - { - options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); - options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); - options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); -#if NET5_0_OR_GREATER - if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) - return; - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); - options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); - options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); - options.AddAllowedType(typeof(string)); - options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); - options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); - options.AddDefaultSerializerService(static provider => new CompletedResponseActivator()); - options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); - options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); -#endif - } - - private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator - { - public CompletedResponseActivator() - { - } - - public global::Orleans.Serialization.Invocation.CompletedResponse Create() => global::Orleans.Serialization.Invocation.CompletedResponse.Instance; - } - - private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer - { - public ResponseFieldCodec() - { - } - } - - private sealed class ResponseFieldCopier : global::Orleans.Serialization.Cloning.IDeepCopier - { - public ResponseFieldCopier() - { - } - - [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] - public global::Orleans.Serialization.Invocation.Response DeepCopy(global::Orleans.Serialization.Invocation.Response input, global::Orleans.Serialization.Cloning.CopyContext context) - { - if (context is null) - throw new global::System.ArgumentNullException(nameof(context)); - if (input is global::Orleans.Serialization.Invocation.CompletedResponse or global::Orleans.Serialization.Invocation.ExceptionResponse) - return input; - return (global::Orleans.Serialization.Invocation.Response)global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context); - } - } - } - - internal sealed class RpcResponse_9146C7E3 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter - { - internal string Value; - private RpcResponse_9146C7E3Factory _factory; - public RpcResponse_9146C7E3() - { - } - - internal static RpcResponse_9146C7E3 Rent(string value, RpcResponse_9146C7E3Factory factory) - { - var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); - result.Value = value; - result._factory = factory; - return result; - } - - public override object Result { get => Value; set => Value = (string)value; } - public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } - - public override global::System.Type GetSimpleResultType() => typeof(string); - public override T GetResult() - { - if (typeof(T) == typeof(string)) - return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); - return (T)(object)Value; - } - - public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (_factory is null) - throw new global::System.ObjectDisposedException(GetType().Name); - writer.WriteStartObject(0, null, typeof(string)); - if (Value is not null) - { - global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, Value); - } - - writer.WriteEndObject(); - } - - public override void Dispose() - { - if (_factory is null) - return; - Value = default; - _factory = null; - global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); - } - } - - internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader - { - private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; - private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; - public bool IsSupported { get; } - - internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) - { - provider.GetCodec(); - provider.GetDeepCopier(); - provider.GetCodec>(); - provider.GetDeepCopier>(); - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); - } - - public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) - { - _codec = provider.GetCodec() as global::Orleans.Serialization.Codecs.StringCodec; - _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; - var responseCodec = provider.GetCodec>(); - var responseCopier = provider.GetDeepCopier>(); - IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); - } - - internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) - { - return RpcResponse_9146C7E3.Rent(value, this); - } - - [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] - public RpcResponse_9146C7E3 DeepCopy(RpcResponse_9146C7E3 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_9146C7E3.Rent(input.Value, this); - internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, string value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - writer.WriteStartObject(0, null, typeof(string)); - if (value is not null) - { - global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value); - } - - writer.WriteEndObject(); - } - - public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); - public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) - { - field.EnsureWireTypeTagDelimited(); - var result = RpcResponse_9146C7E3.Rent(default, this); - try - { - reader.ReadFieldHeader(ref field); - if (!field.IsEndBaseOrEndObject) - { - result.Value = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, field); - reader.ReadFieldHeader(ref field); - reader.ConsumeEndBaseOrEndObject(ref field); - } - - return result; - } - catch - { - result.Dispose(); - throw; - } - } - - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_9146C7E3 value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (value is null) - { - global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); - return; - } - - global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); - writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); - if (value.Value is not null) - { - global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value.Value); - } - - writer.WriteEndObject(); - } - - public RpcResponse_9146C7E3 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) - { - if (field.IsReference) - return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); - global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); - return ReadResult(ref reader, ref field); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase - { - protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) - { - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8), typeof(OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8), typeof(OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8)); - config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IResponseTimeoutGrain)); - config.AddInterface(typeof(global::TestProject.IResponseTimeoutGrain)); - config.AddInterfaceImplementation(typeof(global::TestProject.ResponseTimeoutGrain)); - var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); - var n2 = n1.GetOrAdd(typeof(global::Orleans.Runtime.GrainReference)); - var n3 = n2.GetOrAdd(typeof(global::TestProject.IResponseTimeoutGrain)); - n3.Add("6BE752C8", typeof(OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8)); - } - } -} -#pragma warning restore \ No newline at end of file diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.verified.cs deleted file mode 100644 index 648e630aa1a..00000000000 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.verified.cs +++ /dev/null @@ -1,1553 +0,0 @@ -[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] -#pragma warning disable -[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] -[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] -[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] -[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] -[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] -[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] -namespace OrleansCodeGen.TestProject -{ - using global::Orleans.Serialization.Codecs; - using global::Orleans.Serialization.GeneratedCodeHelpers; - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IMyGrainWithGuidKey), "8F0FEC0E")] - public sealed class Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable - { - global::TestProject.IMyGrainWithGuidKey _target; - private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IMyGrainWithGuidKey).GetMethod("GetGuidValue", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, global::System.Type.EmptyTypes, null); - public override string GetMethodName() => "GetGuidValue"; - public override string GetInterfaceName() => "TestProject.IMyGrainWithGuidKey"; - public override string GetActivityName() => "IMyGrainWithGuidKey/GetGuidValue"; - public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IMyGrainWithGuidKey); - public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; - public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = (global::TestProject.IMyGrainWithGuidKey)holder.GetTarget(); - public override object GetTarget() => _target; - public override void Dispose() - { - _target = default; - } - - protected override global::System.Threading.Tasks.Task InvokeInner() => _target.GetGuidValue(); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) - { - try - { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_5C3A711CFactory.Resolve(provider); - if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); - global::System.Guid value = await InvokeInner(); - return factory.RentCopied(value, contexts); - } - catch (global::System.Exception exception) - { - return global::Orleans.Serialization.Invocation.Response.FromException(exception); - } - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class Proxy_IMyGrainWithGuidKey : global::Orleans.Runtime.GrainReference, global::TestProject.IMyGrainWithGuidKey - { - public Proxy_IMyGrainWithGuidKey(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) - { - } - - global::System.Threading.Tasks.Task global::TestProject.IMyGrainWithGuidKey.GetGuidValue() - { - var request = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E(); - return base.InvokeAsync(request).AsTask(); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IMyGrainWithStringKey), "43570316")] - public sealed class Invokable_IMyGrainWithStringKey_GrainReference_43570316 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable - { - global::TestProject.IMyGrainWithStringKey _target; - private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IMyGrainWithStringKey).GetMethod("GetStringKey", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, global::System.Type.EmptyTypes, null); - public override string GetMethodName() => "GetStringKey"; - public override string GetInterfaceName() => "TestProject.IMyGrainWithStringKey"; - public override string GetActivityName() => "IMyGrainWithStringKey/GetStringKey"; - public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IMyGrainWithStringKey); - public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; - public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = (global::TestProject.IMyGrainWithStringKey)holder.GetTarget(); - public override object GetTarget() => _target; - public override void Dispose() - { - _target = default; - } - - protected override global::System.Threading.Tasks.Task InvokeInner() => _target.GetStringKey(); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) - { - try - { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); - if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); - string value = await InvokeInner(); - return factory.RentCopied(value, contexts); - } - catch (global::System.Exception exception) - { - return global::Orleans.Serialization.Invocation.Response.FromException(exception); - } - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class Proxy_IMyGrainWithStringKey : global::Orleans.Runtime.GrainReference, global::TestProject.IMyGrainWithStringKey - { - public Proxy_IMyGrainWithStringKey(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) - { - } - - global::System.Threading.Tasks.Task global::TestProject.IMyGrainWithStringKey.GetStringKey() - { - var request = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316(); - return base.InvokeAsync(request).AsTask(); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IMyGrainWithGuidCompoundKey), "A9FEF7AF")] - public sealed class Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF : global::Orleans.Runtime.TaskRequest>, global::Orleans.Serialization.Invocation.IResponseInvokable - { - global::TestProject.IMyGrainWithGuidCompoundKey _target; - private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IMyGrainWithGuidCompoundKey).GetMethod("GetGuidAndStringKey", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, global::System.Type.EmptyTypes, null); - public override string GetMethodName() => "GetGuidAndStringKey"; - public override string GetInterfaceName() => "TestProject.IMyGrainWithGuidCompoundKey"; - public override string GetActivityName() => "IMyGrainWithGuidCompoundKey/GetGuidAndStringKey"; - public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IMyGrainWithGuidCompoundKey); - public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; - public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = (global::TestProject.IMyGrainWithGuidCompoundKey)holder.GetTarget(); - public override object GetTarget() => _target; - public override void Dispose() - { - _target = default; - } - - protected override global::System.Threading.Tasks.Task> InvokeInner() => _target.GetGuidAndStringKey(); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) - { - try - { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_6A3EE8F4Factory.Resolve(provider); - if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); - global::System.Tuple value = await InvokeInner(); - return factory.RentCopied(value, contexts); - } - catch (global::System.Exception exception) - { - return global::Orleans.Serialization.Invocation.Response.FromException(exception); - } - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class Proxy_IMyGrainWithGuidCompoundKey : global::Orleans.Runtime.GrainReference, global::TestProject.IMyGrainWithGuidCompoundKey - { - public Proxy_IMyGrainWithGuidCompoundKey(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) - { - } - - global::System.Threading.Tasks.Task> global::TestProject.IMyGrainWithGuidCompoundKey.GetGuidAndStringKey() - { - var request = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF(); - return base.InvokeAsync>(request).AsTask(); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IMyGrainWithIntegerCompoundKey), "9814021A")] - public sealed class Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A : global::Orleans.Runtime.TaskRequest>, global::Orleans.Serialization.Invocation.IResponseInvokable - { - global::TestProject.IMyGrainWithIntegerCompoundKey _target; - private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IMyGrainWithIntegerCompoundKey).GetMethod("GetIntegerAndStringKey", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, global::System.Type.EmptyTypes, null); - public override string GetMethodName() => "GetIntegerAndStringKey"; - public override string GetInterfaceName() => "TestProject.IMyGrainWithIntegerCompoundKey"; - public override string GetActivityName() => "IMyGrainWithIntegerCompoundKey/GetIntegerAndStringKey"; - public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IMyGrainWithIntegerCompoundKey); - public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; - public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = (global::TestProject.IMyGrainWithIntegerCompoundKey)holder.GetTarget(); - public override object GetTarget() => _target; - public override void Dispose() - { - _target = default; - } - - protected override global::System.Threading.Tasks.Task> InvokeInner() => _target.GetIntegerAndStringKey(); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) - { - try - { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_AFB713E4Factory.Resolve(provider); - if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); - global::System.Tuple value = await InvokeInner(); - return factory.RentCopied(value, contexts); - } - catch (global::System.Exception exception) - { - return global::Orleans.Serialization.Invocation.Response.FromException(exception); - } - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class Proxy_IMyGrainWithIntegerCompoundKey : global::Orleans.Runtime.GrainReference, global::TestProject.IMyGrainWithIntegerCompoundKey - { - public Proxy_IMyGrainWithIntegerCompoundKey(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) - { - } - - global::System.Threading.Tasks.Task> global::TestProject.IMyGrainWithIntegerCompoundKey.GetIntegerAndStringKey() - { - var request = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A(); - return base.InvokeAsync>(request).AsTask(); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Codec_Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E : global::Orleans.Serialization.Codecs.IFieldCodec - { - private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E); - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E instance) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E instance) - { - reader.ConsumeEndBaseOrEndObject(); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E @value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (@value is null) - { - ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); - return; - } - - ReferenceCodec.MarkValueField(writer.Session); - writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); - Serialize(ref writer, @value); - writer.WriteEndObject(); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) - { - if (field.IsReference) - return ReferenceCodec.ReadReference(ref reader, field); - field.EnsureWireTypeTagDelimited(); - var result = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E(); - ReferenceCodec.MarkValueField(reader.Session); - Deserialize(ref reader, result); - return result; - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Copier_Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E : global::Orleans.Serialization.Cloning.IDeepCopier - { - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E DeepCopy(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E original, global::Orleans.Serialization.Cloning.CopyContext context) - { - if (original is null) - return null; - var result = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E(); - return result; - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Codec_GrainWithGuidKey : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec - { - private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GrainWithGuidKey); - private readonly global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer; - public Codec_GrainWithGuidKey(global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer) - { - this._baseTypeSerializer = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeSerializer); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.GrainWithGuidKey instance) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - _baseTypeSerializer.Serialize(ref writer, instance); - writer.WriteEndBase(); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.GrainWithGuidKey instance) - { - _baseTypeSerializer.Deserialize(ref reader, instance); - reader.ConsumeEndBaseOrEndObject(); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.GrainWithGuidKey @value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (@value is null || @value.GetType() == typeof(global::TestProject.GrainWithGuidKey)) - { - if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) - return; - writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); - Serialize(ref writer, @value); - writer.WriteEndObject(); - } - else - writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public global::TestProject.GrainWithGuidKey ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) - { - if (field.IsReference) - return ReferenceCodec.ReadReference(ref reader, field); - field.EnsureWireTypeTagDelimited(); - global::System.Type valueType = field.FieldType; - if (valueType is null || valueType == _codecFieldType) - { - var result = new global::TestProject.GrainWithGuidKey(); - ReferenceCodec.RecordObject(reader.Session, result); - Deserialize(ref reader, result); - return result; - } - - return reader.DeserializeUnexpectedType(ref field); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Copier_GrainWithGuidKey : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier - { - private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public global::TestProject.GrainWithGuidKey DeepCopy(global::TestProject.GrainWithGuidKey original, global::Orleans.Serialization.Cloning.CopyContext context) - { - if (context.TryGetCopy(original, out global::TestProject.GrainWithGuidKey existing)) - return existing; - if (original.GetType() != typeof(global::TestProject.GrainWithGuidKey)) - return context.DeepCopy(original); - var result = new global::TestProject.GrainWithGuidKey(); - context.RecordCopy(original, result); - DeepCopy(original, result, context); - return result; - } - - public Copier_GrainWithGuidKey(global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier) - { - this._baseTypeCopier = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeCopier); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void DeepCopy(global::TestProject.GrainWithGuidKey input, global::TestProject.GrainWithGuidKey output, global::Orleans.Serialization.Cloning.CopyContext context) - { - _baseTypeCopier.DeepCopy(input, output, context); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class Activator_GrainWithGuidKey : global::Orleans.Serialization.Activators.IActivator - { - public global::TestProject.GrainWithGuidKey Create() => new global::TestProject.GrainWithGuidKey(); - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Codec_Invokable_IMyGrainWithStringKey_GrainReference_43570316 : global::Orleans.Serialization.Codecs.IFieldCodec - { - private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316); - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316 instance) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316 instance) - { - reader.ConsumeEndBaseOrEndObject(); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316 @value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (@value is null) - { - ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); - return; - } - - ReferenceCodec.MarkValueField(writer.Session); - writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); - Serialize(ref writer, @value); - writer.WriteEndObject(); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) - { - if (field.IsReference) - return ReferenceCodec.ReadReference(ref reader, field); - field.EnsureWireTypeTagDelimited(); - var result = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316(); - ReferenceCodec.MarkValueField(reader.Session); - Deserialize(ref reader, result); - return result; - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Copier_Invokable_IMyGrainWithStringKey_GrainReference_43570316 : global::Orleans.Serialization.Cloning.IDeepCopier - { - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316 DeepCopy(OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316 original, global::Orleans.Serialization.Cloning.CopyContext context) - { - if (original is null) - return null; - var result = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316(); - return result; - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Codec_GrainWithStringKey : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec - { - private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GrainWithStringKey); - private readonly global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer; - public Codec_GrainWithStringKey(global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer) - { - this._baseTypeSerializer = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeSerializer); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.GrainWithStringKey instance) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - _baseTypeSerializer.Serialize(ref writer, instance); - writer.WriteEndBase(); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.GrainWithStringKey instance) - { - _baseTypeSerializer.Deserialize(ref reader, instance); - reader.ConsumeEndBaseOrEndObject(); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.GrainWithStringKey @value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (@value is null || @value.GetType() == typeof(global::TestProject.GrainWithStringKey)) - { - if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) - return; - writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); - Serialize(ref writer, @value); - writer.WriteEndObject(); - } - else - writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public global::TestProject.GrainWithStringKey ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) - { - if (field.IsReference) - return ReferenceCodec.ReadReference(ref reader, field); - field.EnsureWireTypeTagDelimited(); - global::System.Type valueType = field.FieldType; - if (valueType is null || valueType == _codecFieldType) - { - var result = new global::TestProject.GrainWithStringKey(); - ReferenceCodec.RecordObject(reader.Session, result); - Deserialize(ref reader, result); - return result; - } - - return reader.DeserializeUnexpectedType(ref field); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Copier_GrainWithStringKey : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier - { - private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public global::TestProject.GrainWithStringKey DeepCopy(global::TestProject.GrainWithStringKey original, global::Orleans.Serialization.Cloning.CopyContext context) - { - if (context.TryGetCopy(original, out global::TestProject.GrainWithStringKey existing)) - return existing; - if (original.GetType() != typeof(global::TestProject.GrainWithStringKey)) - return context.DeepCopy(original); - var result = new global::TestProject.GrainWithStringKey(); - context.RecordCopy(original, result); - DeepCopy(original, result, context); - return result; - } - - public Copier_GrainWithStringKey(global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier) - { - this._baseTypeCopier = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeCopier); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void DeepCopy(global::TestProject.GrainWithStringKey input, global::TestProject.GrainWithStringKey output, global::Orleans.Serialization.Cloning.CopyContext context) - { - _baseTypeCopier.DeepCopy(input, output, context); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class Activator_GrainWithStringKey : global::Orleans.Serialization.Activators.IActivator - { - public global::TestProject.GrainWithStringKey Create() => new global::TestProject.GrainWithStringKey(); - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Codec_Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF : global::Orleans.Serialization.Codecs.IFieldCodec - { - private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF); - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF instance) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF instance) - { - reader.ConsumeEndBaseOrEndObject(); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF @value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (@value is null) - { - ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); - return; - } - - ReferenceCodec.MarkValueField(writer.Session); - writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); - Serialize(ref writer, @value); - writer.WriteEndObject(); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) - { - if (field.IsReference) - return ReferenceCodec.ReadReference(ref reader, field); - field.EnsureWireTypeTagDelimited(); - var result = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF(); - ReferenceCodec.MarkValueField(reader.Session); - Deserialize(ref reader, result); - return result; - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Copier_Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF : global::Orleans.Serialization.Cloning.IDeepCopier - { - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF DeepCopy(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF original, global::Orleans.Serialization.Cloning.CopyContext context) - { - if (original is null) - return null; - var result = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF(); - return result; - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Codec_GrainWithGuidCompoundKey : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec - { - private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GrainWithGuidCompoundKey); - private readonly global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer; - public Codec_GrainWithGuidCompoundKey(global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer) - { - this._baseTypeSerializer = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeSerializer); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.GrainWithGuidCompoundKey instance) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - _baseTypeSerializer.Serialize(ref writer, instance); - writer.WriteEndBase(); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.GrainWithGuidCompoundKey instance) - { - _baseTypeSerializer.Deserialize(ref reader, instance); - reader.ConsumeEndBaseOrEndObject(); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.GrainWithGuidCompoundKey @value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (@value is null || @value.GetType() == typeof(global::TestProject.GrainWithGuidCompoundKey)) - { - if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) - return; - writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); - Serialize(ref writer, @value); - writer.WriteEndObject(); - } - else - writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public global::TestProject.GrainWithGuidCompoundKey ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) - { - if (field.IsReference) - return ReferenceCodec.ReadReference(ref reader, field); - field.EnsureWireTypeTagDelimited(); - global::System.Type valueType = field.FieldType; - if (valueType is null || valueType == _codecFieldType) - { - var result = new global::TestProject.GrainWithGuidCompoundKey(); - ReferenceCodec.RecordObject(reader.Session, result); - Deserialize(ref reader, result); - return result; - } - - return reader.DeserializeUnexpectedType(ref field); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Copier_GrainWithGuidCompoundKey : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier - { - private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public global::TestProject.GrainWithGuidCompoundKey DeepCopy(global::TestProject.GrainWithGuidCompoundKey original, global::Orleans.Serialization.Cloning.CopyContext context) - { - if (context.TryGetCopy(original, out global::TestProject.GrainWithGuidCompoundKey existing)) - return existing; - if (original.GetType() != typeof(global::TestProject.GrainWithGuidCompoundKey)) - return context.DeepCopy(original); - var result = new global::TestProject.GrainWithGuidCompoundKey(); - context.RecordCopy(original, result); - DeepCopy(original, result, context); - return result; - } - - public Copier_GrainWithGuidCompoundKey(global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier) - { - this._baseTypeCopier = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeCopier); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void DeepCopy(global::TestProject.GrainWithGuidCompoundKey input, global::TestProject.GrainWithGuidCompoundKey output, global::Orleans.Serialization.Cloning.CopyContext context) - { - _baseTypeCopier.DeepCopy(input, output, context); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class Activator_GrainWithGuidCompoundKey : global::Orleans.Serialization.Activators.IActivator - { - public global::TestProject.GrainWithGuidCompoundKey Create() => new global::TestProject.GrainWithGuidCompoundKey(); - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Codec_Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A : global::Orleans.Serialization.Codecs.IFieldCodec - { - private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A); - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A instance) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A instance) - { - reader.ConsumeEndBaseOrEndObject(); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A @value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (@value is null) - { - ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); - return; - } - - ReferenceCodec.MarkValueField(writer.Session); - writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); - Serialize(ref writer, @value); - writer.WriteEndObject(); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) - { - if (field.IsReference) - return ReferenceCodec.ReadReference(ref reader, field); - field.EnsureWireTypeTagDelimited(); - var result = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A(); - ReferenceCodec.MarkValueField(reader.Session); - Deserialize(ref reader, result); - return result; - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Copier_Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A : global::Orleans.Serialization.Cloning.IDeepCopier - { - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A DeepCopy(OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A original, global::Orleans.Serialization.Cloning.CopyContext context) - { - if (original is null) - return null; - var result = new OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A(); - return result; - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Codec_GrainWithIntegerCompoundKey : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec - { - private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GrainWithIntegerCompoundKey); - private readonly global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer; - public Codec_GrainWithIntegerCompoundKey(global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer) - { - this._baseTypeSerializer = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeSerializer); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.GrainWithIntegerCompoundKey instance) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - _baseTypeSerializer.Serialize(ref writer, instance); - writer.WriteEndBase(); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.GrainWithIntegerCompoundKey instance) - { - _baseTypeSerializer.Deserialize(ref reader, instance); - reader.ConsumeEndBaseOrEndObject(); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.GrainWithIntegerCompoundKey @value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (@value is null || @value.GetType() == typeof(global::TestProject.GrainWithIntegerCompoundKey)) - { - if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) - return; - writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); - Serialize(ref writer, @value); - writer.WriteEndObject(); - } - else - writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public global::TestProject.GrainWithIntegerCompoundKey ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) - { - if (field.IsReference) - return ReferenceCodec.ReadReference(ref reader, field); - field.EnsureWireTypeTagDelimited(); - global::System.Type valueType = field.FieldType; - if (valueType is null || valueType == _codecFieldType) - { - var result = new global::TestProject.GrainWithIntegerCompoundKey(); - ReferenceCodec.RecordObject(reader.Session, result); - Deserialize(ref reader, result); - return result; - } - - return reader.DeserializeUnexpectedType(ref field); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Copier_GrainWithIntegerCompoundKey : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier - { - private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public global::TestProject.GrainWithIntegerCompoundKey DeepCopy(global::TestProject.GrainWithIntegerCompoundKey original, global::Orleans.Serialization.Cloning.CopyContext context) - { - if (context.TryGetCopy(original, out global::TestProject.GrainWithIntegerCompoundKey existing)) - return existing; - if (original.GetType() != typeof(global::TestProject.GrainWithIntegerCompoundKey)) - return context.DeepCopy(original); - var result = new global::TestProject.GrainWithIntegerCompoundKey(); - context.RecordCopy(original, result); - DeepCopy(original, result, context); - return result; - } - - public Copier_GrainWithIntegerCompoundKey(global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier) - { - this._baseTypeCopier = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeCopier); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void DeepCopy(global::TestProject.GrainWithIntegerCompoundKey input, global::TestProject.GrainWithIntegerCompoundKey output, global::Orleans.Serialization.Cloning.CopyContext context) - { - _baseTypeCopier.DeepCopy(input, output, context); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class Activator_GrainWithIntegerCompoundKey : global::Orleans.Serialization.Activators.IActivator - { - public global::TestProject.GrainWithIntegerCompoundKey Create() => new global::TestProject.GrainWithIntegerCompoundKey(); - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class RpcResponseFactories : global::Orleans.Serialization.SerializerContext - { - protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) - { - options.AddDefaultSerializerService(static provider => new RpcResponse_5C3A711CFactory(provider)); - options.AddDefaultSerializer(static provider => RpcResponse_5C3A711CFactory.Resolve(provider), static provider => RpcResponse_5C3A711CFactory.Resolve(provider)); - options.AddRawResponseReader(static provider => RpcResponse_5C3A711CFactory.Resolve(provider)); - options.AddDefaultSerializerService(static provider => new RpcResponse_6A3EE8F4Factory(provider)); - options.AddDefaultSerializer(static provider => RpcResponse_6A3EE8F4Factory.Resolve(provider), static provider => RpcResponse_6A3EE8F4Factory.Resolve(provider)); - options.AddRawResponseReader>(static provider => RpcResponse_6A3EE8F4Factory.Resolve(provider)); - options.AddDefaultSerializerService(static provider => new RpcResponse_AFB713E4Factory(provider)); - options.AddDefaultSerializer(static provider => RpcResponse_AFB713E4Factory.Resolve(provider), static provider => RpcResponse_AFB713E4Factory.Resolve(provider)); - options.AddRawResponseReader>(static provider => RpcResponse_AFB713E4Factory.Resolve(provider)); - options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); - options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); - options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); -#if NET5_0_OR_GREATER - if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) - return; - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); - options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); - options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider)); - options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response>)); - options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider)); - options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response>)); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); - options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); - options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.GuidCodec()); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); - options.AddAllowedType(typeof(global::System.Guid)); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); - options.AddAllowedType(typeof(global::System.Tuple)); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); - options.AddAllowedType(typeof(global::System.Tuple)); - options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.Int64Codec()); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); - options.AddAllowedType(typeof(long)); - options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); - options.AddAllowedType(typeof(string)); - options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); - options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); - options.AddDefaultSerializerService(static provider => new CompletedResponseActivator()); - options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); - options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); -#endif - } - - private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator - { - public CompletedResponseActivator() - { - } - - public global::Orleans.Serialization.Invocation.CompletedResponse Create() => global::Orleans.Serialization.Invocation.CompletedResponse.Instance; - } - - private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer - { - public ResponseFieldCodec() - { - } - } - - private sealed class ResponseFieldCopier : global::Orleans.Serialization.Cloning.IDeepCopier - { - public ResponseFieldCopier() - { - } - - [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] - public global::Orleans.Serialization.Invocation.Response DeepCopy(global::Orleans.Serialization.Invocation.Response input, global::Orleans.Serialization.Cloning.CopyContext context) - { - if (context is null) - throw new global::System.ArgumentNullException(nameof(context)); - if (input is global::Orleans.Serialization.Invocation.CompletedResponse or global::Orleans.Serialization.Invocation.ExceptionResponse) - return input; - return (global::Orleans.Serialization.Invocation.Response)global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context); - } - } - } - - internal sealed class RpcResponse_5C3A711C : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter - { - internal global::System.Guid Value; - private RpcResponse_5C3A711CFactory _factory; - public RpcResponse_5C3A711C() - { - } - - internal static RpcResponse_5C3A711C Rent(global::System.Guid value, RpcResponse_5C3A711CFactory factory) - { - var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); - result.Value = value; - result._factory = factory; - return result; - } - - public override object Result { get => Value; set => Value = (global::System.Guid)value; } - public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } - - public override global::System.Type GetSimpleResultType() => typeof(global::System.Guid); - public override T GetResult() - { - if (typeof(T) == typeof(global::System.Guid)) - return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); - return (T)(object)Value; - } - - public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (_factory is null) - throw new global::System.ObjectDisposedException(GetType().Name); - writer.WriteStartObject(0, null, typeof(global::System.Guid)); - global::Orleans.Serialization.Codecs.GuidCodec.WriteField(ref writer, 0, Value); - writer.WriteEndObject(); - } - - public override void Dispose() - { - if (_factory is null) - return; - Value = default; - _factory = null; - global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); - } - } - - internal sealed class RpcResponse_5C3A711CFactory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader - { - private readonly global::Orleans.Serialization.Codecs.GuidCodec _codec; - private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; - public bool IsSupported { get; } - - internal static RpcResponse_5C3A711CFactory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) - { - provider.GetCodec(); - provider.GetDeepCopier(); - provider.GetCodec>(); - provider.GetDeepCopier>(); - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); - } - - public RpcResponse_5C3A711CFactory(global::Orleans.Serialization.Serializers.ICodecProvider provider) - { - _codec = provider.GetCodec() as global::Orleans.Serialization.Codecs.GuidCodec; - _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; - var responseCodec = provider.GetCodec>(); - var responseCopier = provider.GetDeepCopier>(); - IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); - } - - internal global::Orleans.Serialization.Invocation.Response RentCopied(global::System.Guid value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) - { - return RpcResponse_5C3A711C.Rent(value, this); - } - - [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] - public RpcResponse_5C3A711C DeepCopy(RpcResponse_5C3A711C input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_5C3A711C.Rent(input.Value, this); - internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, global::System.Guid value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - writer.WriteStartObject(0, null, typeof(global::System.Guid)); - global::Orleans.Serialization.Codecs.GuidCodec.WriteField(ref writer, 0, value); - writer.WriteEndObject(); - } - - public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_5C3A711C)value).Value); - public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - private RpcResponse_5C3A711C ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) - { - field.EnsureWireTypeTagDelimited(); - var result = RpcResponse_5C3A711C.Rent(default, this); - try - { - reader.ReadFieldHeader(ref field); - if (!field.IsEndBaseOrEndObject) - { - result.Value = global::Orleans.Serialization.Codecs.GuidCodec.ReadValue(ref reader, field); - reader.ReadFieldHeader(ref field); - reader.ConsumeEndBaseOrEndObject(ref field); - } - - return result; - } - catch - { - result.Dispose(); - throw; - } - } - - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_5C3A711C value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (value is null) - { - global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); - return; - } - - global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); - writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); - global::Orleans.Serialization.Codecs.GuidCodec.WriteField(ref writer, 0, value.Value); - writer.WriteEndObject(); - } - - public RpcResponse_5C3A711C ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) - { - if (field.IsReference) - return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); - global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); - return ReadResult(ref reader, ref field); - } - } - - internal sealed class RpcResponse_6A3EE8F4 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter - { - internal global::System.Tuple Value; - private RpcResponse_6A3EE8F4Factory _factory; - public RpcResponse_6A3EE8F4() - { - } - - internal static RpcResponse_6A3EE8F4 Rent(global::System.Tuple value, RpcResponse_6A3EE8F4Factory factory) - { - var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); - result.Value = value; - result._factory = factory; - return result; - } - - public override object Result { get => Value; set => Value = (global::System.Tuple)value; } - public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } - - public override global::System.Type GetSimpleResultType() => typeof(global::System.Tuple); - public override T GetResult() - { - if (typeof(T) == typeof(global::System.Tuple)) - return global::System.Runtime.CompilerServices.Unsafe.As, T>(ref Value); - return (T)(object)Value; - } - - public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (_factory is null) - throw new global::System.ObjectDisposedException(GetType().Name); - _factory.WriteResult(ref writer, Value); - } - - public override void Dispose() - { - if (_factory is null) - return; - Value = default; - _factory = null; - global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); - } - } - - internal sealed class RpcResponse_6A3EE8F4Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader - { - private readonly global::Orleans.Serialization.Codecs.TupleCodec _codec; - private readonly global::Orleans.Serialization.Codecs.TupleCopier _copier; - public bool IsSupported { get; } - - internal static RpcResponse_6A3EE8F4Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) - { - provider.GetCodec>(); - provider.GetDeepCopier>(); - provider.GetCodec>>(); - provider.GetDeepCopier>>(); - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); - } - - public RpcResponse_6A3EE8F4Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) - { - _codec = provider.GetCodec>() as global::Orleans.Serialization.Codecs.TupleCodec; - _copier = provider.GetDeepCopier>() as global::Orleans.Serialization.Codecs.TupleCopier; - var responseCodec = provider.GetCodec>>(); - var responseCopier = provider.GetDeepCopier>>(); - IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec> || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec>>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Cloning.IDeepCopier>>); - } - - internal global::Orleans.Serialization.Invocation.Response RentCopied(global::System.Tuple value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) - { - return RpcResponse_6A3EE8F4.Rent(value, this); - } - - [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] - public RpcResponse_6A3EE8F4 DeepCopy(RpcResponse_6A3EE8F4 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_6A3EE8F4.Rent(input.Value, this); - internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, global::System.Tuple value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - writer.WriteStartObject(0, null, typeof(global::System.Tuple)); - if (value is not null) - { - _codec.WriteField(ref writer, 0, typeof(global::System.Tuple), value); - } - - writer.WriteEndObject(); - } - - public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_6A3EE8F4)value).Value); - public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - private RpcResponse_6A3EE8F4 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) - { - field.EnsureWireTypeTagDelimited(); - var result = RpcResponse_6A3EE8F4.Rent(default, this); - try - { - reader.ReadFieldHeader(ref field); - if (!field.IsEndBaseOrEndObject) - { - result.Value = _codec.ReadValue(ref reader, field); - reader.ReadFieldHeader(ref field); - reader.ConsumeEndBaseOrEndObject(ref field); - } - - return result; - } - catch - { - result.Dispose(); - throw; - } - } - - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_6A3EE8F4 value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (value is null) - { - global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); - return; - } - - global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); - writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response>)); - if (value.Value is not null) - { - _codec.WriteField(ref writer, 0, typeof(global::System.Tuple), value.Value); - } - - writer.WriteEndObject(); - } - - public RpcResponse_6A3EE8F4 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) - { - if (field.IsReference) - return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); - global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); - return ReadResult(ref reader, ref field); - } - } - - internal sealed class RpcResponse_AFB713E4 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter - { - internal global::System.Tuple Value; - private RpcResponse_AFB713E4Factory _factory; - public RpcResponse_AFB713E4() - { - } - - internal static RpcResponse_AFB713E4 Rent(global::System.Tuple value, RpcResponse_AFB713E4Factory factory) - { - var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); - result.Value = value; - result._factory = factory; - return result; - } - - public override object Result { get => Value; set => Value = (global::System.Tuple)value; } - public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } - - public override global::System.Type GetSimpleResultType() => typeof(global::System.Tuple); - public override T GetResult() - { - if (typeof(T) == typeof(global::System.Tuple)) - return global::System.Runtime.CompilerServices.Unsafe.As, T>(ref Value); - return (T)(object)Value; - } - - public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (_factory is null) - throw new global::System.ObjectDisposedException(GetType().Name); - _factory.WriteResult(ref writer, Value); - } - - public override void Dispose() - { - if (_factory is null) - return; - Value = default; - _factory = null; - global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); - } - } - - internal sealed class RpcResponse_AFB713E4Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader - { - private readonly global::Orleans.Serialization.Codecs.TupleCodec _codec; - private readonly global::Orleans.Serialization.Codecs.TupleCopier _copier; - public bool IsSupported { get; } - - internal static RpcResponse_AFB713E4Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) - { - provider.GetCodec>(); - provider.GetDeepCopier>(); - provider.GetCodec>>(); - provider.GetDeepCopier>>(); - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); - } - - public RpcResponse_AFB713E4Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) - { - _codec = provider.GetCodec>() as global::Orleans.Serialization.Codecs.TupleCodec; - _copier = provider.GetDeepCopier>() as global::Orleans.Serialization.Codecs.TupleCopier; - var responseCodec = provider.GetCodec>>(); - var responseCopier = provider.GetDeepCopier>>(); - IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec> || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec>>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Cloning.IDeepCopier>>); - } - - internal global::Orleans.Serialization.Invocation.Response RentCopied(global::System.Tuple value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) - { - return RpcResponse_AFB713E4.Rent(value, this); - } - - [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] - public RpcResponse_AFB713E4 DeepCopy(RpcResponse_AFB713E4 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_AFB713E4.Rent(input.Value, this); - internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, global::System.Tuple value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - writer.WriteStartObject(0, null, typeof(global::System.Tuple)); - if (value is not null) - { - _codec.WriteField(ref writer, 0, typeof(global::System.Tuple), value); - } - - writer.WriteEndObject(); - } - - public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_AFB713E4)value).Value); - public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - private RpcResponse_AFB713E4 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) - { - field.EnsureWireTypeTagDelimited(); - var result = RpcResponse_AFB713E4.Rent(default, this); - try - { - reader.ReadFieldHeader(ref field); - if (!field.IsEndBaseOrEndObject) - { - result.Value = _codec.ReadValue(ref reader, field); - reader.ReadFieldHeader(ref field); - reader.ConsumeEndBaseOrEndObject(ref field); - } - - return result; - } - catch - { - result.Dispose(); - throw; - } - } - - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_AFB713E4 value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (value is null) - { - global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); - return; - } - - global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); - writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response>)); - if (value.Value is not null) - { - _codec.WriteField(ref writer, 0, typeof(global::System.Tuple), value.Value); - } - - writer.WriteEndObject(); - } - - public RpcResponse_AFB713E4 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) - { - if (field.IsReference) - return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); - global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); - return ReadResult(ref reader, ref field); - } - } - - internal sealed class RpcResponse_9146C7E3 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter - { - internal string Value; - private RpcResponse_9146C7E3Factory _factory; - public RpcResponse_9146C7E3() - { - } - - internal static RpcResponse_9146C7E3 Rent(string value, RpcResponse_9146C7E3Factory factory) - { - var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); - result.Value = value; - result._factory = factory; - return result; - } - - public override object Result { get => Value; set => Value = (string)value; } - public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } - - public override global::System.Type GetSimpleResultType() => typeof(string); - public override T GetResult() - { - if (typeof(T) == typeof(string)) - return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); - return (T)(object)Value; - } - - public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (_factory is null) - throw new global::System.ObjectDisposedException(GetType().Name); - writer.WriteStartObject(0, null, typeof(string)); - if (Value is not null) - { - global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, Value); - } - - writer.WriteEndObject(); - } - - public override void Dispose() - { - if (_factory is null) - return; - Value = default; - _factory = null; - global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); - } - } - - internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader - { - private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; - private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; - public bool IsSupported { get; } - - internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) - { - provider.GetCodec(); - provider.GetDeepCopier(); - provider.GetCodec>(); - provider.GetDeepCopier>(); - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); - } - - public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) - { - _codec = provider.GetCodec() as global::Orleans.Serialization.Codecs.StringCodec; - _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; - var responseCodec = provider.GetCodec>(); - var responseCopier = provider.GetDeepCopier>(); - IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); - } - - internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) - { - return RpcResponse_9146C7E3.Rent(value, this); - } - - [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] - public RpcResponse_9146C7E3 DeepCopy(RpcResponse_9146C7E3 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_9146C7E3.Rent(input.Value, this); - internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, string value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - writer.WriteStartObject(0, null, typeof(string)); - if (value is not null) - { - global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value); - } - - writer.WriteEndObject(); - } - - public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); - public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) - { - field.EnsureWireTypeTagDelimited(); - var result = RpcResponse_9146C7E3.Rent(default, this); - try - { - reader.ReadFieldHeader(ref field); - if (!field.IsEndBaseOrEndObject) - { - result.Value = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, field); - reader.ReadFieldHeader(ref field); - reader.ConsumeEndBaseOrEndObject(ref field); - } - - return result; - } - catch - { - result.Dispose(); - throw; - } - } - - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_9146C7E3 value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (value is null) - { - global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); - return; - } - - global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); - writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); - if (value.Value is not null) - { - global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value.Value); - } - - writer.WriteEndObject(); - } - - public RpcResponse_9146C7E3 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) - { - if (field.IsReference) - return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); - global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); - return ReadResult(ref reader, ref field); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase - { - protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) - { - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E), typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_GrainWithGuidKey), typeof(global::TestProject.GrainWithGuidKey)); - config.AddBaseCodec(typeof(OrleansCodeGen.TestProject.Codec_GrainWithGuidKey), typeof(global::TestProject.GrainWithGuidKey)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IMyGrainWithStringKey_GrainReference_43570316), typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_GrainWithStringKey), typeof(global::TestProject.GrainWithStringKey)); - config.AddBaseCodec(typeof(OrleansCodeGen.TestProject.Codec_GrainWithStringKey), typeof(global::TestProject.GrainWithStringKey)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF), typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_GrainWithGuidCompoundKey), typeof(global::TestProject.GrainWithGuidCompoundKey)); - config.AddBaseCodec(typeof(OrleansCodeGen.TestProject.Codec_GrainWithGuidCompoundKey), typeof(global::TestProject.GrainWithGuidCompoundKey)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A), typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_GrainWithIntegerCompoundKey), typeof(global::TestProject.GrainWithIntegerCompoundKey)); - config.AddBaseCodec(typeof(OrleansCodeGen.TestProject.Codec_GrainWithIntegerCompoundKey), typeof(global::TestProject.GrainWithIntegerCompoundKey)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E), typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithGuidKey), typeof(global::TestProject.GrainWithGuidKey)); - config.AddBaseCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithGuidKey), typeof(global::TestProject.GrainWithGuidKey)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IMyGrainWithStringKey_GrainReference_43570316), typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithStringKey), typeof(global::TestProject.GrainWithStringKey)); - config.AddBaseCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithStringKey), typeof(global::TestProject.GrainWithStringKey)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF), typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithGuidCompoundKey), typeof(global::TestProject.GrainWithGuidCompoundKey)); - config.AddBaseCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithGuidCompoundKey), typeof(global::TestProject.GrainWithGuidCompoundKey)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A), typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithIntegerCompoundKey), typeof(global::TestProject.GrainWithIntegerCompoundKey)); - config.AddBaseCopier(typeof(OrleansCodeGen.TestProject.Copier_GrainWithIntegerCompoundKey), typeof(global::TestProject.GrainWithIntegerCompoundKey)); - config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IMyGrainWithGuidKey)); - config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IMyGrainWithStringKey)); - config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IMyGrainWithGuidCompoundKey)); - config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IMyGrainWithIntegerCompoundKey)); - config.AddInterface(typeof(global::TestProject.IMyGrainWithGuidKey)); - config.AddInterface(typeof(global::TestProject.IMyGrainWithStringKey)); - config.AddInterface(typeof(global::TestProject.IMyGrainWithGuidCompoundKey)); - config.AddInterface(typeof(global::TestProject.IMyGrainWithIntegerCompoundKey)); - config.AddInterfaceImplementation(typeof(global::TestProject.GrainWithGuidKey)); - config.AddInterfaceImplementation(typeof(global::TestProject.GrainWithStringKey)); - config.AddInterfaceImplementation(typeof(global::TestProject.GrainWithGuidCompoundKey)); - config.AddInterfaceImplementation(typeof(global::TestProject.GrainWithIntegerCompoundKey)); - config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_GrainWithGuidKey), typeof(global::TestProject.GrainWithGuidKey)); - config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_GrainWithStringKey), typeof(global::TestProject.GrainWithStringKey)); - config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_GrainWithGuidCompoundKey), typeof(global::TestProject.GrainWithGuidCompoundKey)); - config.AddActivator(typeof(OrleansCodeGen.TestProject.Activator_GrainWithIntegerCompoundKey), typeof(global::TestProject.GrainWithIntegerCompoundKey)); - var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); - var n2 = n1.GetOrAdd(typeof(global::Orleans.Runtime.GrainReference)); - var n3 = n2.GetOrAdd(typeof(global::TestProject.IMyGrainWithGuidKey)); - n3.Add("8F0FEC0E", typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E)); - var n5 = n2.GetOrAdd(typeof(global::TestProject.IMyGrainWithStringKey)); - n5.Add("43570316", typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithStringKey_GrainReference_43570316)); - var n7 = n2.GetOrAdd(typeof(global::TestProject.IMyGrainWithGuidCompoundKey)); - n7.Add("A9FEF7AF", typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF)); - var n9 = n2.GetOrAdd(typeof(global::TestProject.IMyGrainWithIntegerCompoundKey)); - n9.Add("9814021A", typeof(OrleansCodeGen.TestProject.Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A)); - } - } -} -#pragma warning restore \ No newline at end of file diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.verified.cs deleted file mode 100644 index 5ee9f1824df..00000000000 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.verified.cs +++ /dev/null @@ -1,557 +0,0 @@ -[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.RpcResponseFactories))] -#pragma warning disable -[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] -[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] -[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] -[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] -[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] -[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] -namespace OrleansCodeGen.TestProject -{ - using global::Orleans.Serialization.Codecs; - using global::Orleans.Serialization.GeneratedCodeHelpers; - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IGrainA), "11405B98")] - public sealed class Invokable_IGrainA_GrainReference_11405B98 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable - { - public string arg0; - global::TestProject.IGrainA _target; - private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IGrainA).GetMethod("MethodA", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new[] { typeof(string) }, null); - public override int GetArgumentCount() => 1; - public override string GetMethodName() => "MethodA"; - public override string GetInterfaceName() => "TestProject.IGrainA"; - public override string GetActivityName() => "IGrainA/MethodA"; - public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IGrainA); - public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; - public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = (global::TestProject.IGrainA)holder.GetTarget(); - public override object GetTarget() => _target; - public override void Dispose() - { - arg0 = default; - _target = default; - } - - public override object GetArgument(int index) - { - switch (index) - { - case 0: - return arg0; - default: - return OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); - } - } - - public override void SetArgument(int index, object value) - { - switch (index) - { - case 0: - arg0 = (string)value; - return; - default: - OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); - return; - } - } - - protected override global::System.Threading.Tasks.Task InvokeInner() => _target.MethodA(arg0); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) - { - try - { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); - if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); - string value = await InvokeInner(); - return factory.RentCopied(value, contexts); - } - catch (global::System.Exception exception) - { - return global::Orleans.Serialization.Invocation.Response.FromException(exception); - } - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class Proxy_IGrainA : global::Orleans.Runtime.GrainReference, global::TestProject.IGrainA - { - public Proxy_IGrainA(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) - { - } - - global::System.Threading.Tasks.Task global::TestProject.IGrainA.MethodA(string arg0) - { - var request = new OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98(); - request.arg0 = arg0; - return base.InvokeAsync(request).AsTask(); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IGrainB), "6B5D7809")] - public sealed class Invokable_IGrainB_GrainReference_6B5D7809 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable - { - public string arg0; - global::TestProject.IGrainB _target; - private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IGrainB).GetMethod("MethodB", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new[] { typeof(string) }, null); - public override int GetArgumentCount() => 1; - public override string GetMethodName() => "MethodB"; - public override string GetInterfaceName() => "TestProject.IGrainB"; - public override string GetActivityName() => "IGrainB/MethodB"; - public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IGrainB); - public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; - public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = (global::TestProject.IGrainB)holder.GetTarget(); - public override object GetTarget() => _target; - public override void Dispose() - { - arg0 = default; - _target = default; - } - - public override object GetArgument(int index) - { - switch (index) - { - case 0: - return arg0; - default: - return OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); - } - } - - public override void SetArgument(int index, object value) - { - switch (index) - { - case 0: - arg0 = (string)value; - return; - default: - OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); - return; - } - } - - protected override global::System.Threading.Tasks.Task InvokeInner() => _target.MethodB(arg0); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) - { - try - { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); - if (!factory.IsSupported) - return responseCopier.Copy(await Invoke()); - string value = await InvokeInner(); - return factory.RentCopied(value, contexts); - } - catch (global::System.Exception exception) - { - return global::Orleans.Serialization.Invocation.Response.FromException(exception); - } - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class Proxy_IGrainB : global::Orleans.Runtime.GrainReference, global::TestProject.IGrainB - { - public Proxy_IGrainB(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) - { - } - - global::System.Threading.Tasks.Task global::TestProject.IGrainB.MethodB(string arg0) - { - var request = new OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809(); - request.arg0 = arg0; - return base.InvokeAsync(request).AsTask(); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Codec_Invokable_IGrainA_GrainReference_11405B98 : global::Orleans.Serialization.Codecs.IFieldCodec - { - private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98); - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 instance) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.arg0); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 instance) - { - uint id = 0U; - global::Orleans.Serialization.WireProtocol.Field header = default; - while (true) - { - reader.ReadFieldHeader(ref header); - if (header.IsEndBaseOrEndObject) - break; - id += header.FieldIdDelta; - if (id == 0U) - { - instance.arg0 = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); - reader.ReadFieldHeader(ref header); - } - - reader.ConsumeEndBaseOrEndObject(ref header); - break; - } - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 @value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (@value is null) - { - ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); - return; - } - - ReferenceCodec.MarkValueField(writer.Session); - writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); - Serialize(ref writer, @value); - writer.WriteEndObject(); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) - { - if (field.IsReference) - return ReferenceCodec.ReadReference(ref reader, field); - field.EnsureWireTypeTagDelimited(); - var result = new OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98(); - ReferenceCodec.MarkValueField(reader.Session); - Deserialize(ref reader, result); - return result; - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Copier_Invokable_IGrainA_GrainReference_11405B98 : global::Orleans.Serialization.Cloning.IDeepCopier - { - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 DeepCopy(OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 original, global::Orleans.Serialization.Cloning.CopyContext context) - { - if (original is null) - return null; - var result = new OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98(); - result.arg0 = original.arg0; - return result; - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Codec_Invokable_IGrainB_GrainReference_6B5D7809 : global::Orleans.Serialization.Codecs.IFieldCodec - { - private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809); - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809 instance) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.arg0); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809 instance) - { - uint id = 0U; - global::Orleans.Serialization.WireProtocol.Field header = default; - while (true) - { - reader.ReadFieldHeader(ref header); - if (header.IsEndBaseOrEndObject) - break; - id += header.FieldIdDelta; - if (id == 0U) - { - instance.arg0 = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); - reader.ReadFieldHeader(ref header); - } - - reader.ConsumeEndBaseOrEndObject(ref header); - break; - } - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809 @value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (@value is null) - { - ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); - return; - } - - ReferenceCodec.MarkValueField(writer.Session); - writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); - Serialize(ref writer, @value); - writer.WriteEndObject(); - } - - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) - { - if (field.IsReference) - return ReferenceCodec.ReadReference(ref reader, field); - field.EnsureWireTypeTagDelimited(); - var result = new OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809(); - ReferenceCodec.MarkValueField(reader.Session); - Deserialize(ref reader, result); - return result; - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Copier_Invokable_IGrainB_GrainReference_6B5D7809 : global::Orleans.Serialization.Cloning.IDeepCopier - { - [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809 DeepCopy(OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809 original, global::Orleans.Serialization.Cloning.CopyContext context) - { - if (original is null) - return null; - var result = new OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809(); - result.arg0 = original.arg0; - return result; - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class RpcResponseFactories : global::Orleans.Serialization.SerializerContext - { - protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions options) - { - options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); - options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); - options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); -#if NET5_0_OR_GREATER - if (global::System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported) - return; - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider))); - options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider)); - options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); - options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); - options.AddAllowedType(typeof(string)); - options.AddDefaultSerializerService(static provider => new ResponseFieldCodec()); - options.AddDefaultSerializerService(static provider => new ResponseFieldCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); - options.AddDefaultSerializerService(static provider => new CompletedResponseActivator()); - options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.Orleans.Serialization.Invocation.Codec_CompletedResponse(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider))); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); - options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); -#endif - } - - private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator - { - public CompletedResponseActivator() - { - } - - public global::Orleans.Serialization.Invocation.CompletedResponse Create() => global::Orleans.Serialization.Invocation.CompletedResponse.Instance; - } - - private sealed class ResponseFieldCodec : global::Orleans.Serialization.Serializers.AbstractTypeSerializer - { - public ResponseFieldCodec() - { - } - } - - private sealed class ResponseFieldCopier : global::Orleans.Serialization.Cloning.IDeepCopier - { - public ResponseFieldCopier() - { - } - - [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] - public global::Orleans.Serialization.Invocation.Response DeepCopy(global::Orleans.Serialization.Invocation.Response input, global::Orleans.Serialization.Cloning.CopyContext context) - { - if (context is null) - throw new global::System.ArgumentNullException(nameof(context)); - if (input is global::Orleans.Serialization.Invocation.CompletedResponse or global::Orleans.Serialization.Invocation.ExceptionResponse) - return input; - return (global::Orleans.Serialization.Invocation.Response)global::Orleans.Serialization.Codecs.ObjectCopier.DeepCopy(input, context); - } - } - } - - internal sealed class RpcResponse_9146C7E3 : global::Orleans.Serialization.Invocation.Response, global::Orleans.Serialization.Invocation.IRawResponseWriter - { - internal string Value; - private RpcResponse_9146C7E3Factory _factory; - public RpcResponse_9146C7E3() - { - } - - internal static RpcResponse_9146C7E3 Rent(string value, RpcResponse_9146C7E3Factory factory) - { - var result = global::Orleans.Serialization.Invocation.ResponsePool.GetGenerated(); - result.Value = value; - result._factory = factory; - return result; - } - - public override object Result { get => Value; set => Value = (string)value; } - public override global::System.Exception Exception { get => null; set => throw new global::System.InvalidOperationException("Successful response holders contain result values."); } - - public override global::System.Type GetSimpleResultType() => typeof(string); - public override T GetResult() - { - if (typeof(T) == typeof(string)) - return global::System.Runtime.CompilerServices.Unsafe.As(ref Value); - return (T)(object)Value; - } - - public void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (_factory is null) - throw new global::System.ObjectDisposedException(GetType().Name); - writer.WriteStartObject(0, null, typeof(string)); - if (Value is not null) - { - global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, Value); - } - - writer.WriteEndObject(); - } - - public override void Dispose() - { - if (_factory is null) - return; - Value = default; - _factory = null; - global::Orleans.Serialization.Invocation.ResponsePool.ReturnGenerated(this); - } - } - - internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader - { - private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; - private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; - public bool IsSupported { get; } - - internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) - { - provider.GetCodec(); - provider.GetDeepCopier(); - provider.GetCodec>(); - provider.GetDeepCopier>(); - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); - } - - public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICodecProvider provider) - { - _codec = provider.GetCodec() as global::Orleans.Serialization.Codecs.StringCodec; - _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; - var responseCodec = provider.GetCodec>(); - var responseCopier = provider.GetDeepCopier>(); - IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); - } - - internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) - { - return RpcResponse_9146C7E3.Rent(value, this); - } - - [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("input")] - public RpcResponse_9146C7E3 DeepCopy(RpcResponse_9146C7E3 input, global::Orleans.Serialization.Cloning.CopyContext context) => input is null ? null : RpcResponse_9146C7E3.Rent(input.Value, this); - internal void WriteResult(ref global::Orleans.Serialization.Buffers.Writer writer, string value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - writer.WriteStartObject(0, null, typeof(string)); - if (value is not null) - { - global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value); - } - - writer.WriteEndObject(); - } - - public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); - public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) - { - field.EnsureWireTypeTagDelimited(); - var result = RpcResponse_9146C7E3.Rent(default, this); - try - { - reader.ReadFieldHeader(ref field); - if (!field.IsEndBaseOrEndObject) - { - result.Value = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, field); - reader.ReadFieldHeader(ref field); - reader.ConsumeEndBaseOrEndObject(ref field); - } - - return result; - } - catch - { - result.Dispose(); - throw; - } - } - - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, RpcResponse_9146C7E3 value) - where TBufferWriter : global::System.Buffers.IBufferWriter - { - if (value is null) - { - global::Orleans.Serialization.Codecs.ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); - return; - } - - global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(writer.Session); - writer.WriteStartObject(fieldIdDelta, expectedType, typeof(global::Orleans.Serialization.Invocation.Response)); - if (value.Value is not null) - { - global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0, value.Value); - } - - writer.WriteEndObject(); - } - - public RpcResponse_9146C7E3 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) - { - if (field.IsReference) - return global::Orleans.Serialization.Codecs.ReferenceCodec.ReadReference(ref reader, field); - global::Orleans.Serialization.Codecs.ReferenceCodec.MarkValueField(reader.Session); - return ReadResult(ref reader, ref field); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase - { - protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) - { - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IGrainA_GrainReference_11405B98), typeof(OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98)); - config.AddSerializer(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IGrainB_GrainReference_6B5D7809), typeof(OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IGrainA_GrainReference_11405B98), typeof(OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98)); - config.AddCopier(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IGrainB_GrainReference_6B5D7809), typeof(OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809)); - config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IGrainA)); - config.AddInterfaceProxy(typeof(OrleansCodeGen.TestProject.Proxy_IGrainB)); - config.AddInterface(typeof(global::TestProject.IGrainA)); - config.AddInterface(typeof(global::TestProject.IGrainB)); - config.AddInterfaceImplementation(typeof(global::TestProject.RealGrain)); - var n1 = config.CompoundTypeAliases.GetOrAdd("inv"); - var n2 = n1.GetOrAdd(typeof(global::Orleans.Runtime.GrainReference)); - var n3 = n2.GetOrAdd(typeof(global::TestProject.IGrainA)); - n3.Add("11405B98", typeof(OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98)); - var n5 = n2.GetOrAdd(typeof(global::TestProject.IGrainB)); - n5.Add("6B5D7809", typeof(OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809)); - } - } -} -#pragma warning restore \ No newline at end of file From aec5a5012324e023c39c5f20104a34739dd893f1 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Tue, 6 Oct 2026 13:50:32 -0700 Subject: [PATCH 37/54] fix(rpc): preserve host construction and clarify argument admission --- .../docs/implementation/serialization.md | 4 +-- src/Orleans.CodeGenerator/Resources.resx | 6 ++++ .../RpcResponseGenerator.cs | 22 +++++++++++-- .../RpcResponseHolderGenerator.cs | 2 +- .../Configuration/TypeManifestOptions.cs | 4 +++ .../Serializers/CodecProvider.cs | 13 ++++---- .../OrleansSourceGeneratorTests.cs | 33 +++++++++++++++++-- .../SelfWritingResponseOwnershipTests.cs | 25 ++++++++++++++ 8 files changed, 96 insertions(+), 13 deletions(-) diff --git a/docs/site/src/content/docs/implementation/serialization.md b/docs/site/src/content/docs/implementation/serialization.md index a9f4d5ce685..5062cae84a5 100644 --- a/docs/site/src/content/docs/implementation/serialization.md +++ b/docs/site/src/content/docs/implementation/serialization.md @@ -153,13 +153,13 @@ These supplemental registrations are defaults: explicit closed factory registrat Generated metadata also supplies static response factories for closed generated result models. These factories construct the model's canonical generated codec and copier using their actual constructor signatures, including closed generic generated activators and available generated activators from referenced assemblies. Source-known arrays, tuples, collections, and surrogate value serializers contribute their closed construction services. Interface contracts retain registered metadata dispatch and propagate their dependency requirements. Reference-assembly construction uses the producer's available constructor contracts and explicitly identified members. -Inferred defaults participate when their complete construction graph uses closed service factories and provider-owned services. Admission compares matching metadata implementation identities, and the closed factories supply the executable services. Constructor dependencies supplied by ordinary dependency-injection registrations select canonical metadata activation before the provider starts a serialization construction transaction. carries these dependency edges, preserving explicit registration priority, canonical service identity, and graph rollback. Default activation uses the existing reference- or value-type activator implementation, and custom activation retains its declared contract. Serializer contexts contribute their complete finite dependency graphs and validate each declared member shape. +Inferred defaults participate when their complete construction graph uses closed service factories and provider-owned services. Admission compares matching metadata implementation identities, and the closed factories supply the executable services. Automatic metadata construction retains ordinary dependency-injection resolution throughout its call chain. Closed default roots start their own construction transactions, and explicit factories participate in the declared transaction. Constructor dependencies supplied by ordinary dependency-injection registrations select canonical metadata activation before the provider starts a serialization construction transaction. carries these dependency edges, preserving explicit registration priority, canonical service identity, and graph rollback. Default activation uses the existing reference- or value-type activator implementation, and custom activation retains its declared contract. Serializer contexts contribute their complete finite dependency graphs and validate each declared member shape. The same collector closes source-known argument construction dependencies selected by generated proxy constructors. Reference and value tuples use their existing closed codec and copier implementations with their declared element services. Parameter-only one-way contracts register the required construction services while completion and result contracts also register their response graphs. `OrleansValidateRpcResponseFactories` enables compile-time validation of the response graph and defaults to the executable project's `PublishAot` setting. Diagnostic `ORLEANS0116` identifies an unresolved generic result, a custom return adapter requiring an explicit response contract, or a result dependency outside the supported finite graph. Applications with runtime-selected generic results register every permitted closed graph explicitly through and in a , and set `OrleansValidateRpcResponseFactories=false` for the project supplying that contract. A missing native response registration reports the closed response type and requested serialization service at lookup. -The combined inferred response graph supports up to 1,024 closed types. A larger union produces `ORLEANS0116` in both managed and native builds, even when each method's graph fits individually. The generator retains response holder declarations so the size diagnostic identifies the admission failure directly. +The combined inferred response graph supports up to 1,024 closed executable types. RPC admission counts the codec/copier construction graph; explicit serializer contexts also validate their separate metadata traversal limits. A larger union produces `ORLEANS0116` in both managed and native builds, even when each method's graph fits individually. The generator retains response holder declarations so the size diagnostic identifies the admission failure directly. Argument admission failures use an argument-specific `ORLEANS0116` message directing the application to register the argument's closed codec, copier, and serialization service dependencies, including for one-way methods. Dictionary results and dictionary members require an explicit closed registration which preserves the application's comparer contract. A dictionary's comparer is selected per value, so the method's declared result type alone supplies the key/value shape while the registration supplies comparer serialization and copying. diff --git a/src/Orleans.CodeGenerator/Resources.resx b/src/Orleans.CodeGenerator/Resources.resx index 7e9f55238ac..c532bc9a30b 100644 --- a/src/Orleans.CodeGenerator/Resources.resx +++ b/src/Orleans.CodeGenerator/Resources.resx @@ -150,4 +150,10 @@ RPC method '{0}' requires response result '{1}': {2}; register the closed Response<TResult> types in a serializer context for this contract + + RPC argument requires a closed construction graph + + + RPC method '{0}' requires a closed construction graph for argument type '{1}': {2}; register the argument's closed codec, copier, and required serialization services in a serializer context for this contract + \ No newline at end of file diff --git a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs index 2e70fc575c2..6581da98844 100644 --- a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs +++ b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs @@ -19,6 +19,14 @@ internal static class RpcResponseGenerator DiagnosticSeverity.Error, isEnabledByDefault: true); + private static readonly DiagnosticDescriptor UnsupportedArgument = new( + DiagnosticRuleId.UnsupportedRpcResponseFactory, + new LocalizableResourceString("UnsupportedRpcArgumentFactoryTitle", Resources.ResourceManager, typeof(Resources)), + new LocalizableResourceString("UnsupportedRpcArgumentFactoryMessageFormat", Resources.ResourceManager, typeof(Resources)), + "Usage", + DiagnosticSeverity.Error, + isEnabledByDefault: true); + internal static ImmutableArray Generate( Compilation compilation, ImmutableArray proxies, @@ -130,7 +138,7 @@ internal static ImmutableArray Generate( var method = entry.Value; if (RpcResponseHolderGenerator.TryDescribe(services, resultType, out var holderCodec, out var holderCopier)) responseHolders.Add(resultType, (holderCodec, holderCopier)); - if (SerializerFactoryGenerator.TryCreate(services, [responseDefinition.Construct(resultType)], cancellationToken, out var candidate, out var failure)) + if (SerializerFactoryGenerator.TryCreate(services, [responseDefinition.Construct(resultType)], cancellationToken, out var candidate, out var failure, useDefaultFactories: true)) { var dictionary = candidate.Registrations.Keys.OfType() .FirstOrDefault(type => SymbolEqualityComparer.Default.Equals(type.OriginalDefinition, dictionaryDefinition)); @@ -172,7 +180,7 @@ internal static ImmutableArray Generate( } else { - Report(argument.Value, argument.Key, failure?.Reason ?? "the argument graph requires an explicit closed construction contract"); + ReportArgument(argument.Value, argument.Key, failure?.Reason ?? "the argument graph requires an explicit closed construction contract"); } } @@ -287,6 +295,16 @@ void Report(IMethodSymbol method, ITypeSymbol resultType, string reason) output.Add(SourceOutputResult.FromDiagnostic(Diagnostic.Create( UnsupportedResponse, method.Locations.FirstOrDefault(), method.ToDisplayString(), resultType.ToDisplayString(), reason))); } + + } + + void ReportArgument(IMethodSymbol method, ITypeSymbol argumentType, string reason) + { + if (options.ValidateRpcResponseFactories) + { + output.Add(SourceOutputResult.FromDiagnostic(Diagnostic.Create( + UnsupportedArgument, method.Locations.FirstOrDefault(), method.ToDisplayString(), argumentType.ToDisplayString(), reason))); + } } } diff --git a/src/Orleans.CodeGenerator/RpcResponseHolderGenerator.cs b/src/Orleans.CodeGenerator/RpcResponseHolderGenerator.cs index ec27be40d5f..9821d4a4478 100644 --- a/src/Orleans.CodeGenerator/RpcResponseHolderGenerator.cs +++ b/src/Orleans.CodeGenerator/RpcResponseHolderGenerator.cs @@ -73,7 +73,7 @@ internal static bool TryDescribe(IGeneratorServices services, ITypeSymbol result { codec = copier = ""; if (ContainsParameter(resultType)) return false; - if (SerializerFactoryGenerator.TryCreate(services, [resultType], CancellationToken.None, out var graph, out _)) + if (SerializerFactoryGenerator.TryCreate(services, [resultType], CancellationToken.None, out var graph, out _, useDefaultFactories: true)) { if (graph.Registrations.Keys.OfType().Any(type => SymbolEqualityComparer.Default.Equals(type.OriginalDefinition, services.Compilation.GetTypeByMetadataName("System.Collections.Generic.Dictionary`2")))) diff --git a/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs b/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs index fa0859be30a..db428b62b3a 100644 --- a/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs +++ b/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs @@ -47,6 +47,8 @@ public sealed class TypeManifestOptions internal Dictionary> CodecFactories { get; } = new(); internal Dictionary> CopierFactories { get; } = new(); + internal Dictionary CodecFactoryServices { get; } = new(); + internal Dictionary CopierFactoryServices { get; } = new(); internal Dictionary> SerializerServiceFactories { get; } = new(); internal Dictionary DefaultSerializerContracts { get; } = new(); internal Dictionary DefaultCodecFactoryContracts { get; } = new(); @@ -145,6 +147,8 @@ private void RegisterSerializerFactories( Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null!, provider)); CopierFactories.TryAdd(typeof(T), static provider => Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null!, provider)); + CodecFactoryServices.TryAdd(typeof(T), typeof(IFieldCodec)); + CopierFactoryServices.TryAdd(typeof(T), typeof(IDeepCopier)); AddSerializerServiceFactory(typeof(IFieldCodec), codecFactory, isDefault); AddSerializerServiceFactory(typeof(IDeepCopier), copierFactory, isDefault); if (DefaultSerializerContracts.TryGetValue(typeof(IFieldCodec), out var codecContract)) diff --git a/src/Orleans.Serialization/Serializers/CodecProvider.cs b/src/Orleans.Serialization/Serializers/CodecProvider.cs index 6d8f50a8388..9ede7e33a1d 100644 --- a/src/Orleans.Serialization/Serializers/CodecProvider.cs +++ b/src/Orleans.Serialization/Serializers/CodecProvider.cs @@ -671,16 +671,17 @@ private object ActivateService(Type type, object[]? constructorArguments) } private bool IsDefaultCodecEligible(Type type) - => !_manifest.DefaultCodecFactoryContracts.TryGetValue(type, out var contract) - || IsDefaultContractEligible(contract, []); + => IsDefaultServiceEligible(_manifest.CodecFactoryServices[type]); private bool IsDefaultCopierEligible(Type type) - => !_manifest.DefaultCopierFactoryContracts.TryGetValue(type, out var contract) - || IsDefaultContractEligible(contract, []); + => IsDefaultServiceEligible(_manifest.CopierFactoryServices[type]); + // Inferred defaults preserve an automatic caller's DI boundary instead of starting a transaction inside it. private bool IsDefaultServiceEligible(Type service) - => !_manifest.DefaultSerializerContracts.TryGetValue(service, out var contract) - || IsDefaultContractEligible(contract, []); + => !(_manifest.IsDefaultSerializerService(service) + && OrleansGeneratedCodeHelper.GetConstructionScope(this) is { IsPending: false }) + && (!_manifest.DefaultSerializerContracts.TryGetValue(service, out var contract) + || IsDefaultContractEligible(contract, [])); private bool IsProviderService(Type serviceType) => serviceType != typeof(object) diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index 34d8d30d02c..737e8d325b9 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -2361,6 +2361,35 @@ public interface IResponses : IGrainWithIntegerKey { {{method}} } Assert.NotEqual(Location.None, diagnostic.Location); } + [Theory] + [InlineData("void", "System.IO.Stream")] + [InlineData("Task", "System.IO.Stream")] + [InlineData("void", "System.Collections.Generic.Dictionary")] + [InlineData("Task", "System.Collections.Generic.Dictionary")] + public async Task RpcArgumentFactoriesDiagnoseRequiredArgumentConstructionGraph(string returnType, string argumentType) + { + var compilation = await CreateCompilation($$""" + using Orleans; + using System.Threading.Tasks; + namespace TestProject; + public interface IArguments : IGrainWithIntegerKey + { + {{returnType}} Send({{argumentType}} value); + } + """); + var result = RunSourceGenerator(compilation, new Dictionary { ["build_property.publishaot"] = "true" }); + var diagnostic = Assert.Single(result.Diagnostics); + + Assert.Equal("ORLEANS0116", diagnostic.Id); + Assert.Equal(DiagnosticSeverity.Error, diagnostic.Severity); + Assert.Contains("argument type", diagnostic.GetMessage()); + Assert.Contains(argumentType, diagnostic.GetMessage()); + Assert.Contains("argument's closed codec, copier, and required serialization services", diagnostic.GetMessage()); + Assert.DoesNotContain("response result", diagnostic.GetMessage()); + Assert.DoesNotContain("Response", diagnostic.GetMessage()); + Assert.NotEqual(Location.None, diagnostic.Location); + } + [Theory] [InlineData("System.Collections.Generic.Dictionary")] [InlineData("System.Collections.Generic.List>")] @@ -2452,14 +2481,14 @@ public interface IContract : IGrainWithIntegerKey { var resultType = compilation.GetTypeByMetadataName($"CombinedGraph.{name}")!; Assert.True(SerializerFactoryGenerator.TryCreate(services, [response.Construct(resultType)], - TestContext.Current.CancellationToken, out var individual, out var failure), failure?.Reason); + TestContext.Current.CancellationToken, out var individual, out var failure, useDefaultFactories: true), failure?.Reason); Assert.Equal(membersPerResult + 2, individual.Registrations.Count); } if (membersPerResult == 510) { Assert.True(SerializerFactoryGenerator.TryCreate(services, new[] { "First", "Second" }.Select(name => response.Construct(compilation.GetTypeByMetadataName($"CombinedGraph.{name}")!)), - TestContext.Current.CancellationToken, out var combined, out var failure), failure?.Reason); + TestContext.Current.CancellationToken, out var combined, out var failure, useDefaultFactories: true), failure?.Reason); Assert.Equal(1024, combined.Registrations.Count); } var result = RunSourceGenerator(compilation, new Dictionary diff --git a/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs index 9094e7805f7..cc3c8bccc78 100644 --- a/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs +++ b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs @@ -36,6 +36,31 @@ namespace UnitTests.Serialization; [TestCategory("BVT"), TestCategory("Serialization")] public sealed class SelfWritingResponseOwnershipTests { + [Fact] + public void MigrationArgumentCodec_RetainsOrdinaryHostDependencyResolution() + { + using var services = new ServiceCollection().AddSerializer().BuildServiceProvider(); + var provider = services.GetRequiredService(); + var codec = provider.GetCodec>(); + var activator = provider.GetActivator(); + using var migration = activator.Create(); + var sessions = services.GetRequiredService(); + + Assert.Same(sessions, migration._sessionPool); + Assert.Same(codec, provider.GetCodec>()); + Assert.False(provider.IsConstructionPending); + using var session = sessions.GetSession(); + var output = new ArrayBufferWriter(); + var writer = Writer.Create(output, session); + var source = new List + { + new() { GrainId = GrainId.Create("migration-test", "target"), MigrationContext = migration } + }; + codec.WriteField(ref writer, 0, typeof(List), source); + writer.Commit(); + Assert.True(output.WrittenCount > 0); + } + [Theory] [InlineData(false, false, "Distinct")] [InlineData(false, true, "Distinct")] From 4d856aecf47025ee3344994779a762d93080766c Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Tue, 6 Oct 2026 14:12:03 -0700 Subject: [PATCH 38/54] chore(api): regenerate all admitted RPC response surfaces --- src/api/Orleans.Streaming/Orleans.Streaming.cs | 8 ++++++-- .../Orleans.Transactions.TestKit.Base.cs | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/api/Orleans.Streaming/Orleans.Streaming.cs b/src/api/Orleans.Streaming/Orleans.Streaming.cs index 609eca4357d..0a98960d7f0 100644 --- a/src/api/Orleans.Streaming/Orleans.Streaming.cs +++ b/src/api/Orleans.Streaming/Orleans.Streaming.cs @@ -3407,7 +3407,7 @@ public void DeepCopy(global::Orleans.Streams.StreamSubscriptionHandle input, [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::Orleans.CompoundTypeAlias(new[] { "inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::Orleans.Streams.IStreamCheckpointerGrain), "7AB50A87" })] - public sealed partial class Invokable_IStreamCheckpointerGrain_GrainReference_7AB50A87 : global::Orleans.Runtime.Request + public sealed partial class Invokable_IStreamCheckpointerGrain_GrainReference_7AB50A87 : global::Orleans.Runtime.Request, global::Orleans.Serialization.Invocation.IResponseInvokable { public string arg0; public string arg1; @@ -3436,6 +3436,8 @@ public override void Dispose() { } protected override System.Threading.Tasks.ValueTask InvokeInner() { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + public override void SetArgument(int index, object value) { } public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) { } @@ -3447,7 +3449,7 @@ public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetH [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::Orleans.CompoundTypeAlias(new[] { "inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::Orleans.Streams.IStreamCheckpointerGrain), "DE3727A1" })] - public sealed partial class Invokable_IStreamCheckpointerGrain_GrainReference_DE3727A1 : global::Orleans.Runtime.Request + public sealed partial class Invokable_IStreamCheckpointerGrain_GrainReference_DE3727A1 : global::Orleans.Runtime.Request, global::Orleans.Serialization.Invocation.IResponseInvokable { public System.Threading.CancellationToken arg0; public override bool IsCancellable { get { throw null; } } @@ -3474,6 +3476,8 @@ public override void Dispose() { } protected override System.Threading.Tasks.ValueTask InvokeInner() { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + public override void SetArgument(int index, object value) { } public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) { } diff --git a/src/api/Orleans.Transactions.TestKit.Base/Orleans.Transactions.TestKit.Base.cs b/src/api/Orleans.Transactions.TestKit.Base/Orleans.Transactions.TestKit.Base.cs index a679e6bc542..5f4249bf6b1 100644 --- a/src/api/Orleans.Transactions.TestKit.Base/Orleans.Transactions.TestKit.Base.cs +++ b/src/api/Orleans.Transactions.TestKit.Base/Orleans.Transactions.TestKit.Base.cs @@ -2749,7 +2749,7 @@ public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetH [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::Orleans.CompoundTypeAlias(new[] { "inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::Orleans.Transactions.TestKit.INoAttributionGrain), "BC7E3A79" })] - public sealed partial class Invokable_INoAttributionGrain_GrainReference_BC7E3A79 : global::Orleans.Runtime.TaskRequest[]> + public sealed partial class Invokable_INoAttributionGrain_GrainReference_BC7E3A79 : global::Orleans.Runtime.TaskRequest[]>, global::Orleans.Serialization.Invocation.IResponseInvokable { public int arg0; public System.Collections.Generic.List[] arg1; @@ -2773,6 +2773,8 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task[]> InvokeInner() { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + public override void SetArgument(int index, object value) { } public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) { } From 4df46fba1e7dc325ee4e8cddcc5eed21f82acd62 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Tue, 6 Oct 2026 15:40:04 -0700 Subject: [PATCH 39/54] fix(serialization): preserve converter priority for inferred defaults --- .../Serializers/CodecProvider.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Orleans.Serialization/Serializers/CodecProvider.cs b/src/Orleans.Serialization/Serializers/CodecProvider.cs index 9ede7e33a1d..572196f1274 100644 --- a/src/Orleans.Serialization/Serializers/CodecProvider.cs +++ b/src/Orleans.Serialization/Serializers/CodecProvider.cs @@ -693,11 +693,19 @@ private bool IsDefaultContractEligible(TypeManifestOptions.DefaultSerializerCont if (!_manifest.IsDefaultSerializerService(contract.Service) || !visited.Add(contract.Service)) return true; var role = contract.Service.IsConstructedGenericType ? contract.Service.GetGenericTypeDefinition() : null; var target = role is null ? contract.Service : contract.Service.GenericTypeArguments[0]; - if (role is not null && contract.Implementation is { } implementation - && TrySelectImplementation(role, target, target.IsConstructedGenericType ? target.GetGenericTypeDefinition() : target, - out var selected, out _, materializeImplementation: false) - && !MatchesDefaultImplementation(selected, implementation, contract.CompatibleImplementation, target)) - return false; + if (role is not null && contract.Implementation is { } implementation) + { + var searchType = target.IsConstructedGenericType ? target.GetGenericTypeDefinition() : target; + if (TrySelectImplementation(role, target, searchType, out var selected, out _, materializeImplementation: false)) + { + if (!MatchesDefaultImplementation(selected, implementation, contract.CompatibleImplementation, target)) return false; + } + else if ((role == typeof(IFieldCodec<>) || role == typeof(IDeepCopier<>)) + && TrySelectImplementation(typeof(IConverter<,>), target, searchType, out _, out _, materializeImplementation: false)) + { + return false; + } + } foreach (var dependency in contract.Dependencies) { if (_manifest.DefaultSerializerContracts.TryGetValue(dependency, out var required)) From 845d3aedfe19f053a7f3f3a08ea267c65fc9a5b7 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Tue, 6 Oct 2026 15:54:15 -0700 Subject: [PATCH 40/54] fix(codegen): bind metadata-only RPC compilations --- .../RpcResponseGenerator.cs | 9 ++- .../OrleansSourceGeneratorTests.cs | 63 +++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs index 6581da98844..10c829c3843 100644 --- a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs +++ b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs @@ -39,13 +39,20 @@ internal static ImmutableArray Generate( return []; } + var bindingTree = compilation.SyntaxTrees.FirstOrDefault(); + if (bindingTree is null) + { + bindingTree = CSharpSyntaxTree.Create(SyntaxFactory.CompilationUnit()); + compilation = compilation.AddSyntaxTrees(bindingTree); + } + var services = new GeneratorServices(compilation, SourceGeneratorOptionsParser.CreateCodeGeneratorOptions(options)); var responseDefinition = compilation.GetTypeByMetadataName("Orleans.Serialization.Invocation.Response`1")!; var resolver = new TypeSymbolResolver(compilation); var proxyContext = new ProxyGenerationContext(compilation, SourceGeneratorOptionsParser.CreateCodeGeneratorOptions(options), responseNames); ProxySourceOutputGenerator.PopulateProxyInterfaces(proxyContext, resolver, proxies.Select(static proxy => proxy.ProxyInterface).ToImmutableArray(), cancellationToken); - var binding = compilation.GetSemanticModel(compilation.SyntaxTrees.First()); + var binding = compilation.GetSemanticModel(bindingTree); var results = new Dictionary(SymbolEqualityComparer.Default); var arguments = new Dictionary(SymbolEqualityComparer.Default); var hasCompletionMethods = false; diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index 737e8d325b9..4de3e02bfe6 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -3,6 +3,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.Extensions.DependencyInjection; using Orleans.CodeGenerator.Diagnostics; +using Orleans.CodeGenerator.Model; using Orleans.Serialization; namespace Orleans.CodeGenerator.Tests; @@ -2284,6 +2285,68 @@ public partial class Context : Orleans.Serialization.SerializerContext { } Assert.DoesNotContain("RequireExplicitTypeRegistration", source); } + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task RpcResponseFactoriesGenerateForMetadataOnlyCompilation(bool referenceAssembly) + { + var library = await CreateCompilation(""" + using Orleans; + using System.Collections.Generic; + using System.Threading.Tasks; + namespace MetadataContracts; + public interface IResponses : IGrainWithIntegerKey + { + Task Reference(List values); + ValueTask Array(); + Task Done(); + } + """, "MetadataContracts"); + using var image = new System.IO.MemoryStream(); + var emitted = library.Emit(image, + options: new Microsoft.CodeAnalysis.Emit.EmitOptions(metadataOnly: referenceAssembly, includePrivateMembers: !referenceAssembly), + cancellationToken: TestContext.Current.CancellationToken); + Assert.True(emitted.Success, string.Join(Environment.NewLine, emitted.Diagnostics)); + + var compilation = (await CreateCompilation(string.Empty, "MetadataConsumer")) + .AddReferences( + MetadataReference.CreateFromImage(image.ToArray()), + MetadataReference.CreateFromFile(typeof(Microsoft.Extensions.Options.IConfigureOptions<>).Assembly.Location)); + var metadataCompilation = compilation.RemoveAllSyntaxTrees(); + Assert.Empty(metadataCompilation.SyntaxTrees); + var interfaceType = metadataCompilation.GetTypeByMetadataName("MetadataContracts.IResponses"); + Assert.NotNull(interfaceType); + var model = ModelExtractor.ExtractProxyInterfaceModel(interfaceType, metadataCompilation, TestContext.Current.CancellationToken); + Assert.NotNull(model); + var options = SourceGeneratorOptionsParser.ParseOptions(TestCompilationHelper.CreateOptionsProvider( + new Dictionary { ["build_property.publishaot"] = "true" }).GlobalOptions); + var names = RpcResponseHolderGenerator.GetNames(metadataCompilation, [model], options, TestContext.Current.CancellationToken); + var preparation = ProxySourceOutputGenerator.CreateProxyOutputPreparation( + metadataCompilation, [model], options, names, TestContext.Current.CancellationToken); + Assert.Empty(preparation.Diagnostics); + + var responses = RpcResponseGenerator.Generate( + metadataCompilation, preparation.ProxyOutputModels, options, names, TestContext.Current.CancellationToken); + var baseline = RpcResponseGenerator.Generate( + compilation, preparation.ProxyOutputModels, options, names, TestContext.Current.CancellationToken); + Assert.Equal(baseline, responses); + Assert.NotEmpty(responses); + Assert.All(responses, static output => Assert.Null(output.Diagnostic)); + var responseSource = Assert.Single(responses, static output => + output.SourceEntry is { HintName: var hintName } && hintName.EndsWith(".orleans.rpcresponses.g.cs", StringComparison.Ordinal)) + .SourceEntry!.Value.Source; + Assert.Contains("ListCopier", responseSource); + Assert.Contains("AddRawResponseReader", responseSource); + Assert.Contains("AddRawResponseReader", responseSource); + Assert.Contains("CompletedResponse", responseSource); + + var sources = preparation.SourceOutputs.Concat(responses); + var outputCompilation = metadataCompilation.AddSyntaxTrees(sources.Select(static output => + CSharpSyntaxTree.ParseText(output.SourceEntry!.Value.Source, path: output.SourceEntry.Value.HintName))); + Assert.Empty(outputCompilation.GetDiagnostics(TestContext.Current.CancellationToken) + .Where(static diagnostic => diagnostic.Severity == DiagnosticSeverity.Error)); + } + [Fact] public async Task RpcResponseFactoriesGenerateConcreteClosedGraph() { From 586a0839a9d1984a7af30acb3a1e495485c1cff2 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Tue, 6 Oct 2026 16:39:45 -0700 Subject: [PATCH 41/54] fix(rpc): honor explicit child factories Record canonical service aliases independently of registration order and declare the exact services consumed by inferred factories. Preserve contract-aware parents and custom metadata precedence. Emit RPC registrations unconditionally and retain managed/native/framework-symbol source parity. --- .../docs/implementation/serialization.md | 2 +- .../RpcResponseGenerator.cs | 2 - .../SerializerFactoryGenerator.cs | 53 ++++--- .../Configuration/TypeManifestOptions.cs | 14 ++ .../Serializers/CodecProvider.cs | 62 ++++++--- .../OrleansSourceGeneratorTests.cs | 16 +++ ...ests.TestBasicGrain.DotNet10_0.verified.cs | 8 +- ...Tests.TestBasicGrain.DotNet8_0.verified.cs | 8 +- ...rializersAnnotation.DotNet10_0.verified.cs | 8 +- ...erializersAnnotation.DotNet8_0.verified.cs | 8 +- ...stGrainComplexGrain.DotNet10_0.verified.cs | 18 ++- ...estGrainComplexGrain.DotNet8_0.verified.cs | 18 ++- ...thInvokableBaseType.DotNet10_0.verified.cs | 8 +- ...ithInvokableBaseType.DotNet8_0.verified.cs | 8 +- ...WithResponseTimeout.DotNet10_0.verified.cs | 8 +- ...dWithResponseTimeout.DotNet8_0.verified.cs | 8 +- ...thDifferentKeyTypes.DotNet10_0.verified.cs | 38 +++--- ...ithDifferentKeyTypes.DotNet8_0.verified.cs | 38 +++--- ...hMultipleInterfaces.DotNet10_0.verified.cs | 8 +- ...thMultipleInterfaces.DotNet8_0.verified.cs | 8 +- .../DefaultFactoryDependencyAdmissionTests.cs | 32 +++++ .../RpcResponseTests.cs | 129 +++++++++++++++++- 22 files changed, 349 insertions(+), 153 deletions(-) diff --git a/docs/site/src/content/docs/implementation/serialization.md b/docs/site/src/content/docs/implementation/serialization.md index 5062cae84a5..1f883925b9d 100644 --- a/docs/site/src/content/docs/implementation/serialization.md +++ b/docs/site/src/content/docs/implementation/serialization.md @@ -149,7 +149,7 @@ Completed response transport uses the existing generated codec and its canonical The finite response graph supplies successful typed results and completed-response transport, plus immutable exception-envelope copying. Exception transport uses the selected codec and the exception and `Data` value dependencies. Closed factories provide statically compiled implementations; registered metadata and the existing exception codecs provide the remaining supported serialization contracts. -These supplemental registrations are defaults: explicit closed factory registrations take precedence in either configuration order. Generated factories and registered metadata use one resolution pipeline, with closed services selected first. Direct-holder factories and raw-reader registrations bind the selected provider implementations in both JIT and native execution. Custom application codec/copier selection uses the compatibility invocation and serialization path. +These supplemental registrations are emitted unconditionally and are defaults: explicit closed factory registrations take precedence in either configuration order. Inferred parent factories preserve each child's selected service: replacing a child contract selects parent construction through that contract, while parents consuming the explicit contract directly remain eligible. This applies throughout the dependency graph, including concrete canonical services and their codec, copier, and activator aliases. Generated factories and registered metadata use one resolution pipeline, with closed services selected first. Direct-holder factories and raw-reader registrations bind the selected provider implementations in both JIT and native execution. Custom application codec/copier selection uses the compatibility invocation and serialization path. Generated metadata also supplies static response factories for closed generated result models. These factories construct the model's canonical generated codec and copier using their actual constructor signatures, including closed generic generated activators and available generated activators from referenced assemblies. Source-known arrays, tuples, collections, and surrogate value serializers contribute their closed construction services. Interface contracts retain registered metadata dispatch and propagate their dependency requirements. Reference-assembly construction uses the producer's available constructor contracts and explicitly identified members. diff --git a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs index 10c829c3843..2e389f581f2 100644 --- a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs +++ b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs @@ -226,7 +226,6 @@ internal static ImmutableArray Generate( source.AppendLine($"options.AddDefaultSerializer<{name}>(static provider => {resolve}, static provider => {resolve});"); source.AppendLine($"options.AddRawResponseReader<{type}>(static provider => {resolve});"); } - source.AppendLine("#if NET5_0_OR_GREATER"); if (graph is not null) { source.AppendLine(graph.ConfigurationStatements); @@ -256,7 +255,6 @@ internal static ImmutableArray Generate( source.AppendLine("options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse));"); } - source.AppendLine("#endif"); source.AppendLine("}"); source.AppendLine("private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator"); source.AppendLine("{"); diff --git a/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs b/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs index c65204832db..de9811e6abf 100644 --- a/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs +++ b/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs @@ -248,14 +248,14 @@ internal sealed record Failure(ITypeSymbol Type, string Reason); result.Append("options.AddDefaultSerializerService<").Append(codec).Append(">(static provider => new ") .Append(codec).Append("(caller => ").Append(Resolve(registration.Codec, "caller")) - .Append("), dependencies: ").Append(DefaultDependencyServices([type], codec: true)).AppendLine(");"); + .Append("), dependencies: ").Append(DefaultServiceDependencies([registration.Codec])).AppendLine(");"); result.Append("options.AddDefaultSerializerService<").Append(copier).Append(">(static provider => new ") .Append(copier).Append("(caller => ").Append(Resolve(registration.Copier, "caller")) - .Append("), dependencies: ").Append(DefaultDependencyServices([type], codec: false)).AppendLine(");"); + .Append("), dependencies: ").Append(DefaultServiceDependencies([registration.Copier])).AppendLine(");"); result.Append("options.AddDefaultSerializer<").Append(Name(responseType)).Append(", ").Append(codec).Append(", ").Append(copier).Append(">(static provider => ") .Append(Resolve(codec)).Append(", static provider => ").Append(Resolve(copier)) - .Append(", codecDependencies: ").Append(DefaultDependencyServices([type], codec: true)) - .Append(", copierDependencies: ").Append(DefaultDependencyServices([type], codec: false)).AppendLine(");"); + .Append(", codecDependencies: ").Append(DefaultServiceDependencies([registration.Codec])) + .Append(", copierDependencies: ").Append(DefaultServiceDependencies([registration.Copier])).AppendLine(");"); result.Append("options.AddAllowedType(typeof(").Append(Name(responseType)).AppendLine("));"); return new Graph(new Dictionary(SymbolEqualityComparer.Default) { [type] = registration }, result.ToString()); @@ -311,8 +311,8 @@ private static void AppendConstructionDependency(IGeneratorServices services, IT .Append(", dependencies: ").Append(DefaultServiceDependencies(ConstructorDependencies(tupleCopier))).AppendLine(");"); result.Append("options.AddDefaultSerializer<").Append(Name(tupleType)).Append(", ").Append(Name(tupleCodec)).Append(", ").Append(Name(tupleCopier)).Append(">(static provider => ") .Append(Resolve(Name(tupleCodec))).Append(", static provider => ").Append(Resolve(Name(tupleCopier))) - .Append(", codecDependencies: ").Append(DefaultDependencyServices(tupleType.TypeArguments, codec: true)) - .Append(", copierDependencies: ").Append(DefaultDependencyServices(tupleType.TypeArguments, codec: false)).AppendLine(");"); + .Append(", codecDependencies: ").Append(DefaultServiceDependencies(ConstructorDependencies(tupleCodec))) + .Append(", copierDependencies: ").Append(DefaultServiceDependencies(ConstructorDependencies(tupleCopier))).AppendLine(");"); return; } @@ -329,8 +329,8 @@ private static void AppendConstructionDependency(IGeneratorServices services, IT .Append(", dependencies: ").Append(DefaultServiceDependencies(ConstructorDependencies(copier))).AppendLine(");"); result.Append("options.AddDefaultSerializer<").Append(Name(arrayType)).Append(", ").Append(Name(codec)).Append(", ").Append(Name(copier)).Append(">(static provider => ") .Append(Resolve(Name(codec))).Append(", static provider => ").Append(Resolve(Name(copier))) - .Append(", codecDependencies: ").Append(DefaultDependencyServices([arrayType.ElementType], codec: true)) - .Append(", copierDependencies: ").Append(DefaultDependencyServices([arrayType.ElementType], codec: false)).AppendLine(");"); + .Append(", codecDependencies: ").Append(DefaultServiceDependencies(ConstructorDependencies(codec))) + .Append(", copierDependencies: ").Append(DefaultServiceDependencies(ConstructorDependencies(copier))).AppendLine(");"); return; } @@ -447,6 +447,8 @@ internal static bool TryCreate( var typeName = Name(registration.Type); var hasBaseCodec = false; var hasBaseCopier = false; + var codecDependencies = new List(); + var copierDependencies = new List(); if (registration.Model is { } model) { if (registration.ReferencedCodec is { } referencedCodec) @@ -457,22 +459,30 @@ internal static bool TryCreate( hasBaseCopier = registration.ReferencedCopier?.AllInterfaces.Any(contract => SymbolEqualityComparer.Default.Equals(contract.OriginalDefinition, implementationLibrary.BaseCopier_1)) == true; registration.CodecConstruction = ConstructReferenced(registration.Codec, referencedCodec); + codecDependencies.AddRange(ConstructorDependencies(referencedCodec)); registration.CopierConstruction = registration.ReferencedCopier is { } referencedCopier ? ConstructReferenced(registration.Copier, referencedCopier) : $"new {registration.Copier}()"; + if (registration.ReferencedCopier is { } copierType) + copierDependencies.AddRange(ConstructorDependencies(copierType)); } else { - var codecDeclaration = serializerGenerator.Generate(model); + var codecDeclaration = SpecializeGeneratedSyntax(serializerGenerator.Generate(model), model, (INamedTypeSymbol)registration.Type); var copierDeclaration = copierGenerator.GenerateCopier(model, new()); + if (copierDeclaration is not null) + copierDeclaration = SpecializeGeneratedSyntax(copierDeclaration, model, (INamedTypeSymbol)registration.Type); hasBaseCodec = codecDeclaration.BaseList!.Types.Any(contract => contract.Type.ToString() == services.LibraryTypes.BaseCodec_1.ToTypeSyntax(model.TypeSyntax).ToString()); hasBaseCopier = copierDeclaration?.BaseList?.Types.Any(contract => contract.Type.ToString() == services.LibraryTypes.BaseCopier_1.ToTypeSyntax(model.TypeSyntax).ToString()) == true; registration.CodecConstruction = ConstructGenerated(registration.Codec, codecDeclaration); + codecDependencies.AddRange(ConstructorDependencies(codecDeclaration)); registration.CopierConstruction = copierDeclaration is null ? $"new {registration.Copier}()" : ConstructGenerated(registration.Copier, copierDeclaration); + if (copierDeclaration is not null) + copierDependencies.AddRange(ConstructorDependencies(copierDeclaration)); } } else if (registration.Dependencies.Count > 0) @@ -483,6 +493,13 @@ internal static bool TryCreate( { var target = registrations[dependency.WithNullableAnnotation(NullableAnnotation.None)]; var cyclic = Reaches(target, registration.Type, registrations, new(SymbolEqualityComparer.Default)); + var consumesConcreteService = (!cyclic && useDefaultFactories) || registration.ResponseResult is not null; + codecDependencies.Add(consumesConcreteService + ? target.Codec + : $"global::Orleans.Serialization.Codecs.IFieldCodec<{Name(dependency)}>"); + copierDependencies.Add(consumesConcreteService + ? target.Copier + : $"global::Orleans.Serialization.Cloning.IDeepCopier<{Name(dependency)}>"); codecArguments.Add(cyclic && registration.ResponseResult is not null ? $"caller => {Resolve(target.Codec, "caller")}" : cyclic @@ -501,23 +518,23 @@ internal static bool TryCreate( result.Append("options.").Append(addService).Append('<').Append(registration.Codec).Append(">(static provider => ") .Append(registration.CodecConstruction); - if (useDefaultFactories && registration.Dependencies.Count > 0) - result.Append(", dependencies: ").Append(DefaultDependencyServices(registration.Dependencies, codec: true)); + if (useDefaultFactories && codecDependencies.Count > 0) + result.Append(", dependencies: ").Append(DefaultServiceDependencies(codecDependencies)); result.AppendLine(");"); result.Append("options.").Append(addService).Append('<').Append(registration.Copier).Append(">(static provider => ") .Append(registration.CopierConstruction); - if (useDefaultFactories && registration.Dependencies.Count > 0) - result.Append(", dependencies: ").Append(DefaultDependencyServices(registration.Dependencies, codec: false)); + if (useDefaultFactories && copierDependencies.Count > 0) + result.Append(", dependencies: ").Append(DefaultServiceDependencies(copierDependencies)); result.AppendLine(");"); result.Append("options.").Append(addSerializer).Append('<').Append(typeName); if (useDefaultFactories) result.Append(", ").Append(registration.Codec).Append(", ").Append(registration.Copier); result.Append(">(static provider => ") .Append(Resolve(registration.Codec)).Append(", static provider => ").Append(Resolve(registration.Copier)); - if (useDefaultFactories && registration.Dependencies.Count > 0) + if (useDefaultFactories && (codecDependencies.Count > 0 || copierDependencies.Count > 0)) { - result.Append(", codecDependencies: ").Append(DefaultDependencyServices(registration.Dependencies, codec: true)) - .Append(", copierDependencies: ").Append(DefaultDependencyServices(registration.Dependencies, codec: false)); + result.Append(", codecDependencies: ").Append(DefaultServiceDependencies(codecDependencies)) + .Append(", copierDependencies: ").Append(DefaultServiceDependencies(copierDependencies)); } result.AppendLine(");"); if (registration.Model is { IsValueType: true, IsEnumType: false }) @@ -534,7 +551,7 @@ internal static bool TryCreate( if (useDefaultFactories) result.Append(", ").Append(registration.Codec); result.Append(">(static provider => ").Append(Resolve(registration.Codec)); if (useDefaultFactories) - result.Append(", dependencies: ").Append(DefaultDependencyServices(registration.Dependencies, codec: true)); + result.Append(", dependencies: ").Append(DefaultServiceDependencies(codecDependencies)); result.AppendLine(");"); } if (hasBaseCopier) @@ -544,7 +561,7 @@ internal static bool TryCreate( if (useDefaultFactories) result.Append(", ").Append(registration.Copier); result.Append(">(static provider => ").Append(Resolve(registration.Copier)); if (useDefaultFactories) - result.Append(", dependencies: ").Append(DefaultDependencyServices(registration.Dependencies, codec: false)); + result.Append(", dependencies: ").Append(DefaultServiceDependencies(copierDependencies)); result.AppendLine(");"); } diff --git a/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs b/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs index db428b62b3a..22d3116dc08 100644 --- a/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs +++ b/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs @@ -51,6 +51,7 @@ public sealed class TypeManifestOptions internal Dictionary CopierFactoryServices { get; } = new(); internal Dictionary> SerializerServiceFactories { get; } = new(); internal Dictionary DefaultSerializerContracts { get; } = new(); + internal Dictionary> DefaultSerializerImplementationServices { get; } = new(); internal Dictionary DefaultCodecFactoryContracts { get; } = new(); internal Dictionary DefaultCopierFactoryContracts { get; } = new(); internal Dictionary> RawResponseReaderFactories { get; } = new(); @@ -124,6 +125,8 @@ public void AddDefaultSerializer( var registerCodec = !SerializerServiceFactories.ContainsKey(typeof(IFieldCodec)); var registerCopier = !SerializerServiceFactories.ContainsKey(typeof(IDeepCopier)); RegisterSerializerFactories(codecFactory, copierFactory, isDefault: true); + RegisterDefaultImplementationService(typeof(IFieldCodec), typeof(TCodec)); + RegisterDefaultImplementationService(typeof(IDeepCopier), typeof(TCopier)); if (registerCodec) { RegisterDefaultContract(typeof(IFieldCodec), typeof(TCodec), compatibleCodecType, codecDependencies); @@ -230,11 +233,22 @@ public void AddDefaultSerializerService( dependencies = CopyDefaultDependencies(dependencies); var register = !SerializerServiceFactories.ContainsKey(typeof(TService)); AddDefaultSerializerService(factory); + RegisterDefaultImplementationService(typeof(TService), typeof(TImplementation)); if (register) RegisterDefaultContract(typeof(TService), typeof(TImplementation), compatibleImplementationType, dependencies); } internal bool IsDefaultSerializerService(Type type) => _defaultSerializerServices.Contains(type); + private void RegisterDefaultImplementationService(Type service, Type implementation) + { + if (service == implementation) return; + if (!DefaultSerializerImplementationServices.TryGetValue(implementation, out var services)) + { + DefaultSerializerImplementationServices.Add(implementation, services = new()); + } + services.Add(service); + } + private void RegisterDefaultContract(Type service, Type? implementation, Type? compatible, Type[]? dependencies) { if (!_defaultSerializerServices.Contains(service) || DefaultSerializerContracts.ContainsKey(service)) return; diff --git a/src/Orleans.Serialization/Serializers/CodecProvider.cs b/src/Orleans.Serialization/Serializers/CodecProvider.cs index 572196f1274..bb725b0c147 100644 --- a/src/Orleans.Serialization/Serializers/CodecProvider.cs +++ b/src/Orleans.Serialization/Serializers/CodecProvider.cs @@ -678,10 +678,25 @@ private bool IsDefaultCopierEligible(Type type) // Inferred defaults preserve an automatic caller's DI boundary instead of starting a transaction inside it. private bool IsDefaultServiceEligible(Type service) - => !(_manifest.IsDefaultSerializerService(service) - && OrleansGeneratedCodeHelper.GetConstructionScope(this) is { IsPending: false }) - && (!_manifest.DefaultSerializerContracts.TryGetValue(service, out var contract) - || IsDefaultContractEligible(contract, [])); + => !_manifest.IsDefaultSerializerService(service) + || (OrleansGeneratedCodeHelper.GetConstructionScope(this) is not { IsPending: false } + && IsDefaultImplementationEligible(service) + && (!_manifest.DefaultSerializerContracts.TryGetValue(service, out var contract) + || IsDefaultContractEligible(contract, []))); + + private bool IsDefaultImplementationEligible(Type implementation) + { + if (_manifest.DefaultSerializerImplementationServices.TryGetValue(implementation, out var services)) + { + foreach (var service in services) + { + if (!_manifest.IsDefaultSerializerService(service)) return false; + if (_manifest.DefaultSerializerContracts.TryGetValue(service, out var contract) + && !IsDefaultContractImplementationEligible(contract)) return false; + } + } + return true; + } private bool IsProviderService(Type serviceType) => serviceType != typeof(object) @@ -691,23 +706,12 @@ private bool IsProviderService(Type serviceType) private bool IsDefaultContractEligible(TypeManifestOptions.DefaultSerializerContract contract, HashSet visited) { if (!_manifest.IsDefaultSerializerService(contract.Service) || !visited.Add(contract.Service)) return true; - var role = contract.Service.IsConstructedGenericType ? contract.Service.GetGenericTypeDefinition() : null; - var target = role is null ? contract.Service : contract.Service.GenericTypeArguments[0]; - if (role is not null && contract.Implementation is { } implementation) - { - var searchType = target.IsConstructedGenericType ? target.GetGenericTypeDefinition() : target; - if (TrySelectImplementation(role, target, searchType, out var selected, out _, materializeImplementation: false)) - { - if (!MatchesDefaultImplementation(selected, implementation, contract.CompatibleImplementation, target)) return false; - } - else if ((role == typeof(IFieldCodec<>) || role == typeof(IDeepCopier<>)) - && TrySelectImplementation(typeof(IConverter<,>), target, searchType, out _, out _, materializeImplementation: false)) - { - return false; - } - } + if (!IsDefaultContractImplementationEligible(contract)) return false; foreach (var dependency in contract.Dependencies) { + if (_manifest.SerializerServiceFactories.ContainsKey(dependency) && !_manifest.IsDefaultSerializerService(dependency)) + continue; + if (!IsDefaultImplementationEligible(dependency)) return false; if (_manifest.DefaultSerializerContracts.TryGetValue(dependency, out var required)) { if (!IsDefaultContractEligible(required, visited)) return false; @@ -724,6 +728,26 @@ private bool IsDefaultContractEligible(TypeManifestOptions.DefaultSerializerCont return true; } + private bool IsDefaultContractImplementationEligible(TypeManifestOptions.DefaultSerializerContract contract) + { + var role = contract.Service.IsConstructedGenericType ? contract.Service.GetGenericTypeDefinition() : null; + var target = role is null ? contract.Service : contract.Service.GenericTypeArguments[0]; + if (role is not null && contract.Implementation is { } implementation) + { + var searchType = target.IsConstructedGenericType ? target.GetGenericTypeDefinition() : target; + if (TrySelectImplementation(role, target, searchType, out var selected, out _, materializeImplementation: false)) + { + if (!MatchesDefaultImplementation(selected, implementation, contract.CompatibleImplementation, target)) return false; + } + else if ((role == typeof(IFieldCodec<>) || role == typeof(IDeepCopier<>)) + && TrySelectImplementation(typeof(IConverter<,>), target, searchType, out _, out _, materializeImplementation: false)) + { + return false; + } + } + return true; + } + private static bool MatchesDefaultImplementation(Type selected, Type expected, Type? compatible, Type target) { if (selected == expected || selected == compatible) return true; diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index 4de3e02bfe6..952b628db8c 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -2268,18 +2268,30 @@ public partial class Context : Orleans.Serialization.SerializerContext { } """); var managed = RunSourceGenerator(compilation, new Dictionary { ["build_property.publishaot"] = "false" }); var native = RunSourceGenerator(compilation, new Dictionary { ["build_property.publishaot"] = "true" }); + var tree = compilation.SyntaxTrees.Single(); + var frameworkSymbolCompilation = compilation.ReplaceSyntaxTree(tree, + tree.WithRootAndOptions(tree.GetRoot(TestContext.Current.CancellationToken), + ((CSharpParseOptions)tree.Options).WithPreprocessorSymbols("NET5_0_OR_GREATER"))); + var frameworkSymbol = RunSourceGenerator(frameworkSymbolCompilation); Assert.Empty(managed.Diagnostics); Assert.Empty(native.Diagnostics); + Assert.Empty(frameworkSymbol.Diagnostics); Assert.Equal( managed.GeneratedSources.OrderBy(static source => source.HintName, StringComparer.Ordinal) .Select(static source => (source.HintName, Source: source.SourceText.ToString())), native.GeneratedSources.OrderBy(static source => source.HintName, StringComparer.Ordinal) .Select(static source => (source.HintName, Source: source.SourceText.ToString()))); + Assert.Equal( + managed.GeneratedSources.OrderBy(static source => source.HintName, StringComparer.Ordinal) + .Select(static source => (source.HintName, Source: source.SourceText.ToString())), + frameworkSymbol.GeneratedSources.OrderBy(static source => source.HintName, StringComparer.Ordinal) + .Select(static source => (source.HintName, Source: source.SourceText.ToString()))); var source = ConcatenateGeneratedSources(managed); Assert.Contains("IResponseInvokable", source); Assert.Contains("IRawResponseWriter", source); Assert.Contains("AddRawResponseReader", source); + Assert.DoesNotContain("#if NET5_0_OR_GREATER", source); Assert.DoesNotContain("RuntimeFeature", source); Assert.DoesNotContain("UseGeneratedSerializerContexts", source); Assert.DoesNotContain("RequireExplicitTypeRegistration", source); @@ -2387,6 +2399,10 @@ public class Payload Assert.DoesNotContain("RuntimeFeature.IsDynamicCodeSupported", source); Assert.Contains("codecDependencies: new global::System.Type[]", source); Assert.Contains("copierDependencies: new global::System.Type[]", source); + var integerResponseRegistration = Assert.Single(source.Split('\n'), static line => + line.Contains("options.AddDefaultSerializer,", StringComparison.Ordinal)); + Assert.Contains("codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.Int32Codec) }", integerResponseRegistration); + Assert.Contains("copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }", integerResponseRegistration); Assert.DoesNotContain("GetService(static provider => new RpcResponse_9146C7E3Factory(provider)); options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); -#if NET5_0_OR_GREATER - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); - options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); @@ -298,7 +297,6 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); -#endif } private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs index 083a0fa5927..ff489b8c6c5 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs @@ -281,10 +281,9 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); -#if NET5_0_OR_GREATER - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); - options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); @@ -298,7 +297,6 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); -#endif } private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs index b0eb7456911..5c30dbb303e 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs @@ -189,10 +189,9 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); -#if NET5_0_OR_GREATER - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); - options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); @@ -206,7 +205,6 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); -#endif } private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs index 7a7727d16da..ee1f03b35bf 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs @@ -189,10 +189,9 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); -#if NET5_0_OR_GREATER - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); - options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); @@ -206,7 +205,6 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); -#endif } private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs index 7cf5715b388..d74d21e5cf2 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs @@ -475,16 +475,15 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new RpcResponse_FC7DD5BDFactory(provider)); options.AddDefaultSerializer(static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider), static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider)); -#if NET5_0_OR_GREATER - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); - options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::OrleansCodeGen.TestProject.Codec_ComplexData) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::OrleansCodeGen.TestProject.Copier_ComplexData) }); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::OrleansCodeGen.TestProject.Codec_ComplexData) }, copierDependencies: new global::System.Type[] { typeof(global::OrleansCodeGen.TestProject.Copier_ComplexData) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); - options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Codec_ComplexData(), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); - options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Copier_ComplexData(), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); - options.AddDefaultSerializerService, global::OrleansCodeGen.TestProject.Codec_ComplexData>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); - options.AddDefaultSerializerService, global::OrleansCodeGen.TestProject.Copier_ComplexData>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Codec_ComplexData()); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Copier_ComplexData()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); + options.AddDefaultSerializerService, global::OrleansCodeGen.TestProject.Codec_ComplexData>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), dependencies: new global::System.Type[] { }); + options.AddDefaultSerializerService, global::OrleansCodeGen.TestProject.Copier_ComplexData>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), dependencies: new global::System.Type[] { }); options.AddAllowedType(typeof(global::TestProject.ComplexData)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.Int32Codec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); @@ -502,7 +501,6 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); -#endif } private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs index 80f59fc84f1..908fd213c57 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs @@ -474,16 +474,15 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new RpcResponse_FC7DD5BDFactory(provider)); options.AddDefaultSerializer(static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider), static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider)); -#if NET5_0_OR_GREATER - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); - options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::OrleansCodeGen.TestProject.Codec_ComplexData) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::OrleansCodeGen.TestProject.Copier_ComplexData) }); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::OrleansCodeGen.TestProject.Codec_ComplexData) }, copierDependencies: new global::System.Type[] { typeof(global::OrleansCodeGen.TestProject.Copier_ComplexData) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); - options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Codec_ComplexData(), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); - options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Copier_ComplexData(), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); - options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); - options.AddDefaultSerializerService, global::OrleansCodeGen.TestProject.Codec_ComplexData>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); - options.AddDefaultSerializerService, global::OrleansCodeGen.TestProject.Copier_ComplexData>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Codec_ComplexData()); + options.AddDefaultSerializerService(static provider => new global::OrleansCodeGen.TestProject.Copier_ComplexData()); + options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)); + options.AddDefaultSerializerService, global::OrleansCodeGen.TestProject.Codec_ComplexData>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), dependencies: new global::System.Type[] { }); + options.AddDefaultSerializerService, global::OrleansCodeGen.TestProject.Copier_ComplexData>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), dependencies: new global::System.Type[] { }); options.AddAllowedType(typeof(global::TestProject.ComplexData)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.Int32Codec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); @@ -501,7 +500,6 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); -#endif } private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs index 53a198828a7..60683d99759 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs @@ -286,10 +286,9 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); -#if NET5_0_OR_GREATER - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); - options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); @@ -303,7 +302,6 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); -#endif } private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs index 7f6fd2c89af..fdbcde11b51 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs @@ -286,10 +286,9 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); -#if NET5_0_OR_GREATER - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); - options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); @@ -303,7 +302,6 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); -#endif } private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs index 9895d058e02..0246b4145d3 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs @@ -188,10 +188,9 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); -#if NET5_0_OR_GREATER - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); - options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); @@ -205,7 +204,6 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); -#endif } private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs index 9f179cd43cb..68f40093422 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs @@ -188,10 +188,9 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); -#if NET5_0_OR_GREATER - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); - options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); @@ -205,7 +204,6 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); -#endif } private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs index 92de56a866f..87b15ff690c 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs @@ -892,34 +892,33 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); -#if NET5_0_OR_GREATER - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); - options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.GuidCodec) }); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.GuidCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); - options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec>) }); - options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier>) }); - options.AddDefaultSerializer>, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>, global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec>) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier>) }); + options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCodec) }); + options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCopier) }); + options.AddDefaultSerializer>, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>, global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response>)); - options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec>) }); - options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier>) }); - options.AddDefaultSerializer>, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>, global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec>) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier>) }); + options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCodec) }); + options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCopier) }); + options.AddDefaultSerializer>, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>, global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response>)); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); - options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.GuidCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(global::System.Guid)); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); - options.AddDefaultSerializer, global::Orleans.Serialization.Codecs.TupleCodec, global::Orleans.Serialization.Codecs.TupleCopier>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.GuidCodec), typeof(global::Orleans.Serialization.Codecs.StringCodec) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier), typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); + options.AddDefaultSerializer, global::Orleans.Serialization.Codecs.TupleCodec, global::Orleans.Serialization.Codecs.TupleCopier>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.GuidCodec), typeof(global::Orleans.Serialization.Codecs.StringCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier), typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddAllowedType(typeof(global::System.Tuple)); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); - options.AddDefaultSerializer, global::Orleans.Serialization.Codecs.TupleCodec, global::Orleans.Serialization.Codecs.TupleCopier>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.Int64Codec), typeof(global::Orleans.Serialization.Codecs.StringCodec) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier), typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); + options.AddDefaultSerializer, global::Orleans.Serialization.Codecs.TupleCodec, global::Orleans.Serialization.Codecs.TupleCopier>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.Int64Codec), typeof(global::Orleans.Serialization.Codecs.StringCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier), typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddAllowedType(typeof(global::System.Tuple)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.Int64Codec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); @@ -937,7 +936,6 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); -#endif } private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs index 5213a5818ea..5d831ddbd02 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs @@ -892,34 +892,33 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); -#if NET5_0_OR_GREATER - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); - options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.GuidCodec) }); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.GuidCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); - options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec>) }); - options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier>) }); - options.AddDefaultSerializer>, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>, global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec>) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier>) }); + options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCodec) }); + options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCopier) }); + options.AddDefaultSerializer>, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>, global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response>)); - options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec>) }); - options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier>) }); - options.AddDefaultSerializer>, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>, global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec>) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier>) }); + options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCodec) }); + options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCopier) }); + options.AddDefaultSerializer>, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>, global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response>)); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); - options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.GuidCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(global::System.Guid)); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); - options.AddDefaultSerializer, global::Orleans.Serialization.Codecs.TupleCodec, global::Orleans.Serialization.Codecs.TupleCopier>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.GuidCodec), typeof(global::Orleans.Serialization.Codecs.StringCodec) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier), typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); + options.AddDefaultSerializer, global::Orleans.Serialization.Codecs.TupleCodec, global::Orleans.Serialization.Codecs.TupleCopier>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.GuidCodec), typeof(global::Orleans.Serialization.Codecs.StringCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier), typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddAllowedType(typeof(global::System.Tuple)); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); - options.AddDefaultSerializer, global::Orleans.Serialization.Codecs.TupleCodec, global::Orleans.Serialization.Codecs.TupleCopier>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec), typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier), typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.Int64Codec), typeof(global::Orleans.Serialization.Codecs.StringCodec) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Codecs.TupleCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier), typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); + options.AddDefaultSerializer, global::Orleans.Serialization.Codecs.TupleCodec, global::Orleans.Serialization.Codecs.TupleCopier>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.Int64Codec), typeof(global::Orleans.Serialization.Codecs.StringCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier), typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddAllowedType(typeof(global::System.Tuple)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.Int64Codec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); @@ -937,7 +936,6 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); -#endif } private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs index 552ee117ca5..13a915150ec 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs @@ -353,10 +353,9 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); -#if NET5_0_OR_GREATER - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); - options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); @@ -370,7 +369,6 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); -#endif } private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs index 8c2dcca45d4..e0ca637a8bb 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs @@ -353,10 +353,9 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); -#if NET5_0_OR_GREATER - options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }); - options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); - options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.IFieldCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.IDeepCopier) }); + options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }); + options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); + options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); @@ -370,7 +369,6 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.CompletedResponse)); -#endif } private sealed class CompletedResponseActivator : global::Orleans.Serialization.Activators.IActivator diff --git a/test/Orleans.Serialization.UnitTests/DefaultFactoryDependencyAdmissionTests.cs b/test/Orleans.Serialization.UnitTests/DefaultFactoryDependencyAdmissionTests.cs index 776c092691b..3d10152589e 100644 --- a/test/Orleans.Serialization.UnitTests/DefaultFactoryDependencyAdmissionTests.cs +++ b/test/Orleans.Serialization.UnitTests/DefaultFactoryDependencyAdmissionTests.cs @@ -1,5 +1,6 @@ using System; using Microsoft.Extensions.DependencyInjection; +using Orleans.Serialization.Activators; using Orleans.Serialization.Buffers; using Orleans.Serialization.Cloning; using Orleans.Serialization.Codecs; @@ -112,6 +113,30 @@ public void ExplicitClosedDependency_FailedGraphRollsBackBeforeCanonicalRetry() Assert.False(provider.IsConstructionPending); } + [Theory] + [InlineData(false)] + [InlineData(true)] + public void ExplicitActivatorContract_SelectsContractAwareParentConstruction(bool explicitFirst) + { + var options = new TypeManifestOptions(); + if (explicitFirst) RegisterExplicit(); + options.AddDefaultSerializerService(static _ => new()); + options.AddDefaultSerializerService, CanonicalActivator>( + static provider => OrleansGeneratedCodeHelper.GetService(null!, provider)); + options.AddDefaultSerializerService( + static _ => throw new InvalidOperationException("The canonical parent must yield to the explicit child contract."), + [typeof(CanonicalActivator)]); + if (!explicitFirst) RegisterExplicit(); + using var services = new ServiceCollection().BuildServiceProvider(); + var provider = new CodecProvider(services, Microsoft.Extensions.Options.Options.Create(options)); + + Assert.False(provider.TryGetSerializerService(typeof(ActivatingRoot), out _)); + Assert.False(provider.IsConstructionPending); + + void RegisterExplicit() => options.AddSerializerService>( + static _ => throw new InvalidOperationException("Admission examines the declared dependency without constructing it.")); + } + private static void RegisterDefaults(TypeManifestOptions options, State state) { options.AddSerializer(typeof(DependentCodec)); @@ -144,6 +169,13 @@ private sealed class FailingRoot { } + private sealed class ActivatingRoot; + + private sealed class CanonicalActivator : IActivator + { + public Target Create() => new(); + } + public sealed class DependentCodec : IFieldCodec { public DependentCodec(Dependency dependency, IServiceProvider services) diff --git a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs index ce4feed446e..e15607fb699 100644 --- a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs +++ b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs @@ -223,6 +223,103 @@ public void GeneratedResponseFactoriesPreserveCanonicalClosedImplementations() Assert.IsType>>(provider.GetDeepCopier>()); } + [Theory] + [InlineData(false, false, false)] + [InlineData(false, false, true)] + [InlineData(false, true, false)] + [InlineData(false, true, true)] + [InlineData(true, false, false)] + [InlineData(true, false, true)] + [InlineData(true, true, false)] + [InlineData(true, true, true)] + public void InferredResponseParentsHonorExplicitChildFactories( + bool explicitFirst, bool describeCanonicalServices, bool consumeChildContracts) + { + foreach (var untyped in new[] { false, true }) + { + var payloadCodec = new DelegatingCodec(new Int32Codec()); + var payloadCopier = new TransformingIntCopier(); + var codecCalls = 0; + var copierCalls = 0; + var options = new TypeManifestOptions(); + options.AddSerializer(typeof(PooledResponseCodec<>), typeof(Response<>)); + options.AddCopier(typeof(PooledResponseCopier<>), typeof(Response<>)); + if (explicitFirst) RegisterExplicit(); + if (describeCanonicalServices) + { + options.AddDefaultSerializerService(static _ => new(), []); + options.AddDefaultSerializerService>(static _ => new(), []); + } + else + { + options.AddDefaultSerializerService(static _ => new()); + options.AddDefaultSerializerService>(static _ => new()); + } + options.AddDefaultSerializer>( + static provider => OrleansGeneratedCodeHelper.GetService(null!, provider), + static provider => OrleansGeneratedCodeHelper.GetService>(null!, provider)); + if (consumeChildContracts) RegisterParent, IDeepCopier>(); + else RegisterParent>(); + if (!explicitFirst) RegisterExplicit(); + using var services = new ServiceCollection().AddSerializer() + .AddSingleton>(Microsoft.Extensions.Options.Options.Create(options)) + .BuildServiceProvider(); + var provider = services.GetRequiredService(); + var codec = untyped + ? Assert.IsAssignableFrom>>(provider.GetCodec(typeof(Response))) + : provider.GetCodec>(); + var copier = untyped + ? Assert.IsAssignableFrom>>(provider.GetDeepCopier(typeof(Response))) + : provider.GetDeepCopier>(); + if (!consumeChildContracts) + { + Assert.IsType>(codec); + Assert.IsType>(copier); + } + + using var response = (Response)Response.FromResult(42); + var bytes = Write(codec, response); + using var session = _services.GetRequiredService().GetSession(); + var reader = Reader.Create(bytes, session); + using var roundTrip = codec.ReadValue(ref reader, reader.ReadFieldHeader()); + Assert.NotNull(roundTrip); + Assert.Equal(42, roundTrip.TypedResult); + Assert.Equal(1, payloadCodec.Writes); + Assert.Equal(1, payloadCodec.Reads); + using var context = _services.GetRequiredService().GetContext(); + using var copy = copier.DeepCopy(response, context); + Assert.Equal(43, copy.TypedResult); + Assert.Equal(1, payloadCopier.Copies); + Assert.Equal(consumeChildContracts ? 1 : 0, codecCalls); + Assert.Equal(consumeChildContracts ? 1 : 0, copierCalls); + Assert.Same(payloadCodec, provider.GetCodec()); + Assert.Same(payloadCopier, provider.GetDeepCopier()); + Assert.False(provider.IsConstructionPending); + + void RegisterExplicit() => options.AddSerializer(_ => payloadCodec, _ => payloadCopier); + + void RegisterParent() + where TCodec : class, IFieldCodec + where TCopier : class, IDeepCopier + { + options.AddDefaultSerializerService>(provider => + { + codecCalls++; + return new(OrleansGeneratedCodeHelper.GetService(null!, provider)); + }, [typeof(TCodec)]); + options.AddDefaultSerializerService>(provider => + { + copierCalls++; + return new(OrleansGeneratedCodeHelper.GetService(null!, provider)); + }, [typeof(TCopier)]); + options.AddDefaultSerializer, PooledResponseCodec, PooledResponseCopier>( + static provider => OrleansGeneratedCodeHelper.GetService>(null!, provider), + static provider => OrleansGeneratedCodeHelper.GetService>(null!, provider), + codecDependencies: [typeof(TCodec)], copierDependencies: [typeof(TCopier)]); + } + } + } + [Fact] public void InferredResponseFactoriesInspectDefinitionsWithoutMaterializingLegacyImplementations() { @@ -727,17 +824,21 @@ public async Task GeneratedResponseHolderHonorsCustomPayloadCopier() [Theory] [InlineData("PayloadCodec")] + [InlineData("PayloadCopier")] [InlineData("ResponseCodec")] [InlineData("ResponseCopier")] public async Task GeneratedResponseHolderHonorsCustomResultAndResponseServices(string service) { var payloadCodec = new DelegatingCodec(new Int32Codec()); + var payloadCopier = new TransformingIntCopier(); var responseCodec = new DelegatingCodec>(new PooledResponseCodec(new Int32Codec())); var responseCopier = new TransformingResponseCopier(); using var services = new ServiceCollection().AddSerializer(builder => builder.Configure(options => { if (service == "PayloadCodec") options.AddSerializer(_ => payloadCodec, _ => new ShallowCopier()); + else if (service == "PayloadCopier") + options.AddSerializer(static _ => new Int32Codec(), _ => payloadCopier); else if (service == "ResponseCodec") options.AddSerializer>(_ => responseCodec, _ => new PooledResponseCopier>(new ShallowCopier())); else @@ -750,8 +851,10 @@ public async Task GeneratedResponseHolderHonorsCustomResultAndResponseServices(s using var result = await Assert.IsAssignableFrom(invokable).InvokeAndCopy( provider, contexts, services.GetRequiredService().GetCopier()); + Assert.Null(result.Exception); Assert.IsType>(result); - Assert.Equal(service == "ResponseCopier" ? 43 : 42, result.GetResult()); + Assert.Equal(service is "PayloadCopier" or "ResponseCopier" ? 43 : 42, result.GetResult()); + Assert.Equal(service == "PayloadCopier" ? 1 : 0, payloadCopier.Copies); Assert.Equal(service == "ResponseCopier" ? 1 : 0, responseCopier.Copies); Assert.False(provider.TryGetRawResponseReader(typeof(int), out _)); if (service == "PayloadCodec") Assert.Same(payloadCodec, provider.GetCodec()); @@ -800,11 +903,31 @@ public async Task GeneratedResponseReaderReturnsHolderAfterMalformedPayload() private sealed class DelegatingCodec(IFieldCodec codec) : IFieldCodec { + public int Writes { get; private set; } + public int Reads { get; private set; } public void WriteField(ref Writer writer, uint fieldIdDelta, [System.Diagnostics.CodeAnalysis.AllowNull] Type expectedType, [System.Diagnostics.CodeAnalysis.AllowNull] T value) - where TBufferWriter : IBufferWriter => codec.WriteField(ref writer, fieldIdDelta, expectedType, value); + where TBufferWriter : IBufferWriter + { + Writes++; + codec.WriteField(ref writer, fieldIdDelta, expectedType, value); + } [return: System.Diagnostics.CodeAnalysis.MaybeNull] - public T ReadValue(ref Reader reader, Field field) => codec.ReadValue(ref reader, field); + public T ReadValue(ref Reader reader, Field field) + { + Reads++; + return codec.ReadValue(ref reader, field); + } + } + + private sealed class TransformingIntCopier : IDeepCopier + { + public int Copies { get; private set; } + public int DeepCopy(int input, CopyContext context) + { + Copies++; + return input + 1; + } } private sealed class TransformingResponseCopier : IDeepCopier> From 7f74fe002e3a1eb152da071f08ac1341e01e41c1 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Tue, 6 Oct 2026 18:54:23 -0700 Subject: [PATCH 42/54] refactor(rpc): consolidate response planning and service resolution Share candidate constraint validation, source-known argument metadata, immutable response plans, and construction-driven registration emission. Remove redundant manifest maps and pair each closed factory with its service identity. Centralize response copy/dispose ownership and raw reader adaptation while retaining typed/runtime dispatch, filter isolation, graph publication, and native-safe factory selection. --- .../docs/implementation/serialization.md | 4 + .../InvokableGenerator.cs | 11 +- .../OrleansSourceGenerator.cs | 9 +- .../RpcResponseGenerator.cs | 93 +++--- .../RpcResponseHolderGenerator.cs | 55 +--- src/Orleans.CodeGenerator/RpcResponsePlan.cs | 100 ++++++ .../SerializerFactoryGenerator.cs | 234 ++++++++------ src/Orleans.Core/Core/ResponseCopyBoundary.cs | 25 +- .../Messaging/MessageSerializer.cs | 16 +- .../Configuration/TypeManifestOptions.cs | 67 ++-- .../OrleansGeneratedCodeHelper.cs | 39 +++ .../Invocation/Response.cs | 10 +- .../Serializers/CodecProvider.cs | 37 +-- .../Serializers/GenericConstraintValidator.cs | 197 ++++++++++++ .../Orleans.Serialization.cs | 12 +- .../GeneratorMemoryRetentionTests.cs | 4 + .../OrleansSourceGeneratorTests.cs | 14 +- .../SerializerConstructionReviewTests.cs | 17 ++ ...ests.TestBasicGrain.DotNet10_0.verified.cs | 18 +- ...Tests.TestBasicGrain.DotNet8_0.verified.cs | 18 +- ...rializersAnnotation.DotNet10_0.verified.cs | 18 +- ...erializersAnnotation.DotNet8_0.verified.cs | 18 +- ...stGrainComplexGrain.DotNet10_0.verified.cs | 20 +- ...estGrainComplexGrain.DotNet8_0.verified.cs | 20 +- ...thInvokableBaseType.DotNet10_0.verified.cs | 18 +- ...ithInvokableBaseType.DotNet8_0.verified.cs | 18 +- ...WithResponseTimeout.DotNet10_0.verified.cs | 18 +- ...dWithResponseTimeout.DotNet8_0.verified.cs | 18 +- ...thDifferentKeyTypes.DotNet10_0.verified.cs | 73 ++--- ...ithDifferentKeyTypes.DotNet8_0.verified.cs | 73 ++--- ...hMultipleInterfaces.DotNet10_0.verified.cs | 29 +- ...thMultipleInterfaces.DotNet8_0.verified.cs | 29 +- .../ManifestContractTests.cs | 287 +++++++++++++++++- 33 files changed, 1050 insertions(+), 569 deletions(-) create mode 100644 src/Orleans.CodeGenerator/RpcResponsePlan.cs create mode 100644 src/Orleans.Serialization/Serializers/GenericConstraintValidator.cs diff --git a/docs/site/src/content/docs/implementation/serialization.md b/docs/site/src/content/docs/implementation/serialization.md index 1f883925b9d..758f32c6b06 100644 --- a/docs/site/src/content/docs/implementation/serialization.md +++ b/docs/site/src/content/docs/implementation/serialization.md @@ -149,6 +149,10 @@ Completed response transport uses the existing generated codec and its canonical The finite response graph supplies successful typed results and completed-response transport, plus immutable exception-envelope copying. Exception transport uses the selected codec and the exception and `Data` value dependencies. Closed factories provide statically compiled implementations; registered metadata and the existing exception codecs provide the remaining supported serialization contracts. +The generator prepares one response plan for holder naming, graph admission, and factory emission. Complete, partial, and referenced graphs share constructor-service descriptions and a registration emitter, so each dependency edge identifies the service consumed by its factory. Generated graphs register closed generic-argument metadata through . Candidate selection validates bound generic constraints before choosing an implementation, using the same validation for inferred defaults and ordinary lookup. Managed lookup retains runtime constraint validation for application-selected types whose metadata is supplied at runtime. + +Generated invocation fallbacks and runtime delivery boundaries share envelope copy-and-dispose ownership logic. The selected copier retains its typed or runtime-type dispatch behavior, including immutable exception envelopes and custom copiers that return their input. Raw response transport resolves one reader per result type; adapts compatibility codecs to , and supported generated readers retain precedence. + These supplemental registrations are emitted unconditionally and are defaults: explicit closed factory registrations take precedence in either configuration order. Inferred parent factories preserve each child's selected service: replacing a child contract selects parent construction through that contract, while parents consuming the explicit contract directly remain eligible. This applies throughout the dependency graph, including concrete canonical services and their codec, copier, and activator aliases. Generated factories and registered metadata use one resolution pipeline, with closed services selected first. Direct-holder factories and raw-reader registrations bind the selected provider implementations in both JIT and native execution. Custom application codec/copier selection uses the compatibility invocation and serialization path. Generated metadata also supplies static response factories for closed generated result models. These factories construct the model's canonical generated codec and copier using their actual constructor signatures, including closed generic generated activators and available generated activators from referenced assemblies. Source-known arrays, tuples, collections, and surrogate value serializers contribute their closed construction services. Interface contracts retain registered metadata dispatch and propagate their dependency requirements. Reference-assembly construction uses the producer's available constructor contracts and explicitly identified members. diff --git a/src/Orleans.CodeGenerator/InvokableGenerator.cs b/src/Orleans.CodeGenerator/InvokableGenerator.cs index 7a94047b7d2..c86da6eb911 100644 --- a/src/Orleans.CodeGenerator/InvokableGenerator.cs +++ b/src/Orleans.CodeGenerator/InvokableGenerator.cs @@ -175,16 +175,7 @@ private ClassDeclarationSyntax GetClassDeclarationSyntax( if (!factory.IsSupported) { var original = await Invoke(); - global::Orleans.Serialization.Invocation.Response copy = null; - try - { - return copy = responseCopier.Copy(original); - } - finally - { - if (!global::System.Object.ReferenceEquals(original, copy)) - original.Dispose(); - } + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } {{type}} value = await InvokeInner(); return factory.RentCopied(value, contexts); diff --git a/src/Orleans.CodeGenerator/OrleansSourceGenerator.cs b/src/Orleans.CodeGenerator/OrleansSourceGenerator.cs index 777cfc0e22b..3ff001bb2c0 100644 --- a/src/Orleans.CodeGenerator/OrleansSourceGenerator.cs +++ b/src/Orleans.CodeGenerator/OrleansSourceGenerator.cs @@ -151,10 +151,11 @@ public void Initialize(IncrementalGeneratorInitializationContext context) .Select(static (input, _) => ModelExtractor.MergeProxyInterfaces(input.Left, input.Right.ReferencedProxyInterfaces)) .WithComparer(ImmutableArrayComparer.Instance); - var responseNames = allProxyInterfaces + var responsePlan = allProxyInterfaces .Combine(compilationProvider) .Combine(generatorOptions) - .Select(static (input, ct) => RpcResponseHolderGenerator.GetNames(input.Left.Right, input.Left.Left, input.Right, ct)) + .Select(static (input, ct) => RpcResponsePlan.Create(input.Left.Right, input.Left.Left, input.Right, ct)); + var responseNames = responsePlan.Select(static (plan, _) => plan.Names) .WithComparer(ImmutableArrayComparer<(string TypeName, string HolderName)>.Instance); var preparedProxyOutputs = allProxyInterfaces @@ -229,10 +230,10 @@ public void Initialize(IncrementalGeneratorInitializationContext context) GeneratedSourceOutput.EmitSourceOutputResult(productionContext, input); }); - var responseOutputs = preparedProxyOutputModels + var responseOutputs = preparedProxyOutputs .Combine(compilationProvider) .Combine(generatorOptions) - .Combine(responseNames) + .Combine(responsePlan) .SelectMany(static (input, ct) => RpcResponseGenerator.Generate( input.Left.Left.Right, input.Left.Left.Left, input.Left.Right, input.Right, ct)); diff --git a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs index 2e389f581f2..b11c9364991 100644 --- a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs +++ b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs @@ -29,30 +29,24 @@ internal static class RpcResponseGenerator internal static ImmutableArray Generate( Compilation compilation, - ImmutableArray proxies, + ProxyOutputPreparationResult preparation, SourceGeneratorOptions options, - ImmutableArray<(string TypeName, string HolderName)> responseNames, + RpcResponsePlan plan, CancellationToken cancellationToken) { + var proxies = preparation.ProxyOutputModels; if (proxies.IsDefaultOrEmpty) { return []; } - var bindingTree = compilation.SyntaxTrees.FirstOrDefault(); - if (bindingTree is null) - { - bindingTree = CSharpSyntaxTree.Create(SyntaxFactory.CompilationUnit()); - compilation = compilation.AddSyntaxTrees(bindingTree); - } + compilation = RpcResponsePlan.WithBindingTree(compilation); var services = new GeneratorServices(compilation, SourceGeneratorOptionsParser.CreateCodeGeneratorOptions(options)); - var responseDefinition = compilation.GetTypeByMetadataName("Orleans.Serialization.Invocation.Response`1")!; var resolver = new TypeSymbolResolver(compilation); - var proxyContext = new ProxyGenerationContext(compilation, SourceGeneratorOptionsParser.CreateCodeGeneratorOptions(options), responseNames); - ProxySourceOutputGenerator.PopulateProxyInterfaces(proxyContext, resolver, - proxies.Select(static proxy => proxy.ProxyInterface).ToImmutableArray(), cancellationToken); - var binding = compilation.GetSemanticModel(bindingTree); + var responseNames = plan.Names.ToImmutableDictionary(static entry => entry.TypeName, static entry => entry.HolderName, StringComparer.Ordinal); + var binding = compilation.GetSemanticModel(compilation.SyntaxTrees.First()); + var constructorServices = GetConstructorServices(preparation.SourceOutputs, cancellationToken); var results = new Dictionary(SymbolEqualityComparer.Default); var arguments = new Dictionary(SymbolEqualityComparer.Default); var hasCompletionMethods = false; @@ -65,32 +59,29 @@ internal static ImmutableArray Generate( continue; } - var description = ProxySourceOutputGenerator.GetProxyInterfaceDescription(proxyContext, resolver, proxy.ProxyInterface, cancellationToken); - var (proxyClass, _) = new ProxyGenerator(proxyContext, new CopierGenerator(proxyContext)).Generate(description); - foreach (var request in proxyClass.Members.OfType() - .SelectMany(static constructor => constructor.DescendantNodes().OfType()) - .Where(static invocation => invocation.Expression is MemberAccessExpressionSyntax { Name: GenericNameSyntax { Identifier.ValueText: "GetService" } }) - .Select(static invocation => ((GenericNameSyntax)((MemberAccessExpressionSyntax)invocation.Expression).Name).TypeArgumentList.Arguments.Single())) + var methods = interfaceType.GetDeclaredInstanceMembers() + .Concat(interfaceType.AllInterfaces.SelectMany(static type => type.GetDeclaredInstanceMembers())) + .Where(static method => method.MethodKind == MethodKind.Ordinary).ToImmutableArray(); + constructorServices.TryGetValue(interfaceType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat), out var requests); + foreach (var request in requests.IsDefault ? [] : requests) { if (binding.GetSpeculativeTypeInfo(0, request, SpeculativeBindingOption.BindAsTypeOrNamespace).Type is INamedTypeSymbol service && service.AllInterfaces.Concat([service]).FirstOrDefault(type => SymbolEqualityComparer.Default.Equals(type.OriginalDefinition, services.LibraryTypes.DeepCopier_1)) is { } copier - && !ContainsTypeParameter(copier.TypeArguments[0]) && !arguments.ContainsKey(copier.TypeArguments[0])) + && !RpcResponsePlan.ContainsTypeParameter(copier.TypeArguments[0]) && !arguments.ContainsKey(copier.TypeArguments[0])) { - arguments.Add(copier.TypeArguments[0], description.Methods[0].Method); + arguments.Add(copier.TypeArguments[0], methods[0]); } } - foreach (var method in interfaceType.GetDeclaredInstanceMembers() - .Concat(interfaceType.AllInterfaces.SelectMany(static type => type.GetDeclaredInstanceMembers())) - .Where(static method => method.MethodKind == MethodKind.Ordinary)) + foreach (var method in methods) { if (method.TypeParameters.Length == 0) { foreach (var parameter in method.Parameters) { var parameterType = parameter.Type.WithNullableAnnotation(NullableAnnotation.None); - if (!ContainsTypeParameter(parameterType) && !services.LibraryTypes.IsShallowCopyable(parameterType) + if (!RpcResponsePlan.ContainsTypeParameter(parameterType) && !services.LibraryTypes.IsShallowCopyable(parameterType) && !arguments.ContainsKey(parameterType)) { arguments.Add(parameterType, method); @@ -120,7 +111,7 @@ internal static ImmutableArray Generate( } var resultType = named.TypeArguments[0].WithNullableAnnotation(NullableAnnotation.None); - if (ContainsTypeParameter(resultType)) + if (RpcResponsePlan.ContainsTypeParameter(resultType)) { Report(method, resultType, "the result contains an unresolved type parameter"); continue; @@ -143,13 +134,12 @@ internal static ImmutableArray Generate( { var resultType = entry.Key; var method = entry.Value; - if (RpcResponseHolderGenerator.TryDescribe(services, resultType, out var holderCodec, out var holderCopier)) + var description = plan.Results[resultType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)]; + if (description.Codec is { } holderCodec && description.Copier is { } holderCopier) responseHolders.Add(resultType, (holderCodec, holderCopier)); - if (SerializerFactoryGenerator.TryCreate(services, [responseDefinition.Construct(resultType)], cancellationToken, out var candidate, out var failure, useDefaultFactories: true)) + if (description.Graph is { } candidate) { - var dictionary = candidate.Registrations.Keys.OfType() - .FirstOrDefault(type => SymbolEqualityComparer.Default.Equals(type.OriginalDefinition, dictionaryDefinition)); - if (dictionary is not null) + if (description.Dictionary is { } dictionary) { Report(method, dictionary, "dictionary comparers are selected per value and require an explicit closed registration preserving the comparer contract"); continue; @@ -160,14 +150,13 @@ internal static ImmutableArray Generate( } else { - if (!options.ValidateRpcResponseFactories && resultType is INamedTypeSymbol named - && SerializerFactoryGenerator.CreateRpcModelRoot(services, named, cancellationToken) is { } metadataRoot) + if (!options.ValidateRpcResponseFactories && description.ModelRoot is { } metadataRoot) { metadataModelRoots.Add(metadataRoot); continue; } - Report(method, failure.Type, failure.Reason); + Report(method, description.Failure!.Type, description.Failure.Reason); } } @@ -197,7 +186,9 @@ internal static ImmutableArray Generate( } SerializerFactoryGenerator.Graph? graph = null; - if (supportedResults.Count > 0 && !SerializerFactoryGenerator.TryCreate(services, supportedResults.Select(type => responseDefinition.Construct(type)), cancellationToken, out graph, out var graphFailure, useDefaultFactories: true)) + if (supportedResults.Count > 0 && !SerializerFactoryGenerator.TryCombine(services, + supportedResults.Select(type => plan.Results[type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)].Graph!), + cancellationToken, out graph, out var graphFailure)) { output.Add(SourceOutputResult.FromDiagnostic(Diagnostic.Create( UnsupportedResponse, Location.None, compilation.AssemblyName, graphFailure.Type.ToDisplayString(), graphFailure.Reason))); @@ -218,7 +209,7 @@ internal static ImmutableArray Generate( source.AppendLine("{"); foreach (var holder in responseHolders) { - var name = proxyContext.RpcResponseNames[holder.Key.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)]; + var name = responseNames[holder.Key.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)]; var factory = name + "Factory"; var type = holder.Key.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); var resolve = $"{factory}.Resolve(provider)"; @@ -279,12 +270,11 @@ internal static ImmutableArray Generate( source.AppendLine("}"); foreach (var holder in responseHolders) { - var name = proxyContext.RpcResponseNames[holder.Key.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)]; + var name = responseNames[holder.Key.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)]; source.AppendLine(RpcResponseHolderGenerator.Generate(services, holder.Key, name, holder.Value.Codec, holder.Value.Copier)); } source.AppendLine("}"); var unit = CSharpSyntaxTree.ParseText(source.ToString(), - options: new CSharpParseOptions(preprocessorSymbols: ["NET5_0_OR_GREATER"]), cancellationToken: cancellationToken).GetCompilationUnitRoot(cancellationToken); var provider = unit.DescendantNodes().OfType() .Single(static declaration => declaration.Identifier.ValueText == "RpcResponseFactories"); @@ -313,9 +303,26 @@ void ReportArgument(IMethodSymbol method, ITypeSymbol argumentType, string reaso } } - private static bool ContainsTypeParameter(ITypeSymbol type) - => type is ITypeParameterSymbol or IErrorTypeSymbol - || type is IArrayTypeSymbol array && ContainsTypeParameter(array.ElementType) - || type is INamedTypeSymbol named && (named.TypeArguments.Any(ContainsTypeParameter) - || named.ContainingType is { } containing && ContainsTypeParameter(containing)); + private static ImmutableDictionary> GetConstructorServices( + ImmutableArray sources, CancellationToken cancellationToken) + { + var result = ImmutableDictionary.CreateBuilder>(StringComparer.Ordinal); + foreach (var source in sources) + { + if (source.SourceEntry is not { } entry) continue; + var root = CSharpSyntaxTree.ParseText(entry.SourceText, cancellationToken: cancellationToken).GetRoot(cancellationToken); + foreach (var proxy in root.DescendantNodes().OfType() + .Where(static declaration => declaration.Identifier.ValueText.StartsWith("Proxy_", StringComparison.Ordinal))) + { + var requests = proxy.Members.OfType() + .SelectMany(static constructor => constructor.DescendantNodes().OfType()) + .Where(static invocation => invocation.Expression is MemberAccessExpressionSyntax { Name: GenericNameSyntax { Identifier.ValueText: "GetService" } }) + .Select(static invocation => ((GenericNameSyntax)((MemberAccessExpressionSyntax)invocation.Expression).Name) + .TypeArgumentList.Arguments.Single()).ToImmutableArray(); + if (proxy.BaseList is not null) + foreach (var contract in proxy.BaseList.Types) result[contract.Type.ToString()] = requests; + } + } + return result.ToImmutable(); + } } diff --git a/src/Orleans.CodeGenerator/RpcResponseHolderGenerator.cs b/src/Orleans.CodeGenerator/RpcResponseHolderGenerator.cs index 9821d4a4478..b459e953678 100644 --- a/src/Orleans.CodeGenerator/RpcResponseHolderGenerator.cs +++ b/src/Orleans.CodeGenerator/RpcResponseHolderGenerator.cs @@ -1,52 +1,12 @@ using System.Collections.Immutable; using System.Globalization; using Microsoft.CodeAnalysis; -using Orleans.CodeGenerator.Model; using Orleans.CodeGenerator.SyntaxGeneration; namespace Orleans.CodeGenerator; internal static class RpcResponseHolderGenerator { - internal static ImmutableArray<(string TypeName, string HolderName)> GetNames( - Compilation compilation, - ImmutableArray proxies, - SourceGeneratorOptions options, - CancellationToken cancellationToken) - { - if (proxies.IsDefaultOrEmpty) - { - return []; - } - - var services = new GeneratorServices(compilation, SourceGeneratorOptionsParser.CreateCodeGeneratorOptions(options)); - var resolver = new TypeSymbolResolver(compilation); - var resultTypes = new HashSet(SymbolEqualityComparer.Default); - foreach (var proxy in proxies) - { - cancellationToken.ThrowIfCancellationRequested(); - if (!resolver.TryResolveProxyInterface(proxy, cancellationToken, out var interfaceType)) - { - continue; - } - - foreach (var method in interfaceType.GetDeclaredInstanceMembers() - .Concat(interfaceType.AllInterfaces.SelectMany(static type => type.GetDeclaredInstanceMembers()))) - { - if (method.MethodKind == MethodKind.Ordinary - && method.ReturnType is INamedTypeSymbol { TypeArguments.Length: 1 } returnType - && (SymbolEqualityComparer.Default.Equals(returnType.OriginalDefinition, services.LibraryTypes.Task_1) - || SymbolEqualityComparer.Default.Equals(returnType.OriginalDefinition, services.LibraryTypes.ValueTask_1))) - { - resultTypes.Add(returnType.TypeArguments[0].WithNullableAnnotation(NullableAnnotation.None)); - } - } - } - - return GetNames(resultTypes.Where(type => TryDescribe(services, type, out _, out _)) - .Select(static type => type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat))); - } - internal static ImmutableArray<(string TypeName, string HolderName)> GetNames(IEnumerable resultTypeNames) { var names = ImmutableArray.CreateBuilder<(string TypeName, string HolderName)>(); @@ -72,7 +32,7 @@ internal static string GetNamespace(Compilation compilation) internal static bool TryDescribe(IGeneratorServices services, ITypeSymbol resultType, out string codec, out string copier) { codec = copier = ""; - if (ContainsParameter(resultType)) return false; + if (RpcResponsePlan.ContainsTypeParameter(resultType)) return false; if (SerializerFactoryGenerator.TryCreate(services, [resultType], CancellationToken.None, out var graph, out _, useDefaultFactories: true)) { if (graph.Registrations.Keys.OfType().Any(type => @@ -174,12 +134,11 @@ public override void Dispose() internal sealed class {{factory}} : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec<{{name}}>, - global::Orleans.Serialization.Cloning.IDeepCopier<{{name}}>, - global::Orleans.Serialization.Invocation.IRawResponseReader + global::Orleans.Serialization.Cloning.IDeepCopier<{{name}}> { private readonly {{codec}} _codec; private readonly {{copier}} _copier; - public bool IsSupported { get; } + public override bool IsSupported { get; } internal static {{factory}} Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { provider.GetCodec<{{type}}>(); @@ -218,9 +177,6 @@ public override void WriteRaw(ref global::Orleans.Serialization.B => WriteResult(ref writer, (({{name}})value).Value); public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw( - ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) - => ReadResult(ref reader, ref field); private {{name}} ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) { field.EnsureWireTypeTagDelimited(); @@ -266,9 +222,4 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. """; } - private static bool ContainsParameter(ITypeSymbol type) - => type is ITypeParameterSymbol or IErrorTypeSymbol - || type is IArrayTypeSymbol array && ContainsParameter(array.ElementType) - || type is INamedTypeSymbol named && (named.TypeArguments.Any(ContainsParameter) - || named.ContainingType is { } containing && ContainsParameter(containing)); } diff --git a/src/Orleans.CodeGenerator/RpcResponsePlan.cs b/src/Orleans.CodeGenerator/RpcResponsePlan.cs new file mode 100644 index 00000000000..ee1255f9ea5 --- /dev/null +++ b/src/Orleans.CodeGenerator/RpcResponsePlan.cs @@ -0,0 +1,100 @@ +using System.Collections.Immutable; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Orleans.CodeGenerator.Model; +using Orleans.CodeGenerator.SyntaxGeneration; + +namespace Orleans.CodeGenerator; + +internal sealed class RpcResponsePlan +{ + internal sealed record Result( + ITypeSymbol Type, + string? Codec, + string? Copier, + SerializerFactoryGenerator.Graph? Graph, + SerializerFactoryGenerator.Graph? ModelRoot, + SerializerFactoryGenerator.Failure? Failure, + ITypeSymbol? Dictionary); + + private RpcResponsePlan(ImmutableArray results) + { + Results = results.ToImmutableDictionary(static result => result.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat), + StringComparer.Ordinal); + Names = RpcResponseHolderGenerator.GetNames(results.Where(static result => result.Codec is not null) + .Select(static result => result.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat))); + } + + internal ImmutableDictionary Results { get; } + internal ImmutableArray<(string TypeName, string HolderName)> Names { get; } + + internal static RpcResponsePlan Create(Compilation compilation, ImmutableArray proxies, + SourceGeneratorOptions options, CancellationToken cancellationToken) + { + if (proxies.IsDefaultOrEmpty) return new([]); + compilation = WithBindingTree(compilation); + var services = new GeneratorServices(compilation, SourceGeneratorOptionsParser.CreateCodeGeneratorOptions(options)); + var resolver = new TypeSymbolResolver(compilation); + var types = new HashSet(SymbolEqualityComparer.Default); + foreach (var proxy in proxies) + { + cancellationToken.ThrowIfCancellationRequested(); + if (!resolver.TryResolveProxyInterface(proxy, cancellationToken, out var interfaceType)) continue; + foreach (var method in interfaceType.GetDeclaredInstanceMembers() + .Concat(interfaceType.AllInterfaces.SelectMany(static type => type.GetDeclaredInstanceMembers()))) + { + if (method.MethodKind == MethodKind.Ordinary && method.ReturnType is INamedTypeSymbol { TypeArguments.Length: 1 } returnType + && (SymbolEqualityComparer.Default.Equals(returnType.OriginalDefinition, services.LibraryTypes.Task_1) + || SymbolEqualityComparer.Default.Equals(returnType.OriginalDefinition, services.LibraryTypes.ValueTask_1))) + types.Add(returnType.TypeArguments[0].WithNullableAnnotation(NullableAnnotation.None)); + } + } + + var responseDefinition = compilation.GetTypeByMetadataName("Orleans.Serialization.Invocation.Response`1")!; + var dictionaryDefinition = compilation.GetTypeByMetadataName("System.Collections.Generic.Dictionary`2"); + var results = ImmutableArray.CreateBuilder(); + foreach (var type in types.OrderBy(static type => type.ToDisplayString(), StringComparer.Ordinal)) + { + if (ContainsTypeParameter(type)) continue; + if (SerializerFactoryGenerator.TryCreate(services, [responseDefinition.Construct(type)], cancellationToken, + out var graph, out var failure, useDefaultFactories: true)) + { + var dictionary = graph.Registrations.Keys.OfType().FirstOrDefault(candidate => + SymbolEqualityComparer.Default.Equals(candidate.OriginalDefinition, dictionaryDefinition)); + var registration = graph.Registrations[type]; + results.Add(new(type, dictionary is null ? registration.Codec : null, + dictionary is null ? registration.Copier : null, graph, null, null, dictionary)); + } + else + { + SerializerFactoryGenerator.Graph? modelRoot = type is INamedTypeSymbol named + ? SerializerFactoryGenerator.CreateRpcModelRoot(services, named, cancellationToken) : null; + string? codec = null; + string? copier = null; + if (modelRoot is not null && (SymbolEqualityComparer.Default.Equals(type.ContainingAssembly, compilation.Assembly) + || compilation.GetTypeByMetadataName($"{SerializerGenerator.GetGeneratedNamespaceName((INamedTypeSymbol)type)}.{SerializerGenerator.GetSimpleClassName(type.Name)}") is not null)) + { + codec = modelRoot.Registrations[type].Codec; + copier = modelRoot.Registrations[type].Copier; + } + else if (RpcResponseHolderGenerator.TryDescribe(services, type, out var availableCodec, out var availableCopier)) + { + codec = availableCodec; + copier = availableCopier; + } + results.Add(new(type, codec, copier, null, modelRoot, failure, null)); + } + } + return new(results.ToImmutable()); + } + + internal static Compilation WithBindingTree(Compilation compilation) + => compilation.SyntaxTrees.Any() ? compilation + : compilation.AddSyntaxTrees(CSharpSyntaxTree.Create(SyntaxFactory.CompilationUnit())); + + internal static bool ContainsTypeParameter(ITypeSymbol type) + => type is ITypeParameterSymbol or IErrorTypeSymbol + || type is IArrayTypeSymbol array && ContainsTypeParameter(array.ElementType) + || type is INamedTypeSymbol named && (named.TypeArguments.Any(ContainsTypeParameter) + || named.ContainingType is { } containing && ContainsTypeParameter(containing)); +} diff --git a/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs b/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs index de9811e6abf..0339e57edef 100644 --- a/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs +++ b/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs @@ -1,4 +1,5 @@ using System.Text; +using System.Collections.Immutable; using System.Diagnostics.CodeAnalysis; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; @@ -23,6 +24,18 @@ internal sealed class Registration(ITypeSymbol type) public INamedTypeSymbol? ReferencedCodec { get; set; } public INamedTypeSymbol? ReferencedCopier { get; set; } public List CanonicalArrays { get; } = []; + + internal Registration Clone() + { + var result = new Registration(Type) + { + Codec = Codec, Copier = Copier, CodecConstruction = CodecConstruction, CopierConstruction = CopierConstruction, + Model = Model, ResponseResult = ResponseResult, ReferencedCodec = ReferencedCodec, ReferencedCopier = ReferencedCopier + }; + result.Dependencies.AddRange(Dependencies); + result.CanonicalArrays.AddRange(CanonicalArrays); + return result; + } } internal sealed class Graph(IReadOnlyDictionary registrations, string configurationStatements) @@ -33,6 +46,70 @@ internal sealed class Graph(IReadOnlyDictionary regis internal sealed record Failure(ITypeSymbol Type, string Reason); + private sealed record ServiceConstruction(string Implementation, string Expression, ImmutableArray Dependencies) + { + internal static ServiceConstruction Create(string implementation, string expression, IEnumerable dependencies) + => new(implementation, expression, [.. dependencies + .Where(static type => type != "global::Orleans.Serialization.Serializers.ICodecProvider") + .Distinct(StringComparer.Ordinal)]); + } + + private static void AppendService(StringBuilder source, ServiceConstruction construction, bool useDefaults, + string? service = null, bool describeEmptyDependencies = false) + { + source.Append("options.").Append(useDefaults ? "AddDefaultSerializerService" : "AddSerializerService") + .Append('<').Append(service ?? construction.Implementation); + if (useDefaults && service is not null) source.Append(", ").Append(construction.Implementation); + source.Append(">(static provider => ").Append(service is null ? construction.Expression : Resolve(construction.Implementation)); + if (useDefaults && (describeEmptyDependencies || !construction.Dependencies.IsEmpty)) + source.Append(", dependencies: ").Append(DefaultServiceDependencies(construction.Dependencies)); + source.AppendLine(");"); + } + + private static void AppendRegistration(StringBuilder source, string type, ServiceConstruction codec, ServiceConstruction copier, + bool useDefaults, bool servicesOnly = false, bool describeEmptyDependencies = false) + { + AppendService(source, codec, useDefaults, describeEmptyDependencies: describeEmptyDependencies); + AppendService(source, copier, useDefaults, describeEmptyDependencies: describeEmptyDependencies); + if (servicesOnly) + { + AppendService(source, codec, useDefaults, $"global::Orleans.Serialization.Codecs.IFieldCodec<{type}>", describeEmptyDependencies); + AppendService(source, copier, useDefaults, $"global::Orleans.Serialization.Cloning.IDeepCopier<{type}>", describeEmptyDependencies); + return; + } + source.Append("options.").Append(useDefaults ? "AddDefaultSerializer" : "AddSerializer").Append('<').Append(type); + if (useDefaults) source.Append(", ").Append(codec.Implementation).Append(", ").Append(copier.Implementation); + source.Append(">(static provider => ").Append(Resolve(codec.Implementation)) + .Append(", static provider => ").Append(Resolve(copier.Implementation)); + if (useDefaults && (describeEmptyDependencies || !codec.Dependencies.IsEmpty || !copier.Dependencies.IsEmpty)) + source.Append(", codecDependencies: ").Append(DefaultServiceDependencies(codec.Dependencies)) + .Append(", copierDependencies: ").Append(DefaultServiceDependencies(copier.Dependencies)); + source.AppendLine(");"); + } + + private static void AppendReferencedRegistration(StringBuilder source, ITypeSymbol type, INamedTypeSymbol codec, INamedTypeSymbol copier, + bool preferCompleteCodecConstructor = false) + => AppendRegistration(source, Name(type), + ServiceConstruction.Create(Name(codec), ConstructReferenced(Name(codec), codec, preferCompleteCodecConstructor), + ConstructorDependencies(codec, preferCompleteCodecConstructor)), + ServiceConstruction.Create(Name(copier), ConstructReferenced(Name(copier), copier), ConstructorDependencies(copier)), + useDefaults: true, describeEmptyDependencies: true); + + private static void AppendArgumentMetadata(StringBuilder source, ITypeSymbol type, HashSet registered, Compilation compilation) + { + if (!registered.Add(type) || RpcResponsePlan.ContainsTypeParameter(type) + || !compilation.IsSymbolAccessibleWithin(type, compilation.Assembly)) return; + source.Append("options.AddGenericArgumentMetadata(typeof(").Append(Name(type)).AppendLine("));"); + if (type is INamedTypeSymbol named) + { + foreach (var argument in named.TypeArguments) AppendArgumentMetadata(source, argument, registered, compilation); + } + else if (type is IArrayTypeSymbol array) + { + AppendArgumentMetadata(source, array.ElementType, registered, compilation); + } + } + internal static Graph? CreateRpcModelRoot( IGeneratorServices services, INamedTypeSymbol type, @@ -58,6 +135,8 @@ internal sealed record Failure(ITypeSymbol Type, string Reason); } var registration = new Registration(type); + var argumentMetadata = new StringBuilder(); + AppendArgumentMetadata(argumentMetadata, type, new(SymbolEqualityComparer.Default), services.Compilation); var inspectionCompilation = services.Compilation; var inspectionType = type; var inspectionLibrary = services.LibraryTypes; @@ -169,7 +248,7 @@ internal sealed record Failure(ITypeSymbol Type, string Reason); var responseType = services.Compilation.GetTypeByMetadataName("Orleans.Serialization.Invocation.Response`1")!.Construct(type); var codec = $"global::Orleans.Serialization.Invocation.PooledResponseCodec<{Name(type)}, {registration.Codec}>"; var copier = $"global::Orleans.Serialization.Invocation.PooledResponseCopier<{Name(type)}, {registration.Copier}>"; - var result = new StringBuilder(); + var result = new StringBuilder(argumentMetadata.ToString()); foreach (var member in constructionModel.Members) { var memberName = Name(member.Type); @@ -220,42 +299,23 @@ internal sealed record Failure(ITypeSymbol Type, string Reason); .Append(factory).Append('<').Append(Name(type)).AppendLine(">());"); } - result.Append("options.AddDefaultSerializerService<").Append(registration.Codec).Append(">(static provider => ") - .Append(registration.CodecConstruction) - .Append(", dependencies: ").Append(DefaultServiceDependencies(codecDependencies)).AppendLine(");"); - result.Append("options.AddDefaultSerializerService<").Append(registration.Copier).Append(">(static provider => ") - .Append(registration.CopierConstruction) - .Append(", dependencies: ").Append(DefaultServiceDependencies(copierDependencies)).AppendLine(");"); - result.Append("options.AddDefaultSerializerService, ").Append(registration.Codec).Append(">(static provider => ") - .Append(Resolve(registration.Codec)) - .Append(", dependencies: ").Append(DefaultServiceDependencies(codecDependencies)).AppendLine(");"); - result.Append("options.AddDefaultSerializerService, ").Append(registration.Copier).Append(">(static provider => ") - .Append(Resolve(registration.Copier)) - .Append(", dependencies: ").Append(DefaultServiceDependencies(copierDependencies)).AppendLine(");"); + var codecConstruction = ServiceConstruction.Create(registration.Codec, registration.CodecConstruction, codecDependencies); + var copierConstruction = ServiceConstruction.Create(registration.Copier, registration.CopierConstruction, copierDependencies); + AppendRegistration(result, Name(type), codecConstruction, copierConstruction, useDefaults: true, servicesOnly: true, describeEmptyDependencies: true); if (type.IsValueType && type.TypeKind != TypeKind.Enum) { - result.Append("options.AddDefaultSerializerService, ").Append(registration.Codec).Append(">(static provider => ") - .Append(Resolve(registration.Codec)) - .Append(", dependencies: ").Append(DefaultServiceDependencies(codecDependencies)).AppendLine(");"); + AppendService(result, codecConstruction, useDefaults: true, + $"global::Orleans.Serialization.Serializers.IValueSerializer<{Name(type)}>", describeEmptyDependencies: true); } if (!includeResponse) { return new Graph(new Dictionary(SymbolEqualityComparer.Default) { [type] = registration }, result.ToString()); } - result.Append("options.AddDefaultSerializerService<").Append(codec).Append(">(static provider => new ") - .Append(codec).Append("(caller => ").Append(Resolve(registration.Codec, "caller")) - .Append("), dependencies: ").Append(DefaultServiceDependencies([registration.Codec])).AppendLine(");"); - result.Append("options.AddDefaultSerializerService<").Append(copier).Append(">(static provider => new ") - .Append(copier).Append("(caller => ").Append(Resolve(registration.Copier, "caller")) - .Append("), dependencies: ").Append(DefaultServiceDependencies([registration.Copier])).AppendLine(");"); - result.Append("options.AddDefaultSerializer<").Append(Name(responseType)).Append(", ").Append(codec).Append(", ").Append(copier).Append(">(static provider => ") - .Append(Resolve(codec)).Append(", static provider => ").Append(Resolve(copier)) - .Append(", codecDependencies: ").Append(DefaultServiceDependencies([registration.Codec])) - .Append(", copierDependencies: ").Append(DefaultServiceDependencies([registration.Copier])).AppendLine(");"); + AppendRegistration(result, Name(responseType), + ServiceConstruction.Create(codec, $"new {codec}(caller => {Resolve(registration.Codec, "caller")})", [registration.Codec]), + ServiceConstruction.Create(copier, $"new {copier}(caller => {Resolve(registration.Copier, "caller")})", [registration.Copier]), + useDefaults: true, describeEmptyDependencies: true); result.Append("options.AddAllowedType(typeof(").Append(Name(responseType)).AppendLine("));"); return new Graph(new Dictionary(SymbolEqualityComparer.Default) { [type] = registration }, result.ToString()); @@ -303,16 +363,7 @@ private static void AppendConstructionDependency(IGeneratorServices services, IT if (dependency is INamedTypeSymbol tupleType && TryGetTupleServices(services, tupleType, out var tupleCodec, out var tupleCopier)) { foreach (var element in tupleType.TypeArguments) AppendConstructionDependency(services, element, cancellationToken, constructionTypes, result); - result.Append("options.AddDefaultSerializerService<").Append(Name(tupleCodec)).Append(">(static provider => ") - .Append(ConstructReferenced(Name(tupleCodec), tupleCodec)) - .Append(", dependencies: ").Append(DefaultServiceDependencies(ConstructorDependencies(tupleCodec))).AppendLine(");"); - result.Append("options.AddDefaultSerializerService<").Append(Name(tupleCopier)).Append(">(static provider => ") - .Append(ConstructReferenced(Name(tupleCopier), tupleCopier)) - .Append(", dependencies: ").Append(DefaultServiceDependencies(ConstructorDependencies(tupleCopier))).AppendLine(");"); - result.Append("options.AddDefaultSerializer<").Append(Name(tupleType)).Append(", ").Append(Name(tupleCodec)).Append(", ").Append(Name(tupleCopier)).Append(">(static provider => ") - .Append(Resolve(Name(tupleCodec))).Append(", static provider => ").Append(Resolve(Name(tupleCopier))) - .Append(", codecDependencies: ").Append(DefaultServiceDependencies(ConstructorDependencies(tupleCodec))) - .Append(", copierDependencies: ").Append(DefaultServiceDependencies(ConstructorDependencies(tupleCopier))).AppendLine(");"); + AppendReferencedRegistration(result, tupleType, tupleCodec, tupleCopier); return; } @@ -321,16 +372,7 @@ private static void AppendConstructionDependency(IGeneratorServices services, IT AppendConstructionDependency(services, arrayType.ElementType, cancellationToken, constructionTypes, result); var codec = services.LibraryTypes.ArrayCodec.Construct(arrayType.ElementType); var copier = services.LibraryTypes.ArrayCopier.Construct(arrayType.ElementType); - result.Append("options.AddDefaultSerializerService<").Append(Name(codec)).Append(">(static provider => ") - .Append(ConstructReferenced(Name(codec), codec)) - .Append(", dependencies: ").Append(DefaultServiceDependencies(ConstructorDependencies(codec))).AppendLine(");"); - result.Append("options.AddDefaultSerializerService<").Append(Name(copier)).Append(">(static provider => ") - .Append(ConstructReferenced(Name(copier), copier)) - .Append(", dependencies: ").Append(DefaultServiceDependencies(ConstructorDependencies(copier))).AppendLine(");"); - result.Append("options.AddDefaultSerializer<").Append(Name(arrayType)).Append(", ").Append(Name(codec)).Append(", ").Append(Name(copier)).Append(">(static provider => ") - .Append(Resolve(Name(codec))).Append(", static provider => ").Append(Resolve(Name(copier))) - .Append(", codecDependencies: ").Append(DefaultServiceDependencies(ConstructorDependencies(codec))) - .Append(", copierDependencies: ").Append(DefaultServiceDependencies(ConstructorDependencies(copier))).AppendLine(");"); + AppendReferencedRegistration(result, arrayType, codec, copier); return; } @@ -347,16 +389,7 @@ private static void AppendConstructionDependency(IGeneratorServices services, IT || SymbolEqualityComparer.Default.Equals(contract.OriginalDefinition, services.LibraryTypes.ValueSerializer))) AppendConstructionDependency(services, contract.TypeArguments[0], cancellationToken, constructionTypes, result); } - result.Append("options.AddDefaultSerializerService<").Append(Name(codec)).Append(">(static provider => ") - .Append(ConstructReferenced(Name(codec), codec, preferCompleteConstructor: true)) - .Append(", dependencies: ").Append(DefaultServiceDependencies(ConstructorDependencies(codec, preferCompleteConstructor: true))).AppendLine(");"); - result.Append("options.AddDefaultSerializerService<").Append(Name(copier)).Append(">(static provider => ") - .Append(ConstructReferenced(Name(copier), copier)) - .Append(", dependencies: ").Append(DefaultServiceDependencies(ConstructorDependencies(copier))).AppendLine(");"); - result.Append("options.AddDefaultSerializer<").Append(Name(collection)).Append(", ").Append(Name(codec)).Append(", ").Append(Name(copier)).Append(">(static provider => ") - .Append(Resolve(Name(codec))).Append(", static provider => ").Append(Resolve(Name(copier))) - .Append(", codecDependencies: ").Append(DefaultServiceDependencies(ConstructorDependencies(codec, preferCompleteConstructor: true))) - .Append(", copierDependencies: ").Append(DefaultServiceDependencies(ConstructorDependencies(copier))).AppendLine(");"); + AppendReferencedRegistration(result, collection, codec, copier, preferCompleteCodecConstructor: true); return; } @@ -433,17 +466,50 @@ internal static bool TryCreate( foreach (var dependency in registration.Dependencies) pending.Enqueue(dependency); } + return TryBuildGraph(services, registrations, implementationCompilation, cancellationToken, out graph, out failure, useDefaultFactories); + } + + internal static bool TryCombine(IGeneratorServices services, IEnumerable graphs, CancellationToken cancellationToken, + [NotNullWhen(true)] out Graph? graph, [NotNullWhen(false)] out Failure? failure) + { + var registrations = new Dictionary(SymbolEqualityComparer.Default); + foreach (var candidate in graphs) + { + foreach (var entry in candidate.Registrations) + { + if (registrations.ContainsKey(entry.Key)) continue; + if (registrations.Count >= 1024) + { + graph = null; + failure = new(entry.Key, "the dependency graph exceeds 1024 closed types; declare a finite serialization graph"); + return false; + } + registrations.Add(entry.Key, entry.Value.Clone()); + } + } + var compilation = services.Compilation.WithOptions(services.Compilation.Options.WithMetadataImportOptions(MetadataImportOptions.All)); + return TryBuildGraph(services, registrations, compilation, cancellationToken, out graph, out failure, useDefaultFactories: true); + } + + private static bool TryBuildGraph(IGeneratorServices services, Dictionary registrations, + Compilation implementationCompilation, CancellationToken cancellationToken, + [NotNullWhen(true)] out Graph? graph, [NotNullWhen(false)] out Failure? failure, bool useDefaultFactories) + { + graph = null; + failure = null; var serializerGenerator = new SerializerGenerator(services); var copierGenerator = new CopierGenerator(services); var result = new StringBuilder(); foreach (var registration in registrations.Values) ResolveResponseImplementations(registration); var addService = useDefaultFactories ? "AddDefaultSerializerService" : "AddSerializerService"; - var addSerializer = useDefaultFactories ? "AddDefaultSerializer" : "AddSerializer"; var metadataTypes = new HashSet(SymbolEqualityComparer.Default); + var argumentTypes = new HashSet(SymbolEqualityComparer.Default); var auxiliaryServices = new HashSet(StringComparer.Ordinal); foreach (var registration in registrations.Values.OrderBy(value => Name(value.Type), StringComparer.Ordinal)) { + cancellationToken.ThrowIfCancellationRequested(); + AppendArgumentMetadata(result, registration.Type, argumentTypes, services.Compilation); var typeName = Name(registration.Type); var hasBaseCodec = false; var hasBaseCopier = false; @@ -516,53 +582,23 @@ internal static bool TryCreate( registration.CopierConstruction = $"new {registration.Copier}({string.Join(", ", copierArguments)})"; } - result.Append("options.").Append(addService).Append('<').Append(registration.Codec).Append(">(static provider => ") - .Append(registration.CodecConstruction); - if (useDefaultFactories && codecDependencies.Count > 0) - result.Append(", dependencies: ").Append(DefaultServiceDependencies(codecDependencies)); - result.AppendLine(");"); - result.Append("options.").Append(addService).Append('<').Append(registration.Copier).Append(">(static provider => ") - .Append(registration.CopierConstruction); - if (useDefaultFactories && copierDependencies.Count > 0) - result.Append(", dependencies: ").Append(DefaultServiceDependencies(copierDependencies)); - result.AppendLine(");"); - result.Append("options.").Append(addSerializer).Append('<').Append(typeName); - if (useDefaultFactories) - result.Append(", ").Append(registration.Codec).Append(", ").Append(registration.Copier); - result.Append(">(static provider => ") - .Append(Resolve(registration.Codec)).Append(", static provider => ").Append(Resolve(registration.Copier)); - if (useDefaultFactories && (codecDependencies.Count > 0 || copierDependencies.Count > 0)) - { - result.Append(", codecDependencies: ").Append(DefaultServiceDependencies(codecDependencies)) - .Append(", copierDependencies: ").Append(DefaultServiceDependencies(copierDependencies)); - } - result.AppendLine(");"); + var codecConstruction = ServiceConstruction.Create(registration.Codec, registration.CodecConstruction, codecDependencies); + var copierConstruction = ServiceConstruction.Create(registration.Copier, registration.CopierConstruction, copierDependencies); + AppendRegistration(result, typeName, codecConstruction, copierConstruction, useDefaultFactories); if (registration.Model is { IsValueType: true, IsEnumType: false }) { - result.Append("options.").Append(addService).Append("'); - if (useDefaultFactories) result.Append(", ").Append(registration.Codec); - result.Append(">(static provider => ").Append(Resolve(registration.Codec)).AppendLine(");"); + AppendService(result, codecConstruction with { Dependencies = [] }, useDefaultFactories, + $"global::Orleans.Serialization.Serializers.IValueSerializer<{typeName}>"); } if (hasBaseCodec) { - result.Append("options.").Append(addService).Append("'); - if (useDefaultFactories) result.Append(", ").Append(registration.Codec); - result.Append(">(static provider => ").Append(Resolve(registration.Codec)); - if (useDefaultFactories) - result.Append(", dependencies: ").Append(DefaultServiceDependencies(codecDependencies)); - result.AppendLine(");"); + AppendService(result, codecConstruction, useDefaultFactories, + $"global::Orleans.Serialization.Serializers.IBaseCodec<{typeName}>", describeEmptyDependencies: true); } if (hasBaseCopier) { - result.Append("options.").Append(addService).Append("'); - if (useDefaultFactories) result.Append(", ").Append(registration.Copier); - result.Append(">(static provider => ").Append(Resolve(registration.Copier)); - if (useDefaultFactories) - result.Append(", dependencies: ").Append(DefaultServiceDependencies(copierDependencies)); - result.AppendLine(");"); + AppendService(result, copierConstruction, useDefaultFactories, + $"global::Orleans.Serialization.Cloning.IBaseCopier<{typeName}>", describeEmptyDependencies: true); } foreach (var array in registration.CanonicalArrays) diff --git a/src/Orleans.Core/Core/ResponseCopyBoundary.cs b/src/Orleans.Core/Core/ResponseCopyBoundary.cs index 2bb3eaff31a..2384391c503 100644 --- a/src/Orleans.Core/Core/ResponseCopyBoundary.cs +++ b/src/Orleans.Core/Core/ResponseCopyBoundary.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Orleans.Serialization; using Orleans.Serialization.Cloning; +using Orleans.Serialization.GeneratedCodeHelpers; using Orleans.Serialization.Invocation; using Orleans.Serialization.Serializers; @@ -22,28 +23,8 @@ private static async ValueTask InvokeLegacy(IInvokable request, DeepCo => CopyAndDispose(await request.Invoke(), responseCopier); internal static Response CopyAndDispose(Response response, DeepCopier copier) - { - Response? copy = null; - try - { - return copy = copier.Copy(response)!; - } - finally - { - if (!ReferenceEquals(response, copy)) response.Dispose(); - } - } + => OrleansGeneratedCodeHelper.CopyResponseAndDispose(response, copier); internal static Response CopyAndDispose(Response response, DeepCopier copier) - { - Response? copy = null; - try - { - return copy = copier.Copy(response)!; - } - finally - { - if (!ReferenceEquals(response, copy)) response.Dispose(); - } - } + => OrleansGeneratedCodeHelper.CopyResponseAndDispose(response, copier); } diff --git a/src/Orleans.Core/Messaging/MessageSerializer.cs b/src/Orleans.Core/Messaging/MessageSerializer.cs index bdb21fd0d69..e757212cedf 100644 --- a/src/Orleans.Core/Messaging/MessageSerializer.cs +++ b/src/Orleans.Core/Messaging/MessageSerializer.cs @@ -20,7 +20,6 @@ internal sealed class MessageSerializer : IDisposable private const int FramingLength = Message.LENGTH_HEADER_SIZE; private const int MessageSizeHint = 4096; private const int MaxRequestContextInitialCapacity = 1024; - private readonly Dictionary _rawResponseCodecs = []; private readonly Dictionary _rawResponseReaders = []; private readonly CodecProvider _codecProvider; private readonly IFieldCodec _activationAddressCodec; @@ -86,17 +85,13 @@ internal void ReadBodyObject(Message message, MessageReadRequest readRequest) { message.Result = ResponseTypes.None; // reset raw response indicator var fieldType = field.FieldType!; - if (!_rawResponseReaders.TryGetValue(fieldType, out var registered) - && _codecProvider.TryGetRawResponseReader(fieldType, out registered)) - _rawResponseReaders.Add(fieldType, registered); - if (registered is not null) + if (!_rawResponseReaders.TryGetValue(fieldType, out var registered)) { - message._bodyObject = registered.ReadRaw(ref reader, ref field); - return; + registered = _codecProvider.TryGetRawResponseReader(fieldType, out var generated) + ? generated : GetRawCodec(fieldType); + _rawResponseReaders.Add(fieldType, registered); } - if (!_rawResponseCodecs.TryGetValue(field.FieldType!, out var rawCodec)) - rawCodec = GetRawCodec(field.FieldType!); - message._bodyObject = rawCodec.ReadRaw(ref reader, ref field); + message._bodyObject = registered.ReadRaw(ref reader, ref field); } else { @@ -113,7 +108,6 @@ internal void ReadBodyObject(Message message, MessageReadRequest readRequest) private ResponseCodec GetRawCodec(Type fieldType) { var rawCodec = (ResponseCodec)_codecProvider.GetCodec(typeof(Response<>).MakeGenericType(fieldType)); - _rawResponseCodecs.Add(fieldType, rawCodec); return rawCodec; } diff --git a/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs b/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs index 22d3116dc08..f9235ad95e2 100644 --- a/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs +++ b/src/Orleans.Serialization/Configuration/TypeManifestOptions.cs @@ -44,16 +44,55 @@ public sealed class TypeManifestOptions internal Dictionary> CopierContracts { get; } = new(); internal Dictionary> ActivatorContracts { get; } = new(); internal Dictionary> ConverterContracts { get; } = new(); + internal Dictionary GenericArgumentMetadata { get; } = new(); + internal sealed record ClosedTypeMetadata(bool HasPublicParameterlessConstructor, Type[] Interfaces); - internal Dictionary> CodecFactories { get; } = new(); - internal Dictionary> CopierFactories { get; } = new(); - internal Dictionary CodecFactoryServices { get; } = new(); - internal Dictionary CopierFactoryServices { get; } = new(); + /// + /// Captures the metadata needed to validate a closed type used as a serialization implementation's generic argument. + /// + /// The source-known closed type. + /// + /// Register every closed argument, including nested generic arguments and array elements, which can participate + /// in a constrained implementation. This permits constraint validation without constructing a generic type. + /// Implemented interfaces and their ancestors are captured from this type's interface metadata and do not + /// require separate registrations. + /// Variant comparisons which traverse a constructed constraint's inherited interfaces also require metadata + /// for that closed constraint type, either captured from a registered type's interfaces or explicitly registered. + /// + /// is null. + /// contains unbound generic parameters. + public void AddGenericArgumentMetadata( +#if NET5_0_OR_GREATER + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] +#endif + Type type) + { + if (type is null) throw new ArgumentNullException(nameof(type)); + if (type.ContainsGenericParameters) throw new ArgumentException("Generic argument metadata requires a closed type.", nameof(type)); + if (GenericArgumentMetadata.ContainsKey(type)) return; + var interfaces = type.GetInterfaces(); + GenericArgumentMetadata.Add(type, new( + type.IsValueType || type.GetConstructor(Type.EmptyTypes) is not null, + interfaces)); + foreach (var implemented in interfaces) + { + if (GenericArgumentMetadata.ContainsKey(implemented)) continue; + var ancestors = new List(); + foreach (var candidate in interfaces) + { + if (candidate != implemented && candidate.IsAssignableFrom(implemented)) ancestors.Add(candidate); + } + + GenericArgumentMetadata.Add(implemented, new(false, ancestors.ToArray())); + } + } + + internal Dictionary> CodecFactories { get; } = new(); + internal Dictionary> CopierFactories { get; } = new(); internal Dictionary> SerializerServiceFactories { get; } = new(); internal Dictionary DefaultSerializerContracts { get; } = new(); internal Dictionary> DefaultSerializerImplementationServices { get; } = new(); - internal Dictionary DefaultCodecFactoryContracts { get; } = new(); - internal Dictionary DefaultCopierFactoryContracts { get; } = new(); + internal sealed record ClosedSerializerFactory(Type ServiceType, Func Factory); internal Dictionary> RawResponseReaderFactories { get; } = new(); /// @@ -130,12 +169,10 @@ public void AddDefaultSerializer( if (registerCodec) { RegisterDefaultContract(typeof(IFieldCodec), typeof(TCodec), compatibleCodecType, codecDependencies); - DefaultCodecFactoryContracts.TryAdd(typeof(T), DefaultSerializerContracts[typeof(IFieldCodec)]); } if (registerCopier) { RegisterDefaultContract(typeof(IDeepCopier), typeof(TCopier), compatibleCopierType, copierDependencies); - DefaultCopierFactoryContracts.TryAdd(typeof(T), DefaultSerializerContracts[typeof(IDeepCopier)]); } } @@ -146,18 +183,12 @@ private void RegisterSerializerFactories( { if (codecFactory is null) throw new ArgumentNullException(nameof(codecFactory)); if (copierFactory is null) throw new ArgumentNullException(nameof(copierFactory)); - CodecFactories.TryAdd(typeof(T), static provider => - Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null!, provider)); - CopierFactories.TryAdd(typeof(T), static provider => - Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null!, provider)); - CodecFactoryServices.TryAdd(typeof(T), typeof(IFieldCodec)); - CopierFactoryServices.TryAdd(typeof(T), typeof(IDeepCopier)); + CodecFactories.TryAdd(typeof(T), new(typeof(IFieldCodec), static provider => + Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null!, provider))); + CopierFactories.TryAdd(typeof(T), new(typeof(IDeepCopier), static provider => + Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null!, provider))); AddSerializerServiceFactory(typeof(IFieldCodec), codecFactory, isDefault); AddSerializerServiceFactory(typeof(IDeepCopier), copierFactory, isDefault); - if (DefaultSerializerContracts.TryGetValue(typeof(IFieldCodec), out var codecContract)) - DefaultCodecFactoryContracts.TryAdd(typeof(T), codecContract); - if (DefaultSerializerContracts.TryGetValue(typeof(IDeepCopier), out var copierContract)) - DefaultCopierFactoryContracts.TryAdd(typeof(T), copierContract); ContextTypes.Add(typeof(T)); } diff --git a/src/Orleans.Serialization/GeneratedCodeHelpers/OrleansGeneratedCodeHelper.cs b/src/Orleans.Serialization/GeneratedCodeHelpers/OrleansGeneratedCodeHelper.cs index 162e01d1b88..769d5f3fe01 100644 --- a/src/Orleans.Serialization/GeneratedCodeHelpers/OrleansGeneratedCodeHelper.cs +++ b/src/Orleans.Serialization/GeneratedCodeHelpers/OrleansGeneratedCodeHelper.cs @@ -11,6 +11,7 @@ using Orleans.Serialization.Buffers; using Orleans.Serialization.Cloning; using Orleans.Serialization.Codecs; +using Orleans.Serialization.Invocation; using Orleans.Serialization.Serializers; using Orleans.Serialization.WireProtocol; @@ -21,6 +22,44 @@ namespace Orleans.Serialization.GeneratedCodeHelpers /// public static class OrleansGeneratedCodeHelper { + /// + /// Copies an invocation response and releases its original envelope when the copier returns a different response. + /// + /// The owned response to copy. + /// The selected response copier. + /// The response whose ownership is transferred to the caller. + public static Response CopyResponseAndDispose(Response response, DeepCopier copier) + { + ArgumentNullExceptionPolyfill.ThrowIfNull(copier); + return CopyResponseAndDispose(response, copier, static (value, service) => service.Copy(value)!); + } + + /// + /// Copies an invocation response using runtime-type dispatch and releases a superseded envelope. + /// + /// The owned response to copy. + /// The selected runtime-dispatch copier. + /// The response whose ownership is transferred to the caller. + public static Response CopyResponseAndDispose(Response response, DeepCopier copier) + { + ArgumentNullExceptionPolyfill.ThrowIfNull(copier); + return CopyResponseAndDispose(response, copier, static (value, service) => service.Copy(value)!); + } + + private static Response CopyResponseAndDispose(Response response, TCopier copier, Func copyResponse) + { + ArgumentNullExceptionPolyfill.ThrowIfNull(response); + Response? copy = null; + try + { + return copy = copyResponse(response, copier); + } + finally + { + if (!ReferenceEquals(response, copy)) response.Dispose(); + } + } + /// /// Creates the default activator for a statically specified reference type. /// diff --git a/src/Orleans.Serialization/Invocation/Response.cs b/src/Orleans.Serialization/Invocation/Response.cs index e7b9cd6f721..6197a819717 100644 --- a/src/Orleans.Serialization/Invocation/Response.cs +++ b/src/Orleans.Serialization/Invocation/Response.cs @@ -209,8 +209,16 @@ public override void Dispose() /// /// Supports raw serialization of values. /// - public abstract class ResponseCodec + public abstract class ResponseCodec : IRawResponseReader { + /// + /// Gets whether this codec supports raw response reading with the selected serialization services. + /// + public virtual bool IsSupported => true; + + Response IRawResponseReader.ReadRaw(ref Reader reader, scoped ref Field field) + => (Response)ReadRaw(ref reader, ref field); + /// /// Writes a response without a containing field header. /// diff --git a/src/Orleans.Serialization/Serializers/CodecProvider.cs b/src/Orleans.Serialization/Serializers/CodecProvider.cs index bb725b0c147..3ed78a827f4 100644 --- a/src/Orleans.Serialization/Serializers/CodecProvider.cs +++ b/src/Orleans.Serialization/Serializers/CodecProvider.cs @@ -256,7 +256,7 @@ void AddFromMetadata( public IFieldCodec? TryGetCodec() { var fieldType = typeof(TField); - if (_manifest.CodecFactories.TryGetValue(fieldType, out var factory) && IsDefaultCodecEligible(fieldType)) return (IFieldCodec)factory(this); + if (_manifest.CodecFactories.TryGetValue(fieldType, out var factory) && IsDefaultServiceEligible(factory.ServiceType)) return (IFieldCodec)factory.Factory(this); if (TryGetCached(_typedCodecs, fieldType, out var existing)) return (IFieldCodec)existing; @@ -284,7 +284,7 @@ public IFieldCodec GetCodec(Type fieldType) /// public IFieldCodec? TryGetCodec(Type fieldType) { - if (fieldType is not null && _manifest.CodecFactories.TryGetValue(fieldType, out var factory) && IsDefaultCodecEligible(fieldType)) return factory(this); + if (fieldType is not null && _manifest.CodecFactories.TryGetValue(fieldType, out var factory) && IsDefaultServiceEligible(factory.ServiceType)) return factory.Factory(this); // If the field type is unavailable, return the void codec which can at least handle references. return fieldType is null ? _voidCodec : TryGetCached(_untypedCodecs, fieldType, out var existing) ? existing @@ -299,7 +299,7 @@ public IFieldCodec GetCodec(Type fieldType) private IFieldCodec? TryCreateCodecInner(Type fieldType) { - if (_manifest.CodecFactories.TryGetValue(fieldType, out var factory) && IsDefaultCodecEligible(fieldType)) return factory(this); + if (_manifest.CodecFactories.TryGetValue(fieldType, out var factory) && IsDefaultServiceEligible(factory.ServiceType)) return factory.Factory(this); if (!_initialized) Initialize(); ThrowIfUnsupportedType(fieldType); @@ -441,7 +441,7 @@ public IDeepCopier GetDeepCopier() public IDeepCopier? TryGetDeepCopier() { var type = typeof(T); - if (_manifest.CopierFactories.TryGetValue(type, out var factory) && IsDefaultCopierEligible(type)) return (IDeepCopier)factory(this); + if (_manifest.CopierFactories.TryGetValue(type, out var factory) && IsDefaultServiceEligible(factory.ServiceType)) return (IDeepCopier)factory.Factory(this); if (TryGetCached(_typedCopiers, type, out var existing)) return (IDeepCopier)existing; @@ -469,7 +469,7 @@ public IDeepCopier GetDeepCopier(Type fieldType) /// public IDeepCopier? TryGetDeepCopier(Type fieldType) { - if (fieldType is not null && _manifest.CopierFactories.TryGetValue(fieldType, out var factory) && IsDefaultCopierEligible(fieldType)) return factory(this); + if (fieldType is not null && _manifest.CopierFactories.TryGetValue(fieldType, out var factory) && IsDefaultServiceEligible(factory.ServiceType)) return factory.Factory(this); // If the field type is unavailable, return the void copier which can at least handle references. return fieldType is null ? _voidCopier : TryGetCached(_untypedCopiers, fieldType, out var existing) ? existing @@ -485,7 +485,7 @@ public IDeepCopier GetDeepCopier(Type fieldType) private IDeepCopier? TryCreateCopierInner(Type fieldType) { - if (_manifest.CopierFactories.TryGetValue(fieldType, out var factory) && IsDefaultCopierEligible(fieldType)) return factory(this); + if (_manifest.CopierFactories.TryGetValue(fieldType, out var factory) && IsDefaultServiceEligible(factory.ServiceType)) return factory.Factory(this); if (!_initialized) Initialize(); ThrowIfUnsupportedType(fieldType); @@ -670,12 +670,6 @@ private object ActivateService(Type type, object[]? constructorArguments) return result; } - private bool IsDefaultCodecEligible(Type type) - => IsDefaultServiceEligible(_manifest.CodecFactoryServices[type]); - - private bool IsDefaultCopierEligible(Type type) - => IsDefaultServiceEligible(_manifest.CopierFactoryServices[type]); - // Inferred defaults preserve an automatic caller's DI boundary instead of starting a transaction inside it. private bool IsDefaultServiceEligible(Type service) => !_manifest.IsDefaultSerializerService(service) @@ -1262,7 +1256,7 @@ bool TrySelect(Type? key, [NotNullWhen(true)] out Type? result, out Serializatio } var closed = candidate.Implementation; - if (closed.IsGenericTypeDefinition && materializeImplementation) + if (closed.IsGenericTypeDefinition) { var arguments = bindings is null ? targetType.GetGenericArguments() : new Type[bindings.Length]; if (bindings is not null) @@ -1274,19 +1268,26 @@ bool TrySelect(Type? key, [NotNullWhen(true)] out Type? result, out Serializatio } } - if (arguments.Length != candidate.Implementation.GetGenericArguments().Length) + if (arguments.Length != closed.GetGenericArguments().Length) + ThrowResolutionFailure(new ArgumentException($"Serialization implementation {closed} has a different generic arity from target {targetType}.")); + var validation = GenericConstraintValidator.Validate(candidate.Implementation, arguments, _manifest.GenericArgumentMetadata); + if (validation == GenericConstraintValidationResult.Invalid) continue; + if (validation == GenericConstraintValidationResult.Unknown + && (!materializeImplementation || !RuntimeFeature.IsDynamicCodeSupported)) { - closed = ConstructGenericImplementation(candidate.Implementation, arguments); + throw new NotSupportedException( + $"Cannot validate generic constraints for serialization implementation {closed} and target {targetType}. " + + "Register closed argument and constraint types using TypeManifestOptions.AddGenericArgumentMetadata(typeof(ClosedType)), including nested arguments and array elements."); } - else + + if (materializeImplementation) { try { closed = MaterializeGenericImplementation(candidate.Implementation, arguments); } - catch (ArgumentException) + catch (ArgumentException) when (validation == GenericConstraintValidationResult.Unknown) { - // The runtime rejected the bound arguments, including generic constraints. continue; } } diff --git a/src/Orleans.Serialization/Serializers/GenericConstraintValidator.cs b/src/Orleans.Serialization/Serializers/GenericConstraintValidator.cs new file mode 100644 index 00000000000..e76730bd13f --- /dev/null +++ b/src/Orleans.Serialization/Serializers/GenericConstraintValidator.cs @@ -0,0 +1,197 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using Orleans.Serialization.Configuration; + +namespace Orleans.Serialization.Serializers; + +internal enum GenericConstraintValidationResult +{ + Valid, + Invalid, + Unknown +} + +internal static class GenericConstraintValidator +{ + // This flag was added to GenericParameterAttributes after .NET 8. + private const GenericParameterAttributes AllowByRefLike = (GenericParameterAttributes)0x20; + + internal static GenericConstraintValidationResult Validate( + Type definition, + Type[] arguments, + IReadOnlyDictionary metadata) + { + var parameters = definition.GetGenericArguments(); + if (parameters.Length != arguments.Length) + throw new ArgumentException($"Generic implementation {definition} requires {parameters.Length} arguments, but {arguments.Length} were supplied.", nameof(arguments)); + var result = GenericConstraintValidationResult.Valid; + for (var index = 0; index < parameters.Length; index++) + { + var argument = arguments[index]; + var attributes = parameters[index].GenericParameterAttributes; + if (argument.IsPointer || argument.IsByRef || argument == typeof(void) +#if NET5_0_OR_GREATER + || argument.IsFunctionPointer || argument == typeof(ArgIterator) +#else + || argument.FullName == "System.ArgIterator" && argument.Assembly == typeof(TypedReference).Assembly +#endif + || argument == typeof(TypedReference) || argument == typeof(RuntimeArgumentHandle) + || argument.IsByRefLike && (attributes & AllowByRefLike) == 0) + { + return GenericConstraintValidationResult.Invalid; + } + + if ((attributes & GenericParameterAttributes.ReferenceTypeConstraint) != 0 && argument.IsValueType) + return GenericConstraintValidationResult.Invalid; + if ((attributes & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0 + && (!argument.IsValueType || Nullable.GetUnderlyingType(argument) is not null)) + return GenericConstraintValidationResult.Invalid; + if ((attributes & GenericParameterAttributes.DefaultConstructorConstraint) != 0 && !argument.IsValueType) + { +#if NET10_0_OR_GREATER + if (argument.IsAbstract) return GenericConstraintValidationResult.Invalid; +#endif + if (metadata.TryGetValue(argument, out var argumentMetadata)) + { + if (!argumentMetadata.HasPublicParameterlessConstructor) return GenericConstraintValidationResult.Invalid; + } + else + { + result = GenericConstraintValidationResult.Unknown; + } + } + + foreach (var constraint in parameters[index].GetGenericParameterConstraints()) + { + var constraintResult = IsAssignableTo(new(argument), new(constraint, arguments), metadata); + if (constraintResult == GenericConstraintValidationResult.Invalid) return constraintResult; + if (constraintResult == GenericConstraintValidationResult.Unknown) result = constraintResult; + } + } + + return result; + } + + private static GenericConstraintValidationResult IsAssignableTo( + TypeExpression source, + TypeExpression target, + IReadOnlyDictionary metadata) + { + source = source.ResolveParameter(); + target = target.ResolveParameter(); + if (source.Type.IsGenericParameter || target.Type.IsGenericParameter) return GenericConstraintValidationResult.Unknown; + if (AreEquivalent(source, target)) return GenericConstraintValidationResult.Valid; + + if (!source.Type.ContainsGenericParameters && !target.Type.ContainsGenericParameters) + return target.Type.IsAssignableFrom(source.Type) ? GenericConstraintValidationResult.Valid : GenericConstraintValidationResult.Invalid; + + if (!target.Type.ContainsGenericParameters && !target.Type.IsGenericType && !target.Type.IsArray) + return target.Type.IsAssignableFrom(source.Type) ? GenericConstraintValidationResult.Valid : GenericConstraintValidationResult.Invalid; + + if (source.Type.IsArray && target.Type.IsArray) + { + if (source.Type.GetArrayRank() != target.Type.GetArrayRank() || source.Type.IsSZArray != target.Type.IsSZArray) + return GenericConstraintValidationResult.Invalid; + var sourceElement = new TypeExpression(source.Type.GetElementType()!, source.Bindings).ResolveParameter(); + var targetElement = new TypeExpression(target.Type.GetElementType()!, target.Bindings).ResolveParameter(); + if (sourceElement.Type.IsValueType || targetElement.Type.IsValueType) return GenericConstraintValidationResult.Invalid; + return IsAssignableTo(sourceElement, targetElement, metadata); + } + + if (source.Type.IsGenericType && target.Type.IsGenericType + && source.Type.GetGenericTypeDefinition() == target.Type.GetGenericTypeDefinition()) + { + var sourceArguments = source.Type.GetGenericArguments(); + var targetArguments = target.Type.GetGenericArguments(); + var parameters = target.Type.GetGenericTypeDefinition().GetGenericArguments(); + var result = GenericConstraintValidationResult.Valid; + for (var index = 0; index < parameters.Length; index++) + { + var sourceArgument = new TypeExpression(sourceArguments[index], source.Bindings).ResolveParameter(); + var targetArgument = new TypeExpression(targetArguments[index], target.Bindings).ResolveParameter(); + if (AreEquivalent(sourceArgument, targetArgument)) continue; + var variance = parameters[index].GenericParameterAttributes & GenericParameterAttributes.VarianceMask; + if (sourceArgument.Type.IsValueType || targetArgument.Type.IsValueType || variance == GenericParameterAttributes.None) + return GenericConstraintValidationResult.Invalid; + var argumentResult = variance == GenericParameterAttributes.Covariant + ? IsAssignableTo(sourceArgument, targetArgument, metadata) + : IsAssignableTo(targetArgument, sourceArgument, metadata); + if (argumentResult == GenericConstraintValidationResult.Invalid) return argumentResult; + if (argumentResult == GenericConstraintValidationResult.Unknown) result = argumentResult; + } + + return result; + } + + if (target.Type.IsInterface) + { + if (source.Type == typeof(object)) return GenericConstraintValidationResult.Invalid; + if (!TryGetMetadata(source, metadata, out var sourceMetadata)) return GenericConstraintValidationResult.Unknown; + var result = GenericConstraintValidationResult.Invalid; + foreach (var implemented in sourceMetadata.Interfaces) + { + // Captured interfaces include inherited interfaces, so only matching definitions need comparison. + if (!implemented.IsGenericType || !target.Type.IsGenericType + || implemented.GetGenericTypeDefinition() != target.Type.GetGenericTypeDefinition()) continue; + var interfaceResult = IsAssignableTo(new(implemented), target, metadata); + if (interfaceResult == GenericConstraintValidationResult.Valid) return interfaceResult; + if (interfaceResult == GenericConstraintValidationResult.Unknown) result = interfaceResult; + } + + return result; + } + + return source.Type.BaseType is { } baseType + ? IsAssignableTo(new(baseType, source.Bindings), target, metadata) + : GenericConstraintValidationResult.Invalid; + } + + private static bool TryGetMetadata( + TypeExpression expression, + IReadOnlyDictionary metadata, + out TypeManifestOptions.ClosedTypeMetadata result) + { + if (!expression.Type.ContainsGenericParameters) return metadata.TryGetValue(expression.Type, out result!); + foreach (var entry in metadata) + { + if (AreEquivalent(expression, new(entry.Key))) + { + result = entry.Value; + return true; + } + } + + result = null!; + return false; + } + + private static bool AreEquivalent(TypeExpression left, TypeExpression right) + { + left = left.ResolveParameter(); + right = right.ResolveParameter(); + if (!left.Type.ContainsGenericParameters && !right.Type.ContainsGenericParameters) return left.Type == right.Type; + if (left.Type.IsGenericParameter || right.Type.IsGenericParameter) return false; + if (left.Type.IsArray || right.Type.IsArray) + return left.Type.IsArray && right.Type.IsArray + && left.Type.GetArrayRank() == right.Type.GetArrayRank() && left.Type.IsSZArray == right.Type.IsSZArray + && AreEquivalent(new(left.Type.GetElementType()!, left.Bindings), new(right.Type.GetElementType()!, right.Bindings)); + if (!left.Type.IsGenericType || !right.Type.IsGenericType + || left.Type.GetGenericTypeDefinition() != right.Type.GetGenericTypeDefinition()) return left.Type == right.Type; + var leftArguments = left.Type.GetGenericArguments(); + var rightArguments = right.Type.GetGenericArguments(); + for (var index = 0; index < leftArguments.Length; index++) + { + if (!AreEquivalent(new(leftArguments[index], left.Bindings), new(rightArguments[index], right.Bindings))) return false; + } + + return true; + } + + private readonly record struct TypeExpression(Type Type, Type[]? Bindings = null) + { + internal TypeExpression ResolveParameter() => Type.IsGenericParameter && Bindings is { } bindings + ? new(bindings[Type.GenericParameterPosition]) + : this; + } +} diff --git a/src/api/Orleans.Serialization/Orleans.Serialization.cs b/src/api/Orleans.Serialization/Orleans.Serialization.cs index b02b4141c45..b60c03a61ba 100644 --- a/src/api/Orleans.Serialization/Orleans.Serialization.cs +++ b/src/api/Orleans.Serialization/Orleans.Serialization.cs @@ -3453,6 +3453,8 @@ public void AddFieldCodec(System.Type type, System.Type targetType) { } public void AddFieldCodec(System.Type type) { } + public void AddGenericArgumentMetadata(System.Type type) { } + public void AddInterface(System.Type type) { } public void AddInterfaceImplementation(System.Type type) { } @@ -3501,6 +3503,10 @@ public static void ConsumeEndBaseOrEndObject(this ref Buffers.Reader(this ref Buffers.Reader reader) { } + public static Invocation.Response CopyResponseAndDispose(Invocation.Response response, DeepCopier copier) { throw null; } + + public static Invocation.Response CopyResponseAndDispose(Invocation.Response response, DeepCopier copier) { throw null; } + public static Activators.IActivator CreateDefaultReferenceTypeActivator() where T : class { throw null; } @@ -3691,8 +3697,12 @@ public abstract partial class Response : System.IDisposable public override string ToString() { throw null; } } - public abstract partial class ResponseCodec + public abstract partial class ResponseCodec : IRawResponseReader { + public virtual bool IsSupported { get { throw null; } } + + Response IRawResponseReader.ReadRaw(ref Buffers.Reader reader, scoped ref WireProtocol.Field field) { throw null; } + public abstract object ReadRaw(ref Buffers.Reader reader, scoped ref WireProtocol.Field field); public abstract void WriteRaw(ref Buffers.Writer writer, object value) where TBufferWriter : System.Buffers.IBufferWriter; diff --git a/test/Orleans.CodeGenerator.Tests/GeneratorMemoryRetentionTests.cs b/test/Orleans.CodeGenerator.Tests/GeneratorMemoryRetentionTests.cs index b14c9cf923d..5ad6a3c2e18 100644 --- a/test/Orleans.CodeGenerator.Tests/GeneratorMemoryRetentionTests.cs +++ b/test/Orleans.CodeGenerator.Tests/GeneratorMemoryRetentionTests.cs @@ -39,6 +39,10 @@ public sealed class Payload [Id(0)] public Payload? Next { get; set; } } + public interface IResponses : IGrainWithIntegerKey + { + System.Threading.Tasks.Task Get(); + } """); var compilation = CSharpCompilation.Create( $"RetentionTest{index}", diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index 952b628db8c..369184e7869 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -2332,15 +2332,16 @@ public interface IResponses : IGrainWithIntegerKey Assert.NotNull(model); var options = SourceGeneratorOptionsParser.ParseOptions(TestCompilationHelper.CreateOptionsProvider( new Dictionary { ["build_property.publishaot"] = "true" }).GlobalOptions); - var names = RpcResponseHolderGenerator.GetNames(metadataCompilation, [model], options, TestContext.Current.CancellationToken); + var plan = RpcResponsePlan.Create(metadataCompilation, [model], options, TestContext.Current.CancellationToken); + var names = plan.Names; var preparation = ProxySourceOutputGenerator.CreateProxyOutputPreparation( metadataCompilation, [model], options, names, TestContext.Current.CancellationToken); Assert.Empty(preparation.Diagnostics); var responses = RpcResponseGenerator.Generate( - metadataCompilation, preparation.ProxyOutputModels, options, names, TestContext.Current.CancellationToken); + metadataCompilation, preparation, options, plan, TestContext.Current.CancellationToken); var baseline = RpcResponseGenerator.Generate( - compilation, preparation.ProxyOutputModels, options, names, TestContext.Current.CancellationToken); + compilation, preparation, options, plan, TestContext.Current.CancellationToken); Assert.Equal(baseline, responses); Assert.NotEmpty(responses); Assert.All(responses, static output => Assert.Null(output.Diagnostic)); @@ -3556,7 +3557,8 @@ public interface IWriter : IGrainWithIntegerKey { {{returnType}} Get(); } var response = Assert.Single(result.GeneratedSources, static item => item.HintName.EndsWith(".orleans.rpcresponses.g.cs", StringComparison.Ordinal)).SourceText.ToString(); var proxy = Assert.Single(result.GeneratedSources, static item => item.HintName.Contains(".orleans.proxy.", StringComparison.Ordinal)).SourceText.ToString(); Assert.Contains("IRawResponseWriter", response); - Assert.Contains("IRawResponseReader", response); + Assert.Contains("global::Orleans.Serialization.Invocation.ResponseCodec", response); + Assert.Contains("public override bool IsSupported", response); Assert.Contains("Int32Codec.WriteField(ref writer, 0, Value)", response); Assert.Contains("ResponsePool.GetGenerated<", response); Assert.Contains("_factory = null", response); @@ -3564,9 +3566,7 @@ public interface IWriter : IGrainWithIntegerKey { {{returnType}} Get(); } Assert.Contains("IResponseInvokable.InvokeAndCopy", proxy); Assert.Contains("factory.RentCopied(value, contexts)", proxy); Assert.Contains("var original = await Invoke();", proxy); - Assert.Contains("return copy = responseCopier.Copy(original);", proxy); - Assert.Contains("if (!global::System.Object.ReferenceEquals(original, copy))", proxy); - Assert.Contains("original.Dispose();", proxy); + Assert.Contains("OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier)", proxy); Assert.DoesNotContain("MakeGenericType", response); var holders = CSharpSyntaxTree.ParseText(response, cancellationToken: TestContext.Current.CancellationToken) .GetCompilationUnitRoot(TestContext.Current.CancellationToken).DescendantNodes() diff --git a/test/Orleans.CodeGenerator.Tests/SerializerConstructionReviewTests.cs b/test/Orleans.CodeGenerator.Tests/SerializerConstructionReviewTests.cs index ee8cc9887c0..b9fab43295d 100644 --- a/test/Orleans.CodeGenerator.Tests/SerializerConstructionReviewTests.cs +++ b/test/Orleans.CodeGenerator.Tests/SerializerConstructionReviewTests.cs @@ -621,6 +621,23 @@ IKeyedDependency Resolve(IServiceProvider provider) => keyed : provider.GetRequiredService>(); } + [Theory] + [InlineData(false)] + [InlineData(true)] + public void MalformedActivatorRegistrationsThrowInBothSelectionModes(bool materialize) + { + var options = new TypeManifestOptions(); + options.AddActivator(typeof(UnboundActivator<,>), typeof(ReferenceModel)); + using var services = new ServiceCollection().BuildServiceProvider(); + var codecs = new CodecProvider(services, Options.Create(options)); + var selector = typeof(CodecProvider).GetMethods(BindingFlags.Instance | BindingFlags.NonPublic) + .Single(method => method.Name == "TrySelectImplementation" && method.GetParameters().Length == 6); + + var exception = Assert.Throws(() => selector.Invoke(codecs, + [typeof(IActivator<>), typeof(ReferenceModel), typeof(ReferenceModel<>), null, null, materialize])); + Assert.Contains("different generic arity", Assert.IsType(exception.InnerException).Message); + } + [Theory] [InlineData("activator", typeof(ArgumentException))] [InlineData("value serializer", typeof(KeyNotFoundException))] diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs index 956cda7d99a..ea5c970541d 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs @@ -65,16 +65,7 @@ public override void SetArgument(int index, object value) if (!factory.IsSupported) { var original = await Invoke(); - global::Orleans.Serialization.Invocation.Response copy = null; - try - { - return copy = responseCopier.Copy(original); - } - finally - { - if (!global::System.Object.ReferenceEquals(original, copy)) - original.Dispose(); - } + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } string value = await InvokeInner(); @@ -281,6 +272,8 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); + options.AddGenericArgumentMetadata(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddGenericArgumentMetadata(typeof(string)); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }); options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); @@ -384,11 +377,11 @@ public override void Dispose() } } - internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier { private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; - public bool IsSupported { get; } + public override bool IsSupported { get; } internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { @@ -429,7 +422,6 @@ internal void WriteResult(ref global::Orleans.Serialization.Buffe public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) { field.EnsureWireTypeTagDelimited(); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs index ff489b8c6c5..2d867721db1 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs @@ -65,16 +65,7 @@ public override void SetArgument(int index, object value) if (!factory.IsSupported) { var original = await Invoke(); - global::Orleans.Serialization.Invocation.Response copy = null; - try - { - return copy = responseCopier.Copy(original); - } - finally - { - if (!global::System.Object.ReferenceEquals(original, copy)) - original.Dispose(); - } + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } string value = await InvokeInner(); @@ -281,6 +272,8 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); + options.AddGenericArgumentMetadata(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddGenericArgumentMetadata(typeof(string)); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }); options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); @@ -385,11 +378,11 @@ public override void Dispose() } } - internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier { private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; - public bool IsSupported { get; } + public override bool IsSupported { get; } internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { @@ -430,7 +423,6 @@ internal void WriteResult(ref global::Orleans.Serialization.Buffe public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) { field.EnsureWireTypeTagDelimited(); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs index 5c30dbb303e..dbd04300ced 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs @@ -65,16 +65,7 @@ public override void SetArgument(int index, object value) if (!factory.IsSupported) { var original = await Invoke(); - global::Orleans.Serialization.Invocation.Response copy = null; - try - { - return copy = responseCopier.Copy(original); - } - finally - { - if (!global::System.Object.ReferenceEquals(original, copy)) - original.Dispose(); - } + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } string value = await InvokeInner(); @@ -189,6 +180,8 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); + options.AddGenericArgumentMetadata(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddGenericArgumentMetadata(typeof(string)); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }); options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); @@ -292,11 +285,11 @@ public override void Dispose() } } - internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier { private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; - public bool IsSupported { get; } + public override bool IsSupported { get; } internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { @@ -337,7 +330,6 @@ internal void WriteResult(ref global::Orleans.Serialization.Buffe public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) { field.EnsureWireTypeTagDelimited(); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs index ee1f03b35bf..ec0de93ed3a 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs @@ -65,16 +65,7 @@ public override void SetArgument(int index, object value) if (!factory.IsSupported) { var original = await Invoke(); - global::Orleans.Serialization.Invocation.Response copy = null; - try - { - return copy = responseCopier.Copy(original); - } - finally - { - if (!global::System.Object.ReferenceEquals(original, copy)) - original.Dispose(); - } + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } string value = await InvokeInner(); @@ -189,6 +180,8 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); + options.AddGenericArgumentMetadata(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddGenericArgumentMetadata(typeof(string)); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }); options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); @@ -293,11 +286,11 @@ public override void Dispose() } } - internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier { private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; - public bool IsSupported { get; } + public override bool IsSupported { get; } internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { @@ -338,7 +331,6 @@ internal void WriteResult(ref global::Orleans.Serialization.Buffe public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) { field.EnsureWireTypeTagDelimited(); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs index d74d21e5cf2..af3a75d66b4 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs @@ -109,16 +109,7 @@ public override bool TryCancel() if (!factory.IsSupported) { var original = await Invoke(); - global::Orleans.Serialization.Invocation.Response copy = null; - try - { - return copy = responseCopier.Copy(original); - } - finally - { - if (!global::System.Object.ReferenceEquals(original, copy)) - original.Dispose(); - } + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } global::TestProject.ComplexData value = await InvokeInner(); @@ -475,6 +466,8 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new RpcResponse_FC7DD5BDFactory(provider)); options.AddDefaultSerializer(static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider), static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider)); + options.AddGenericArgumentMetadata(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddGenericArgumentMetadata(typeof(global::TestProject.ComplexData)); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::OrleansCodeGen.TestProject.Codec_ComplexData) }); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::OrleansCodeGen.TestProject.Copier_ComplexData) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::OrleansCodeGen.TestProject.Codec_ComplexData) }, copierDependencies: new global::System.Type[] { typeof(global::OrleansCodeGen.TestProject.Copier_ComplexData) }); @@ -485,10 +478,12 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService, global::OrleansCodeGen.TestProject.Codec_ComplexData>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), dependencies: new global::System.Type[] { }); options.AddDefaultSerializerService, global::OrleansCodeGen.TestProject.Copier_ComplexData>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), dependencies: new global::System.Type[] { }); options.AddAllowedType(typeof(global::TestProject.ComplexData)); + options.AddGenericArgumentMetadata(typeof(int)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.Int32Codec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(int)); + options.AddGenericArgumentMetadata(typeof(string)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); @@ -582,11 +577,11 @@ public override void Dispose() } } - internal sealed class RpcResponse_FC7DD5BDFactory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + internal sealed class RpcResponse_FC7DD5BDFactory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier { private readonly global::OrleansCodeGen.TestProject.Codec_ComplexData _codec; private readonly global::OrleansCodeGen.TestProject.Copier_ComplexData _copier; - public bool IsSupported { get; } + public override bool IsSupported { get; } internal static RpcResponse_FC7DD5BDFactory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { @@ -628,7 +623,6 @@ internal void WriteResult(ref global::Orleans.Serialization.Buffe public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_FC7DD5BD)value).Value); public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); private RpcResponse_FC7DD5BD ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) { field.EnsureWireTypeTagDelimited(); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs index 908fd213c57..5da47180864 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs @@ -108,16 +108,7 @@ public override bool TryCancel() if (!factory.IsSupported) { var original = await Invoke(); - global::Orleans.Serialization.Invocation.Response copy = null; - try - { - return copy = responseCopier.Copy(original); - } - finally - { - if (!global::System.Object.ReferenceEquals(original, copy)) - original.Dispose(); - } + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } global::TestProject.ComplexData value = await InvokeInner(); @@ -474,6 +465,8 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new RpcResponse_FC7DD5BDFactory(provider)); options.AddDefaultSerializer(static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider), static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_FC7DD5BDFactory.Resolve(provider)); + options.AddGenericArgumentMetadata(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddGenericArgumentMetadata(typeof(global::TestProject.ComplexData)); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::OrleansCodeGen.TestProject.Codec_ComplexData) }); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::OrleansCodeGen.TestProject.Copier_ComplexData) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::OrleansCodeGen.TestProject.Codec_ComplexData) }, copierDependencies: new global::System.Type[] { typeof(global::OrleansCodeGen.TestProject.Copier_ComplexData) }); @@ -484,10 +477,12 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService, global::OrleansCodeGen.TestProject.Codec_ComplexData>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), dependencies: new global::System.Type[] { }); options.AddDefaultSerializerService, global::OrleansCodeGen.TestProject.Copier_ComplexData>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), dependencies: new global::System.Type[] { }); options.AddAllowedType(typeof(global::TestProject.ComplexData)); + options.AddGenericArgumentMetadata(typeof(int)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.Int32Codec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); options.AddAllowedType(typeof(int)); + options.AddGenericArgumentMetadata(typeof(string)); options.AddDefaultSerializerService(static provider => new global::Orleans.Serialization.Codecs.StringCodec()); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Cloning.ShallowCopier()); options.AddDefaultSerializer>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)); @@ -582,11 +577,11 @@ public override void Dispose() } } - internal sealed class RpcResponse_FC7DD5BDFactory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + internal sealed class RpcResponse_FC7DD5BDFactory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier { private readonly global::OrleansCodeGen.TestProject.Codec_ComplexData _codec; private readonly global::OrleansCodeGen.TestProject.Copier_ComplexData _copier; - public bool IsSupported { get; } + public override bool IsSupported { get; } internal static RpcResponse_FC7DD5BDFactory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { @@ -628,7 +623,6 @@ internal void WriteResult(ref global::Orleans.Serialization.Buffe public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_FC7DD5BD)value).Value); public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); private RpcResponse_FC7DD5BD ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) { field.EnsureWireTypeTagDelimited(); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs index 60683d99759..fddb557a078 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs @@ -70,16 +70,7 @@ public override void SetArgument(int index, object value) if (!factory.IsSupported) { var original = await Invoke(); - global::Orleans.Serialization.Invocation.Response copy = null; - try - { - return copy = responseCopier.Copy(original); - } - finally - { - if (!global::System.Object.ReferenceEquals(original, copy)) - original.Dispose(); - } + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } string value = await InvokeInner(); @@ -286,6 +277,8 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); + options.AddGenericArgumentMetadata(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddGenericArgumentMetadata(typeof(string)); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }); options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); @@ -389,11 +382,11 @@ public override void Dispose() } } - internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier { private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; - public bool IsSupported { get; } + public override bool IsSupported { get; } internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { @@ -434,7 +427,6 @@ internal void WriteResult(ref global::Orleans.Serialization.Buffe public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) { field.EnsureWireTypeTagDelimited(); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs index fdbcde11b51..235dc76e11c 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs @@ -70,16 +70,7 @@ public override void SetArgument(int index, object value) if (!factory.IsSupported) { var original = await Invoke(); - global::Orleans.Serialization.Invocation.Response copy = null; - try - { - return copy = responseCopier.Copy(original); - } - finally - { - if (!global::System.Object.ReferenceEquals(original, copy)) - original.Dispose(); - } + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } string value = await InvokeInner(); @@ -286,6 +277,8 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); + options.AddGenericArgumentMetadata(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddGenericArgumentMetadata(typeof(string)); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }); options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); @@ -390,11 +383,11 @@ public override void Dispose() } } - internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier { private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; - public bool IsSupported { get; } + public override bool IsSupported { get; } internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { @@ -435,7 +428,6 @@ internal void WriteResult(ref global::Orleans.Serialization.Buffe public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) { field.EnsureWireTypeTagDelimited(); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs index 0246b4145d3..d2acbee0f0f 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs @@ -67,16 +67,7 @@ public override void SetArgument(int index, object value) if (!factory.IsSupported) { var original = await Invoke(); - global::Orleans.Serialization.Invocation.Response copy = null; - try - { - return copy = responseCopier.Copy(original); - } - finally - { - if (!global::System.Object.ReferenceEquals(original, copy)) - original.Dispose(); - } + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } string value = await InvokeInner(); @@ -188,6 +179,8 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); + options.AddGenericArgumentMetadata(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddGenericArgumentMetadata(typeof(string)); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }); options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); @@ -291,11 +284,11 @@ public override void Dispose() } } - internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier { private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; - public bool IsSupported { get; } + public override bool IsSupported { get; } internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { @@ -336,7 +329,6 @@ internal void WriteResult(ref global::Orleans.Serialization.Buffe public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) { field.EnsureWireTypeTagDelimited(); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs index 68f40093422..24b23c61011 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs @@ -67,16 +67,7 @@ public override void SetArgument(int index, object value) if (!factory.IsSupported) { var original = await Invoke(); - global::Orleans.Serialization.Invocation.Response copy = null; - try - { - return copy = responseCopier.Copy(original); - } - finally - { - if (!global::System.Object.ReferenceEquals(original, copy)) - original.Dispose(); - } + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } string value = await InvokeInner(); @@ -188,6 +179,8 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); + options.AddGenericArgumentMetadata(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddGenericArgumentMetadata(typeof(string)); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }); options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); @@ -292,11 +285,11 @@ public override void Dispose() } } - internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier { private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; - public bool IsSupported { get; } + public override bool IsSupported { get; } internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { @@ -337,7 +330,6 @@ internal void WriteResult(ref global::Orleans.Serialization.Buffe public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) { field.EnsureWireTypeTagDelimited(); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs index 87b15ff690c..e857f6744a7 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs @@ -38,16 +38,7 @@ public override void Dispose() if (!factory.IsSupported) { var original = await Invoke(); - global::Orleans.Serialization.Invocation.Response copy = null; - try - { - return copy = responseCopier.Copy(original); - } - finally - { - if (!global::System.Object.ReferenceEquals(original, copy)) - original.Dispose(); - } + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } global::System.Guid value = await InvokeInner(); @@ -101,16 +92,7 @@ public override void Dispose() if (!factory.IsSupported) { var original = await Invoke(); - global::Orleans.Serialization.Invocation.Response copy = null; - try - { - return copy = responseCopier.Copy(original); - } - finally - { - if (!global::System.Object.ReferenceEquals(original, copy)) - original.Dispose(); - } + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } string value = await InvokeInner(); @@ -164,16 +146,7 @@ public override void Dispose() if (!factory.IsSupported) { var original = await Invoke(); - global::Orleans.Serialization.Invocation.Response copy = null; - try - { - return copy = responseCopier.Copy(original); - } - finally - { - if (!global::System.Object.ReferenceEquals(original, copy)) - original.Dispose(); - } + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } global::System.Tuple value = await InvokeInner(); @@ -227,16 +200,7 @@ public override void Dispose() if (!factory.IsSupported) { var original = await Invoke(); - global::Orleans.Serialization.Invocation.Response copy = null; - try - { - return copy = responseCopier.Copy(original); - } - finally - { - if (!global::System.Object.ReferenceEquals(original, copy)) - original.Dispose(); - } + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } global::System.Tuple value = await InvokeInner(); @@ -892,18 +856,27 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); + options.AddGenericArgumentMetadata(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddGenericArgumentMetadata(typeof(global::System.Guid)); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.GuidCodec) }); options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.GuidCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddGenericArgumentMetadata(typeof(global::Orleans.Serialization.Invocation.Response>)); + options.AddGenericArgumentMetadata(typeof(global::System.Tuple)); + options.AddGenericArgumentMetadata(typeof(string)); options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCodec) }); options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCopier) }); options.AddDefaultSerializer>, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>, global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response>)); + options.AddGenericArgumentMetadata(typeof(global::Orleans.Serialization.Invocation.Response>)); + options.AddGenericArgumentMetadata(typeof(global::System.Tuple)); + options.AddGenericArgumentMetadata(typeof(long)); options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCodec) }); options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCopier) }); options.AddDefaultSerializer>, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>, global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response>)); + options.AddGenericArgumentMetadata(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }); options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); @@ -1019,11 +992,11 @@ public override void Dispose() } } - internal sealed class RpcResponse_5C3A711CFactory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + internal sealed class RpcResponse_5C3A711CFactory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier { private readonly global::Orleans.Serialization.Codecs.GuidCodec _codec; private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; - public bool IsSupported { get; } + public override bool IsSupported { get; } internal static RpcResponse_5C3A711CFactory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { @@ -1060,7 +1033,6 @@ internal void WriteResult(ref global::Orleans.Serialization.Buffe public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_5C3A711C)value).Value); public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); private RpcResponse_5C3A711C ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) { field.EnsureWireTypeTagDelimited(); @@ -1153,11 +1125,11 @@ public override void Dispose() } } - internal sealed class RpcResponse_6A3EE8F4Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + internal sealed class RpcResponse_6A3EE8F4Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier { private readonly global::Orleans.Serialization.Codecs.TupleCodec _codec; private readonly global::Orleans.Serialization.Codecs.TupleCopier _copier; - public bool IsSupported { get; } + public override bool IsSupported { get; } internal static RpcResponse_6A3EE8F4Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { @@ -1198,7 +1170,6 @@ internal void WriteResult(ref global::Orleans.Serialization.Buffe public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_6A3EE8F4)value).Value); public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); private RpcResponse_6A3EE8F4 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) { field.EnsureWireTypeTagDelimited(); @@ -1295,11 +1266,11 @@ public override void Dispose() } } - internal sealed class RpcResponse_AFB713E4Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + internal sealed class RpcResponse_AFB713E4Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier { private readonly global::Orleans.Serialization.Codecs.TupleCodec _codec; private readonly global::Orleans.Serialization.Codecs.TupleCopier _copier; - public bool IsSupported { get; } + public override bool IsSupported { get; } internal static RpcResponse_AFB713E4Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { @@ -1340,7 +1311,6 @@ internal void WriteResult(ref global::Orleans.Serialization.Buffe public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_AFB713E4)value).Value); public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); private RpcResponse_AFB713E4 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) { field.EnsureWireTypeTagDelimited(); @@ -1443,11 +1413,11 @@ public override void Dispose() } } - internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier { private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; - public bool IsSupported { get; } + public override bool IsSupported { get; } internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { @@ -1488,7 +1458,6 @@ internal void WriteResult(ref global::Orleans.Serialization.Buffe public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) { field.EnsureWireTypeTagDelimited(); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs index 5d831ddbd02..f6f42ce68b2 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs @@ -38,16 +38,7 @@ public override void Dispose() if (!factory.IsSupported) { var original = await Invoke(); - global::Orleans.Serialization.Invocation.Response copy = null; - try - { - return copy = responseCopier.Copy(original); - } - finally - { - if (!global::System.Object.ReferenceEquals(original, copy)) - original.Dispose(); - } + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } global::System.Guid value = await InvokeInner(); @@ -101,16 +92,7 @@ public override void Dispose() if (!factory.IsSupported) { var original = await Invoke(); - global::Orleans.Serialization.Invocation.Response copy = null; - try - { - return copy = responseCopier.Copy(original); - } - finally - { - if (!global::System.Object.ReferenceEquals(original, copy)) - original.Dispose(); - } + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } string value = await InvokeInner(); @@ -164,16 +146,7 @@ public override void Dispose() if (!factory.IsSupported) { var original = await Invoke(); - global::Orleans.Serialization.Invocation.Response copy = null; - try - { - return copy = responseCopier.Copy(original); - } - finally - { - if (!global::System.Object.ReferenceEquals(original, copy)) - original.Dispose(); - } + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } global::System.Tuple value = await InvokeInner(); @@ -227,16 +200,7 @@ public override void Dispose() if (!factory.IsSupported) { var original = await Invoke(); - global::Orleans.Serialization.Invocation.Response copy = null; - try - { - return copy = responseCopier.Copy(original); - } - finally - { - if (!global::System.Object.ReferenceEquals(original, copy)) - original.Dispose(); - } + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } global::System.Tuple value = await InvokeInner(); @@ -892,18 +856,27 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); + options.AddGenericArgumentMetadata(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddGenericArgumentMetadata(typeof(global::System.Guid)); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.GuidCodec) }); options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.GuidCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddGenericArgumentMetadata(typeof(global::Orleans.Serialization.Invocation.Response>)); + options.AddGenericArgumentMetadata(typeof(global::System.Tuple)); + options.AddGenericArgumentMetadata(typeof(string)); options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCodec) }); options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCopier) }); options.AddDefaultSerializer>, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>, global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response>)); + options.AddGenericArgumentMetadata(typeof(global::Orleans.Serialization.Invocation.Response>)); + options.AddGenericArgumentMetadata(typeof(global::System.Tuple)); + options.AddGenericArgumentMetadata(typeof(long)); options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCodec>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCodec) }); options.AddDefaultSerializerService, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCopier) }); options.AddDefaultSerializer>, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>, global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCodec>>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService, global::Orleans.Serialization.Codecs.TupleCopier>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.TupleCopier) }); options.AddAllowedType(typeof(global::Orleans.Serialization.Invocation.Response>)); + options.AddGenericArgumentMetadata(typeof(global::Orleans.Serialization.Invocation.Response)); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }); options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); @@ -1020,11 +993,11 @@ public override void Dispose() } } - internal sealed class RpcResponse_5C3A711CFactory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + internal sealed class RpcResponse_5C3A711CFactory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier { private readonly global::Orleans.Serialization.Codecs.GuidCodec _codec; private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; - public bool IsSupported { get; } + public override bool IsSupported { get; } internal static RpcResponse_5C3A711CFactory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { @@ -1061,7 +1034,6 @@ internal void WriteResult(ref global::Orleans.Serialization.Buffe public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_5C3A711C)value).Value); public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); private RpcResponse_5C3A711C ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) { field.EnsureWireTypeTagDelimited(); @@ -1155,11 +1127,11 @@ public override void Dispose() } } - internal sealed class RpcResponse_6A3EE8F4Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + internal sealed class RpcResponse_6A3EE8F4Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier { private readonly global::Orleans.Serialization.Codecs.TupleCodec _codec; private readonly global::Orleans.Serialization.Codecs.TupleCopier _copier; - public bool IsSupported { get; } + public override bool IsSupported { get; } internal static RpcResponse_6A3EE8F4Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { @@ -1200,7 +1172,6 @@ internal void WriteResult(ref global::Orleans.Serialization.Buffe public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_6A3EE8F4)value).Value); public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); private RpcResponse_6A3EE8F4 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) { field.EnsureWireTypeTagDelimited(); @@ -1298,11 +1269,11 @@ public override void Dispose() } } - internal sealed class RpcResponse_AFB713E4Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + internal sealed class RpcResponse_AFB713E4Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier { private readonly global::Orleans.Serialization.Codecs.TupleCodec _codec; private readonly global::Orleans.Serialization.Codecs.TupleCopier _copier; - public bool IsSupported { get; } + public override bool IsSupported { get; } internal static RpcResponse_AFB713E4Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { @@ -1343,7 +1314,6 @@ internal void WriteResult(ref global::Orleans.Serialization.Buffe public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_AFB713E4)value).Value); public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); private RpcResponse_AFB713E4 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) { field.EnsureWireTypeTagDelimited(); @@ -1447,11 +1417,11 @@ public override void Dispose() } } - internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier { private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; - public bool IsSupported { get; } + public override bool IsSupported { get; } internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { @@ -1492,7 +1462,6 @@ internal void WriteResult(ref global::Orleans.Serialization.Buffe public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) { field.EnsureWireTypeTagDelimited(); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs index 13a915150ec..1edd539a351 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs @@ -65,16 +65,7 @@ public override void SetArgument(int index, object value) if (!factory.IsSupported) { var original = await Invoke(); - global::Orleans.Serialization.Invocation.Response copy = null; - try - { - return copy = responseCopier.Copy(original); - } - finally - { - if (!global::System.Object.ReferenceEquals(original, copy)) - original.Dispose(); - } + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } string value = await InvokeInner(); @@ -156,16 +147,7 @@ public override void SetArgument(int index, object value) if (!factory.IsSupported) { var original = await Invoke(); - global::Orleans.Serialization.Invocation.Response copy = null; - try - { - return copy = responseCopier.Copy(original); - } - finally - { - if (!global::System.Object.ReferenceEquals(original, copy)) - original.Dispose(); - } + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } string value = await InvokeInner(); @@ -353,6 +335,8 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); + options.AddGenericArgumentMetadata(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddGenericArgumentMetadata(typeof(string)); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }); options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); @@ -456,11 +440,11 @@ public override void Dispose() } } - internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier { private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; - public bool IsSupported { get; } + public override bool IsSupported { get; } internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { @@ -501,7 +485,6 @@ internal void WriteResult(ref global::Orleans.Serialization.Buffe public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) { field.EnsureWireTypeTagDelimited(); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs index e0ca637a8bb..c9a439f3663 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs @@ -65,16 +65,7 @@ public override void SetArgument(int index, object value) if (!factory.IsSupported) { var original = await Invoke(); - global::Orleans.Serialization.Invocation.Response copy = null; - try - { - return copy = responseCopier.Copy(original); - } - finally - { - if (!global::System.Object.ReferenceEquals(original, copy)) - original.Dispose(); - } + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } string value = await InvokeInner(); @@ -156,16 +147,7 @@ public override void SetArgument(int index, object value) if (!factory.IsSupported) { var original = await Invoke(); - global::Orleans.Serialization.Invocation.Response copy = null; - try - { - return copy = responseCopier.Copy(original); - } - finally - { - if (!global::System.Object.ReferenceEquals(original, copy)) - original.Dispose(); - } + return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } string value = await InvokeInner(); @@ -353,6 +335,8 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati options.AddDefaultSerializerService(static provider => new RpcResponse_9146C7E3Factory(provider)); options.AddDefaultSerializer(static provider => RpcResponse_9146C7E3Factory.Resolve(provider), static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); options.AddRawResponseReader(static provider => RpcResponse_9146C7E3Factory.Resolve(provider)); + options.AddGenericArgumentMetadata(typeof(global::Orleans.Serialization.Invocation.Response)); + options.AddGenericArgumentMetadata(typeof(string)); options.AddDefaultSerializerService>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCodec(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }); options.AddDefaultSerializerService>>(static provider => new global::Orleans.Serialization.Invocation.PooledResponseCopier>(global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider)), dependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); options.AddDefaultSerializer, global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Invocation.PooledResponseCopier>>(static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null !, provider), static provider => global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>>(null !, provider), codecDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Codecs.StringCodec) }, copierDependencies: new global::System.Type[] { typeof(global::Orleans.Serialization.Cloning.ShallowCopier) }); @@ -457,11 +441,11 @@ public override void Dispose() } } - internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Invocation.IRawResponseReader + internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serialization.Invocation.ResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Cloning.IDeepCopier { private readonly global::Orleans.Serialization.Codecs.StringCodec _codec; private readonly global::Orleans.Serialization.Cloning.ShallowCopier _copier; - public bool IsSupported { get; } + public override bool IsSupported { get; } internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { @@ -502,7 +486,6 @@ internal void WriteResult(ref global::Orleans.Serialization.Buffe public override void WriteRaw(ref global::Orleans.Serialization.Buffers.Writer writer, object value) => WriteResult(ref writer, ((RpcResponse_9146C7E3)value).Value); public override object ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); - global::Orleans.Serialization.Invocation.Response global::Orleans.Serialization.Invocation.IRawResponseReader.ReadRaw(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) => ReadResult(ref reader, ref field); private RpcResponse_9146C7E3 ReadResult(ref global::Orleans.Serialization.Buffers.Reader reader, scoped ref global::Orleans.Serialization.WireProtocol.Field field) { field.EnsureWireTypeTagDelimited(); diff --git a/test/Orleans.Serialization.UnitTests/ManifestContractTests.cs b/test/Orleans.Serialization.UnitTests/ManifestContractTests.cs index 9a68eea954a..1a6b678828a 100644 --- a/test/Orleans.Serialization.UnitTests/ManifestContractTests.cs +++ b/test/Orleans.Serialization.UnitTests/ManifestContractTests.cs @@ -1144,6 +1144,7 @@ public void StructConstrainedCopiersSelectTheLatestApplicableRegistration() [InlineData(typeof(ConstructorConstrainedCopier<>), typeof(AbstractConstructorTarget), true)] #endif [InlineData(typeof(ConstructorConstrainedCopier<>), typeof(int), true)] + [InlineData(typeof(ConstructorConstrainedCopier<>), typeof(int?), true)] [InlineData(typeof(ComparableConstrainedCopier<>), typeof(string), true)] [InlineData(typeof(ComparableConstrainedCopier<>), typeof(int), true)] [InlineData(typeof(ComparableConstrainedCopier<>), typeof(FirstTarget), false)] @@ -1345,6 +1346,257 @@ public void WinningImplementationIsClosedOnceDuringResolution(bool converter) Assert.Equal(1, implementation.ClosureAttempts); } + [Fact] + public void GenericArgumentMetadataCapturesAnnotatedClosedTypesAndIsIdempotent() + { + var parameter = typeof(TypeManifestOptions).GetMethod(nameof(TypeManifestOptions.AddGenericArgumentMetadata))!.GetParameters()[0]; + Assert.Equal(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicParameterlessConstructor, + parameter.GetCustomAttribute()!.MemberTypes); + var options = new TypeManifestOptions(); + options.AddGenericArgumentMetadata(typeof(PublicConstructorTarget)); + options.AddGenericArgumentMetadata(typeof(PrivateConstructorTarget)); + options.AddGenericArgumentMetadata(typeof(List)); + var metadata = options.GenericArgumentMetadata[typeof(List)]; + options.AddGenericArgumentMetadata(typeof(List)); + + Assert.Same(metadata, options.GenericArgumentMetadata[typeof(List)]); + Assert.True(options.GenericArgumentMetadata[typeof(PublicConstructorTarget)].HasPublicParameterlessConstructor); + Assert.False(options.GenericArgumentMetadata[typeof(PrivateConstructorTarget)].HasPublicParameterlessConstructor); + Assert.Contains(typeof(IEnumerable), metadata.Interfaces); + var readOnlyList = options.GenericArgumentMetadata[typeof(IReadOnlyList)]; + Assert.False(readOnlyList.HasPublicParameterlessConstructor); + Assert.Contains(typeof(IEnumerable), readOnlyList.Interfaces); + Assert.Contains(typeof(IReadOnlyCollection), readOnlyList.Interfaces); + Assert.DoesNotContain(typeof(IList), readOnlyList.Interfaces); + options.AddGenericArgumentMetadata(typeof(IReadOnlyList)); + Assert.Same(readOnlyList, options.GenericArgumentMetadata[typeof(IReadOnlyList)]); + Assert.Equal("type", Assert.Throws(() => options.AddGenericArgumentMetadata(null!)).ParamName); + Assert.Equal("type", Assert.Throws(() => options.AddGenericArgumentMetadata(typeof(List<>))).ParamName); + Assert.Equal(3 + metadata.Interfaces.Length, options.GenericArgumentMetadata.Count); + } + + [Theory] + [InlineData(typeof(StructConstrainedCopier<>), typeof(int), true)] + [InlineData(typeof(StructConstrainedCopier<>), typeof(int?), false)] + [InlineData(typeof(StructConstrainedCopier<>), typeof(string), false)] + [InlineData(typeof(ReferenceConstrainedCopier<>), typeof(string), true)] + [InlineData(typeof(ReferenceConstrainedCopier<>), typeof(int), false)] + [InlineData(typeof(ConstructorConstrainedCopier<>), typeof(int), true)] + [InlineData(typeof(BaseConstrainedCopier<>), typeof(ConstraintDerived), true)] + [InlineData(typeof(BaseConstrainedCopier<>), typeof(string), false)] + [InlineData(typeof(DisposableConstrainedCopier<>), typeof(System.IO.MemoryStream), true)] + [InlineData(typeof(DisposableConstrainedCopier<>), typeof(string), false)] + [InlineData(typeof(NewDisposableConstrainedCopier<>), typeof(string), false)] + public void SpecialAndClosedConstraintsAreDecidableWithoutArgumentMetadata(Type definition, Type target, bool accepted) + { + var options = new TypeManifestOptions(); + var implementation = new CountingGenericImplementation(definition); + options.AddSerializationContract(typeof(ParameterCopier<>), typeof(IDeepCopier<>), SerializationType.Parameter(0)); + options.AddSerializationContract(implementation, typeof(IDeepCopier<>), SerializationType.Parameter(0)); + using var services = new ServiceCollection().BuildServiceProvider(); + var provider = new CodecProvider(services, Options.Create(options)); + + Assert.Equal(accepted ? GenericConstraintValidationResult.Valid : GenericConstraintValidationResult.Invalid, + GenericConstraintValidator.Validate(definition, [target], options.GenericArgumentMetadata)); + Assert.Equal(accepted ? implementation : typeof(ParameterCopier<>), + SelectImplementation(provider, typeof(IDeepCopier<>), target, materialize: false)); + Assert.Equal(0, implementation.ClosureAttempts); + } + + [Theory] + [InlineData(typeof(ConstructorConstrainedCopier<>), typeof(PublicConstructorTarget), true)] + [InlineData(typeof(ConstructorConstrainedCopier<>), typeof(PrivateConstructorTarget), false)] +#if NET10_0_OR_GREATER + [InlineData(typeof(ConstructorConstrainedCopier<>), typeof(AbstractConstructorTarget), false)] +#else + [InlineData(typeof(ConstructorConstrainedCopier<>), typeof(AbstractConstructorTarget), true)] +#endif + [InlineData(typeof(ConstructorConstrainedCopier<>), typeof(string), false)] + [InlineData(typeof(ComparableConstrainedCopier<>), typeof(string), true)] + [InlineData(typeof(ComparableConstrainedCopier<>), typeof(int), true)] + [InlineData(typeof(ComparableConstrainedCopier<>), typeof(FirstTarget), false)] + public void CapturedMetadataValidatesConstructorsAndInterfacesInBothSelectionModes(Type definition, Type target, bool accepted) + { + var options = new TypeManifestOptions(); + options.AddGenericArgumentMetadata(target); + var implementation = new CountingGenericImplementation(definition); + options.AddSerializationContract(typeof(ParameterCopier<>), typeof(IDeepCopier<>), SerializationType.Parameter(0)); + options.AddSerializationContract(implementation, typeof(IDeepCopier<>), SerializationType.Parameter(0)); + using var services = new ServiceCollection().BuildServiceProvider(); + var provider = new CodecProvider(services, Options.Create(options)); + + Assert.Equal(accepted ? GenericConstraintValidationResult.Valid : GenericConstraintValidationResult.Invalid, + GenericConstraintValidator.Validate(definition, [target], options.GenericArgumentMetadata)); + Assert.Equal(accepted ? implementation : typeof(ParameterCopier<>), + SelectImplementation(provider, typeof(IDeepCopier<>), target, materialize: false)); + Assert.Equal(0, implementation.ClosureAttempts); + Assert.Equal((accepted ? definition : typeof(ParameterCopier<>)).MakeGenericType(target), + SelectImplementation(provider, typeof(IDeepCopier<>), target)); + Assert.Equal(accepted ? 1 : 0, implementation.ClosureAttempts); + } + + [Theory] + [InlineData(typeof(PublicConstructorTarget), true)] + [InlineData(typeof(PrivateConstructorTarget), false)] + public void UnknownJitArgumentsRetainPrecedenceAndNonmaterializedSelectionRequiresMetadata(Type target, bool accepted) + { + var options = new TypeManifestOptions(); + var implementation = new CountingGenericImplementation(typeof(ConstructorConstrainedCopier<>)); + options.AddSerializationContract(typeof(ParameterCopier<>), typeof(IDeepCopier<>), SerializationType.Parameter(0)); + options.AddSerializationContract(implementation, typeof(IDeepCopier<>), SerializationType.Parameter(0)); + using var services = new ServiceCollection().BuildServiceProvider(); + var provider = new CodecProvider(services, Options.Create(options)); + + Assert.Equal(GenericConstraintValidationResult.Unknown, + GenericConstraintValidator.Validate(implementation, [target], options.GenericArgumentMetadata)); + var exception = Assert.Throws(() => + SelectImplementation(provider, typeof(IDeepCopier<>), target, materialize: false)); + Assert.Contains(nameof(TypeManifestOptions.AddGenericArgumentMetadata), + Assert.IsType(exception.InnerException).Message); + Assert.Equal(0, implementation.ClosureAttempts); + Assert.Equal((accepted ? typeof(ConstructorConstrainedCopier<>) : typeof(ParameterCopier<>)).MakeGenericType(target), + SelectImplementation(provider, typeof(IDeepCopier<>), target)); + Assert.Equal(1, implementation.ClosureAttempts); + } + + [Theory] + [InlineData(typeof(EnumerableConstrainedCopier<,>), typeof(List), typeof(object), true)] + [InlineData(typeof(EnumerableConstrainedCopier<,>), typeof(string[]), typeof(object), true)] + [InlineData(typeof(EnumerableConstrainedCopier<,>), typeof(List), typeof(object), false)] + [InlineData(typeof(EnumerableConstrainedCopier<,>), typeof(List), typeof(string), false)] + [InlineData(typeof(EnumerableConstrainedCopier<,>), typeof(FirstTarget), typeof(string), false)] + [InlineData(typeof(ConsumerConstrainedCopier<,>), typeof(Consumer), typeof(string), true)] + [InlineData(typeof(ConsumerConstrainedCopier<,>), typeof(Consumer), typeof(object), false)] + [InlineData(typeof(ConsumerConstrainedCopier<,>), typeof(Consumer), typeof(int), false)] + [InlineData(typeof(InvariantConstrainedCopier<,>), typeof(Invariant), typeof(string), true)] + [InlineData(typeof(InvariantConstrainedCopier<,>), typeof(Invariant), typeof(object), false)] + [InlineData(typeof(NestedConsumerConstrainedCopier<,>), typeof(Consumer), typeof(string), true)] + [InlineData(typeof(NestedConsumerConstrainedCopier<,>), typeof(Consumer>), typeof(string), true)] + [InlineData(typeof(NestedConsumerConstrainedCopier<,>), typeof(Consumer>), typeof(int), false)] + [InlineData(typeof(GenericBaseConstrainedCopier<,>), typeof(GenericDerived), typeof(string), true)] + [InlineData(typeof(GenericBaseConstrainedCopier<,>), typeof(GenericDerived), typeof(object), false)] + public void StructuralConstraintsRespectGenericVarianceAndBaseTypes(Type definition, Type argument, Type item, bool accepted) + { + var options = new TypeManifestOptions(); + options.AddGenericArgumentMetadata(argument); + options.AddGenericArgumentMetadata(item); + var implementation = new CountingGenericImplementation(definition); + var description = SerializationType.Create(typeof(GenericTarget<,>), SerializationType.Parameter(0), SerializationType.Parameter(1)); + options.AddSerializationContract(typeof(PairFallbackCopier<,>), typeof(IDeepCopier<>), description); + options.AddSerializationContract(implementation, typeof(IDeepCopier<>), description); + using var services = new ServiceCollection().BuildServiceProvider(); + var provider = new CodecProvider(services, Options.Create(options)); + var target = typeof(GenericTarget<,>).MakeGenericType(argument, item); + + Assert.Equal(accepted ? GenericConstraintValidationResult.Valid : GenericConstraintValidationResult.Invalid, + GenericConstraintValidator.Validate(definition, [argument, item], options.GenericArgumentMetadata)); + Assert.Equal(accepted ? implementation : typeof(PairFallbackCopier<,>), + SelectImplementation(provider, typeof(IDeepCopier<>), target, materialize: false)); + Assert.Equal(0, implementation.ClosureAttempts); + Assert.Equal((accepted ? definition : typeof(PairFallbackCopier<,>)).MakeGenericType(argument, item), + SelectImplementation(provider, typeof(IDeepCopier<>), target)); + Assert.Equal(accepted ? 1 : 0, implementation.ClosureAttempts); + } + + [Fact] + public void BoundParameterRelationshipsRespectReorderedBindingsWithoutMaterialization() + { + var options = new TypeManifestOptions(); + options.AddSerializationContract(typeof(PairFallbackCopier<,>), typeof(IDeepCopier<>), + SerializationType.Create(typeof(GenericTarget<,>), SerializationType.Parameter(0), SerializationType.Parameter(1))); + var implementation = new CountingGenericImplementation(typeof(DependentConstrainedCopier<,>)); + options.AddSerializationContract(implementation, typeof(IDeepCopier<>), + SerializationType.Create(typeof(GenericTarget<,>), SerializationType.Parameter(1), SerializationType.Parameter(0))); + using var services = new ServiceCollection().BuildServiceProvider(); + var provider = new CodecProvider(services, Options.Create(options)); + + Assert.Equal(implementation, SelectImplementation(provider, typeof(IDeepCopier<>), + typeof(GenericTarget), materialize: false)); + Assert.Equal(typeof(PairFallbackCopier<,>), SelectImplementation(provider, typeof(IDeepCopier<>), + typeof(GenericTarget), materialize: false)); + Assert.Equal(0, implementation.ClosureAttempts); + } + + [Fact] + public void VariantConstraintInterfaceTraversalReusesAnAdmittedRootsCapturedInterfaces() + { + var options = new TypeManifestOptions(); + options.AddGenericArgumentMetadata(typeof(Consumer>)); + options.AddGenericArgumentMetadata(typeof(IEnumerable)); + options.AddGenericArgumentMetadata(typeof(string)); + var implementation = new CountingGenericImplementation(typeof(ListConsumerConstrainedCopier<,>)); + options.AddSerializationContract(implementation, typeof(IDeepCopier<>), + SerializationType.Create(typeof(GenericTarget<,>), SerializationType.Parameter(0), SerializationType.Parameter(1))); + using var services = new ServiceCollection().BuildServiceProvider(); + var provider = new CodecProvider(services, Options.Create(options)); + var target = typeof(GenericTarget>, string>); + + Assert.Equal(GenericConstraintValidationResult.Unknown, GenericConstraintValidator.Validate(implementation, + [typeof(Consumer>), typeof(string)], options.GenericArgumentMetadata)); + var exception = Assert.Throws(() => + SelectImplementation(provider, typeof(IDeepCopier<>), target, materialize: false)); + Assert.Contains("closed argument and constraint types", Assert.IsType(exception.InnerException).Message); + Assert.Equal(0, implementation.ClosureAttempts); + options.AddGenericArgumentMetadata(typeof(List)); + Assert.Contains(typeof(IEnumerable), options.GenericArgumentMetadata[typeof(IReadOnlyList)].Interfaces); + Assert.Equal(GenericConstraintValidationResult.Valid, GenericConstraintValidator.Validate(implementation, + [typeof(Consumer>), typeof(string)], options.GenericArgumentMetadata)); + Assert.Equal(implementation, SelectImplementation(provider, typeof(IDeepCopier<>), target, materialize: false)); + Assert.Equal(0, implementation.ClosureAttempts); + Assert.Equal(typeof(ListConsumerConstrainedCopier>, string>), + SelectImplementation(provider, typeof(IDeepCopier<>), target)); + Assert.Equal(1, implementation.ClosureAttempts); + } + + [Fact] + public void SpecialConstraintsRejectInvalidAndDisallowedByRefLikeArguments() + { + var options = new TypeManifestOptions(); + foreach (var argument in new[] { typeof(void), typeof(int).MakePointerType(), typeof(int).MakeByRefType(), typeof(Span), + typeof(TypedReference), typeof(ArgIterator), typeof(RuntimeArgumentHandle) }) + { + Assert.Equal(GenericConstraintValidationResult.Invalid, + GenericConstraintValidator.Validate(typeof(ParameterCopier<>), [argument], options.GenericArgumentMetadata)); + } +#if NET10_0_OR_GREATER + Assert.Equal(GenericConstraintValidationResult.Valid, + GenericConstraintValidator.Validate(typeof(AllowsByRefLikeCandidate<>), [typeof(Span)], options.GenericArgumentMetadata)); + Assert.Equal(GenericConstraintValidationResult.Invalid, + GenericConstraintValidator.Validate(typeof(AllowsByRefLikeCandidate<>), [typeof(TypedReference)], options.GenericArgumentMetadata)); +#endif + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public void InvalidListCandidatesPreserveInferredDefaultsAndValidCandidatesOverrideThem(bool converter) + { + var options = new TypeManifestOptions(); + options.AddDefaultSerializer, ListCodec, ListCopier>( + _ => throw new InvalidOperationException("Eligibility checks must not invoke factories."), + _ => throw new InvalidOperationException("Eligibility checks must not invoke factories.")); + var implementation = new CountingGenericImplementation(converter ? typeof(StructListConverter<>) : typeof(StructListCodec<>)); + if (converter) + { + options.AddConverter(implementation, typeof(List<>), typeof(GenericSurrogate<>)); + } + else + { + options.AddSerializer(implementation, typeof(List<>)); + } + using var services = new ServiceCollection().BuildServiceProvider(); + var provider = new CodecProvider(services, Options.Create(options)); + var eligibility = typeof(CodecProvider).GetMethod("IsDefaultContractImplementationEligible", BindingFlags.Instance | BindingFlags.NonPublic)!; + + Assert.Equal(true, eligibility.Invoke(provider, [options.DefaultSerializerContracts[typeof(IFieldCodec>)]])); + Assert.Equal(0, implementation.ClosureAttempts); + options.AddDefaultSerializer, ListCodec, ListCopier>( + _ => throw new InvalidOperationException("Eligibility checks must not invoke factories."), + _ => throw new InvalidOperationException("Eligibility checks must not invoke factories.")); + Assert.Equal(false, eligibility.Invoke(provider, [options.DefaultSerializerContracts[typeof(IFieldCodec>)]])); + Assert.Equal(0, implementation.ClosureAttempts); + } + [Fact] public void InvalidContractArgumentsThrowBeforeMutatingOptions() { @@ -1361,12 +1613,12 @@ private static TypeConverter CreateConverter(TypeManifestOptions options) => new(Array.Empty(), Array.Empty(), Array.Empty(), Options.Create(options), new CachedTypeResolver()); - private static Type SelectImplementation(CodecProvider provider, Type contract, Type target) + private static Type SelectImplementation(CodecProvider provider, Type contract, Type target, bool materialize = true) { var searchType = target.IsConstructedGenericType ? target.GetGenericTypeDefinition() : target; - object?[] arguments = [contract, target, searchType, null]; + object?[] arguments = [contract, target, searchType, null, null, materialize]; Assert.Equal(true, typeof(CodecProvider).GetMethod("TrySelectImplementation", BindingFlags.Instance | BindingFlags.NonPublic, - [typeof(Type), typeof(Type), typeof(Type), typeof(Type).MakeByRefType()])!.Invoke(provider, arguments)); + [typeof(Type), typeof(Type), typeof(Type), typeof(Type).MakeByRefType(), typeof(SerializationContract).MakeByRefType(), typeof(bool)])!.Invoke(provider, arguments)); return Assert.IsAssignableFrom(arguments[3]); } @@ -1494,6 +1746,35 @@ public sealed class StructTargetConstrainedCopier : ShallowCopier : ShallowCopier where T : class; public sealed class ConstructorConstrainedCopier : ShallowCopier where T : new(); public sealed class ComparableConstrainedCopier : ShallowCopier where T : IComparable; + public sealed class BaseConstrainedCopier : ShallowCopier where T : ConstraintBase; + public sealed class DisposableConstrainedCopier : ShallowCopier where T : IDisposable; + public sealed class NewDisposableConstrainedCopier : ShallowCopier where T : IDisposable, new(); + public sealed class EnumerableConstrainedCopier : ShallowCopier> where T : IEnumerable; + public interface IConsumer; + public sealed class Consumer : IConsumer; + public interface IInvariant; + public sealed class Invariant : IInvariant; + public sealed class ConsumerConstrainedCopier : ShallowCopier> where T : IConsumer; + public sealed class InvariantConstrainedCopier : ShallowCopier> where T : IInvariant; + public sealed class NestedConsumerConstrainedCopier : ShallowCopier> where T : IConsumer>; + public sealed class ListConsumerConstrainedCopier : ShallowCopier> where T : IConsumer>; + public class GenericBase; + public sealed class GenericDerived : GenericBase; + public sealed class GenericBaseConstrainedCopier : ShallowCopier> where T : GenericBase; +#if NET10_0_OR_GREATER + public sealed class AllowsByRefLikeCandidate where T : allows ref struct; +#endif + public sealed class StructListCodec : IFieldCodec> where T : struct + { + public void WriteField(ref Writer writer, uint id, [AllowNull] Type expected, [AllowNull] List value) + where TBufferWriter : IBufferWriter => throw new NotSupportedException(); + public List ReadValue(ref Reader reader, Field field) => throw new NotSupportedException(); + } + public sealed class StructListConverter : IConverter, GenericSurrogate> where T : struct + { + public List ConvertFromSurrogate(in GenericSurrogate surrogate) => throw new NotSupportedException(); + public GenericSurrogate ConvertToSurrogate(in List value) => throw new NotSupportedException(); + } public sealed class PairFallbackCopier : ShallowCopier>; public sealed class PairArrayFallbackCopier : ShallowCopier[]>; public sealed class DependentConstrainedCopier : ShallowCopier> where TDerived : TBase; From cef92f241e7e1a9fc06ccc4b8951118499f5f419 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Wed, 7 Oct 2026 06:49:41 -0700 Subject: [PATCH 43/54] fix(rpc): release response envelopes after successful remote writes --- .../docs/implementation/serialization.md | 2 + .../Networking/MessageWriteRequest.cs | 7 + .../MessageTransportLifecycleTests.cs | 153 ++++++++++++++++++ 3 files changed, 162 insertions(+) diff --git a/docs/site/src/content/docs/implementation/serialization.md b/docs/site/src/content/docs/implementation/serialization.md index 758f32c6b06..00d5ada5591 100644 --- a/docs/site/src/content/docs/implementation/serialization.md +++ b/docs/site/src/content/docs/implementation/serialization.md @@ -139,6 +139,8 @@ Incoming filters receive an isolated result and can transform its envelope or ne Generated holders implement . The message serializer selects their direct writer before runtime-type codec lookup. Primitive holders call the existing static primitive codecs; reference holders use their bound concrete result codec and the message's serialization session. The wire representation retains the result-type header, field zero, end marker, null behavior, cycles, and shared references. Returning a holder to its pool clears both its result and its provider-owned factory binding. +Successful remote write completion releases each response envelope and clears the message's reference to it after recording the send. Serialization and transport-write failures retain the envelope for retry or rerouting, preserving its payload until the successful write completes. + The receiving message serializer first consults using the result type from the wire header. Generated registrations reconstruct a bound holder directly. Compatibility paths retain ordinary response codecs for custom response/payload implementations, custom invokable bases, and unresolved generic contracts. Generated direct factories activate only when the selected result and response codecs/copiers match the canonical implementations, so explicit application behavior retains precedence. For concrete `Task` and `ValueTask` method results, the generator emits identical invocation code and closed response registrations for JIT and NativeAOT execution. Provider registration precedence selects the services in both execution modes. The graph uses the concrete result implementations in and . Recursive result dependencies resolve with a construction caller after the response implementation has been allocated. Reference payload codecs and copiers preserve payload cycles and shared references, and the pooled response envelope retains the existing field and raw-message encoding. diff --git a/src/Orleans.Core/Networking/MessageWriteRequest.cs b/src/Orleans.Core/Networking/MessageWriteRequest.cs index 543c3d32cbd..ef8014359ac 100644 --- a/src/Orleans.Core/Networking/MessageWriteRequest.cs +++ b/src/Orleans.Core/Networking/MessageWriteRequest.cs @@ -4,6 +4,7 @@ using Orleans.Connections.Transport; using Microsoft.Extensions.Logging; using System.Collections.Generic; +using Orleans.Serialization.Invocation; namespace Orleans.Runtime.Messaging; @@ -87,6 +88,12 @@ public override void SetResult() { foreach (var (message, _, _) in _messages) { + if (message._bodyObject is Response response) + { + message._bodyObject = null; + response.Dispose(); + } + message.ReleaseBodyBuffer(); } diff --git a/test/Orleans.Core.Tests/Networking/MessageTransportLifecycleTests.cs b/test/Orleans.Core.Tests/Networking/MessageTransportLifecycleTests.cs index 9e95a7a0973..badb0f2f05c 100644 --- a/test/Orleans.Core.Tests/Networking/MessageTransportLifecycleTests.cs +++ b/test/Orleans.Core.Tests/Networking/MessageTransportLifecycleTests.cs @@ -25,6 +25,8 @@ using Orleans.Serialization; using Orleans.Serialization.Buffers; using Orleans.Serialization.Cloning; +using Orleans.Serialization.Codecs; +using Orleans.Serialization.Invocation; using Orleans.Serialization.Session; using TestExtensions; using Xunit; @@ -555,6 +557,116 @@ public void MessageWriteRequest_SerializationFailure_PreservesValidPrefix() request.Reset(); } + [Fact] + public async Task MessageWriteRequest_Success_ReleasesResponseBodiesOnce() + { + using var services = CreateServiceProvider(); + using var shared = CreateMessageHandlerShared(services); + await using var transport = new CapturingTransport(); + var holder = new TrackedRawResponse("generated payload"); + var legacy = Response.FromResult("legacy payload"); + var sent = 0; + var connection = new ResponseSendConnection(transport, CreateConnectionCommon(services, shared), shared.MessageCenter, + message => + { + Assert.NotNull(message._bodyObject); + Assert.Equal(0, holder.DisposeCount); + Assert.Equal("legacy payload", legacy.GetResult()); + sent++; + }); + var request = shared.GetSendMessageHandler(connection); + var generatedMessage = new Message { Direction = Message.Directions.Response, BodyObject = holder }; + var legacyMessage = new Message { Direction = Message.Directions.Response, BodyObject = legacy }; + byte[] payload = [1, 2, 3]; + var ordinaryMessage = new Message { Direction = Message.Directions.Request, BodyObject = payload }; + request.WriteMessage(generatedMessage); + request.WriteMessage(legacyMessage); + request.WriteMessage(ordinaryMessage); + Assert.Equal(0, holder.DisposeCount); + Assert.Equal("generated payload", holder.GetResult()); + + Assert.True(transport.EnqueueWrite(request)); + + Assert.Equal(3, sent); + Assert.Equal(1, holder.DisposeCount); + Assert.Null(holder.Result); + Assert.Null(legacy.GetResult()); + Assert.Null(generatedMessage._bodyObject); + Assert.Null(legacyMessage._bodyObject); + Assert.Same(payload, ordinaryMessage._bodyObject); + Assert.Equal(0, request.MessageCount); + Assert.Equal(0, request.Length); + generatedMessage.Dispose(); + legacyMessage.Dispose(); + Assert.Equal(1, holder.DisposeCount); + await connection.CloseAsync(null); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task MessageWriteRequest_WriteFailure_PreservesResponseForSuccessfulRetry(bool direct) + { + using var services = CreateServiceProvider(); + using var shared = CreateMessageHandlerShared(services); + await using var transport = new CapturingTransport(); + var connection = new ResponseSendConnection(transport, CreateConnectionCommon(services, shared), shared.MessageCenter); + var response = direct ? (Response)new TrackedRawResponse("retry payload") : Response.FromResult("retry payload"); + var message = new Message { Direction = Message.Directions.Response, BodyObject = response }; + var request = shared.GetSendMessageHandler(connection); + request.WriteMessage(message); + var firstFrame = new byte[request.Length]; + request.Buffers.Consume(firstFrame); + var failure = new IOException("write failed"); + + request.SetException(failure); + var rerouted = await connection.Retried.WaitAsync(TestContext.Current.CancellationToken); + + Assert.Same(message, rerouted.Message); + Assert.Same(failure, rerouted.Error); + Assert.Same(response, message._bodyObject); + Assert.Equal("retry payload", response.GetResult()); + if (response is TrackedRawResponse holder) Assert.Equal(0, holder.DisposeCount); + Assert.Equal(0, request.MessageCount); + request = shared.GetSendMessageHandler(connection); + request.WriteMessage(message); + Assert.True(transport.EnqueueWrite(request)); + Assert.Equal(firstFrame, transport.Written); + Assert.Null(message._bodyObject); + Assert.Null(response.Result); + if (response is TrackedRawResponse returned) Assert.Equal(1, returned.DisposeCount); + await connection.CloseAsync(null); + } + + [Fact] + public async Task MessageWriteRequest_SerializationFailure_RetainsResponseAndValidPrefix() + { + using var services = CreateServiceProvider(); + using var shared = CreateMessageHandlerShared(services); + await using var transport = new CapturingTransport(); + var connection = new ResponseSendConnection(transport, CreateConnectionCommon(services, shared), shared.MessageCenter); + var request = shared.GetSendMessageHandler(connection); + request.WriteMessage(new Message()); + var validLength = request.Length; + var response = new TrackedRawResponse("serialization retry") { FailWriting = true }; + var message = new Message { Direction = Message.Directions.Response, BodyObject = response }; + + Assert.Throws(() => request.WriteMessage(message)); + + Assert.Equal(validLength, request.Length); + Assert.Equal(1, request.MessageCount); + Assert.Same(response, message._bodyObject); + Assert.Equal("serialization retry", response.Result); + Assert.Equal(0, response.DisposeCount); + response.FailWriting = false; + request.WriteMessage(message); + Assert.True(transport.EnqueueWrite(request)); + Assert.Null(message._bodyObject); + Assert.Null(response.Result); + Assert.Equal(1, response.DisposeCount); + await connection.CloseAsync(null); + } + [Fact] public void MessageWriteRequest_LargeMessageState_TracksFramesAndAdaptsPageSize() { @@ -988,6 +1100,47 @@ protected internal override void RecordMessageSend(Message message, int totalByt public void Dispose() => _releaseSend.Dispose(); } + private sealed class ResponseSendConnection( + MessageTransport transport, + ConnectionCommon shared, + IMessageCenter messageCenter, + Action? recordSend = null) : Connection(transport, shared) + { + private readonly TaskCompletionSource<(Message Message, Exception? Error)> _retried = new(TaskCreationOptions.RunContinuationsAsynchronously); + public Task<(Message Message, Exception? Error)> Retried => _retried.Task; + protected override ConnectionDirection ConnectionDirection => ConnectionDirection.SiloToSilo; + protected override TimeSpan CloseConnectionTimeout => TimeSpan.FromSeconds(1); + protected override IMessageCenter MessageCenter => messageCenter; + protected override bool PrepareMessageForSend(Message msg) => true; + protected override void RetryMessage(Message msg, Exception? ex = null) => _retried.SetResult((msg, ex)); + protected internal override void OnReceivedMessage(Message message) { } + protected internal override void RecordMessageReceive(Message message, int totalBytes, int headerBytes) { } + protected internal override void RecordMessageSend(Message message, int totalBytes, int headerBytes) => recordSend?.Invoke(message); + } + + private sealed class TrackedRawResponse(string payload) : Response, IRawResponseWriter + { + public int DisposeCount { get; private set; } + public bool FailWriting { get; set; } + public override object? Result { get; set; } = payload; + public override Exception? Exception { get; set; } + public override Type GetSimpleResultType() => typeof(string); + public override T GetResult() => (T)Result!; + public override void Dispose() + { + DisposeCount++; + Result = null; + } + + public void WriteRaw(ref Writer writer) where TBufferWriter : IBufferWriter + { + writer.WriteStartObject(0, null!, typeof(string)); + if (Result is string value) StringCodec.WriteField(ref writer, 0, value); + if (FailWriting) throw new InvalidOperationException("response serialization failed"); + writer.WriteEndObject(); + } + } + private sealed class CancelableTransport(bool completeWrites = false) : MessageTransport { private readonly CancellationTokenSource _closed = new(); From 57fb0ac5cb29798a4f46444de9aa7a29052f415f Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Wed, 7 Oct 2026 08:35:48 -0700 Subject: [PATCH 44/54] fix(rpc): consume received response envelopes at completion boundaries --- .../docs/implementation/serialization.md | 2 + src/Orleans.Core/Core/GrainMethodInvoker.cs | 48 +----- src/Orleans.Core/Core/ResponseCopyBoundary.cs | 50 ++++++ src/Orleans.Core/Runtime/CallbackData.cs | 1 + .../Runtime/GrainReferenceRuntime.cs | 4 +- .../Runtime/OutgoingCallInvoker.cs | 7 +- .../Invocation/IResponseCompletionSource.cs | 8 +- .../Invocation/ResponseCompletionSource.cs | 92 +++++++---- .../SelfWritingResponseOwnershipTests.cs | 143 +++++++++++++++++ .../ResponseCompletionSourceTests.cs | 151 +++++++++++++++++- 10 files changed, 422 insertions(+), 84 deletions(-) diff --git a/docs/site/src/content/docs/implementation/serialization.md b/docs/site/src/content/docs/implementation/serialization.md index 00d5ada5591..418282e4821 100644 --- a/docs/site/src/content/docs/implementation/serialization.md +++ b/docs/site/src/content/docs/implementation/serialization.md @@ -141,6 +141,8 @@ Generated holders implement . Typed completion extracts the result and releases the envelope, preserving the result payload for the caller. Untyped completion transfers a successful envelope to its awaiting consumer; void consumption releases it directly. Outgoing filters retain selected and superseded envelopes through their continuations, and the invocation releases them after extracting the final result or unwinding a failure. Application code calling `Complete` transfers ownership and leaves envelope disposal to the completion pipeline. + The receiving message serializer first consults using the result type from the wire header. Generated registrations reconstruct a bound holder directly. Compatibility paths retain ordinary response codecs for custom response/payload implementations, custom invokable bases, and unresolved generic contracts. Generated direct factories activate only when the selected result and response codecs/copiers match the canonical implementations, so explicit application behavior retains precedence. For concrete `Task` and `ValueTask` method results, the generator emits identical invocation code and closed response registrations for JIT and NativeAOT execution. Provider registration precedence selects the services in both execution modes. The graph uses the concrete result implementations in and . Recursive result dependencies resolve with a construction caller after the response implementation has been allocated. Reference payload codecs and copiers preserve payload cycles and shared references, and the pooled response envelope retains the existing field and raw-message encoding. diff --git a/src/Orleans.Core/Core/GrainMethodInvoker.cs b/src/Orleans.Core/Core/GrainMethodInvoker.cs index 333ab5c95e4..079234a3339 100644 --- a/src/Orleans.Core/Core/GrainMethodInvoker.cs +++ b/src/Orleans.Core/Core/GrainMethodInvoker.cs @@ -24,8 +24,7 @@ internal sealed class GrainMethodInvoker : IIncomingGrainCallContext, IDisposabl private readonly IGrainContext grainContext; private readonly ICodecProvider codecProvider; private readonly CopyContextPool copyContexts; - private Response? response; - private List? otherOwnedResponses; + private ResponseOwnership responses; private int stage; /// @@ -79,50 +78,13 @@ public object? Result public Response? Response { - get => response; - set - { - if (ReferenceEquals(response, value)) return; - if (response is { } previous) - { - (otherOwnedResponses ??= []).Add(previous); - } - - if (value is not null && otherOwnedResponses is { } others) - { - for (var i = others.Count - 1; i >= 0; i--) - { - if (ReferenceEquals(value, others[i])) others.RemoveAt(i); - } - } - - response = value; - } + get => responses.Value; + set => responses.Value = value; } - internal Response TakeResponse() - { - var result = response!; - response = null; - return result; - } + internal Response TakeResponse() => responses.Take(); - public void Dispose() - { - var current = response; - response = null; - var others = otherOwnedResponses; - otherOwnedResponses = null; - try - { - current?.Dispose(); - } - finally - { - if (others is not null) - foreach (var entry in others) entry.Dispose(); - } - } + public void Dispose() => responses.Dispose(); public GrainId? SourceId => message.SendingGrain is { IsDefault: false } source ? source : null; diff --git a/src/Orleans.Core/Core/ResponseCopyBoundary.cs b/src/Orleans.Core/Core/ResponseCopyBoundary.cs index 2384391c503..86aab434b94 100644 --- a/src/Orleans.Core/Core/ResponseCopyBoundary.cs +++ b/src/Orleans.Core/Core/ResponseCopyBoundary.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using Orleans.Serialization; using Orleans.Serialization.Cloning; @@ -28,3 +29,52 @@ internal static Response CopyAndDispose(Response response, DeepCopier internal static Response CopyAndDispose(Response response, DeepCopier copier) => OrleansGeneratedCodeHelper.CopyResponseAndDispose(response, copier); } + +internal struct ResponseOwnership : IDisposable +{ + private Response? _current; + private List? _others; + + internal Response? Value + { + readonly get => _current; + set + { + if (ReferenceEquals(_current, value)) return; + if (_current is { } previous) (_others ??= []).Add(previous); + if (value is not null && _others is { } others) + { + for (var i = others.Count - 1; i >= 0; i--) + { + if (ReferenceEquals(value, others[i])) others.RemoveAt(i); + } + } + + _current = value; + } + } + + internal Response Take() + { + var result = _current!; + _current = null; + return result; + } + + public void Dispose() + { + var current = _current; + _current = null; + var others = _others; + _others = null; + try + { + current?.Dispose(); + } + finally + { + if (others is not null) + foreach (var response in others) response.Dispose(); + } + } +} diff --git a/src/Orleans.Core/Runtime/CallbackData.cs b/src/Orleans.Core/Runtime/CallbackData.cs index 92f3c7dc463..f43a8449836 100644 --- a/src/Orleans.Core/Runtime/CallbackData.cs +++ b/src/Orleans.Core/Runtime/CallbackData.cs @@ -240,6 +240,7 @@ private static void ResponseCallback(Message message, IResponseCompletionSource try { var body = message.BodyObject; + message._bodyObject = null; if (body is Response response) { context.Complete(response); diff --git a/src/Orleans.Core/Runtime/GrainReferenceRuntime.cs b/src/Orleans.Core/Runtime/GrainReferenceRuntime.cs index 2cde50e9d0b..3fc322ebf68 100644 --- a/src/Orleans.Core/Runtime/GrainReferenceRuntime.cs +++ b/src/Orleans.Core/Runtime/GrainReferenceRuntime.cs @@ -86,7 +86,7 @@ public void InvokeMethod(GrainReference reference, IInvokable request, InvokeMet private async ValueTask InvokeMethodWithFiltersAsync(GrainReference reference, IInvokable request, InvokeMethodOptions options) { SetGrainCancellationTokensTarget(reference, request); - var invoker = new OutgoingCallInvoker(reference, request, options, this.sendRequest, this.filters); + using var invoker = new OutgoingCallInvoker(reference, request, options, this.sendRequest, this.filters); await invoker.Invoke(); return invoker.TypedResult; } @@ -94,7 +94,7 @@ public void InvokeMethod(GrainReference reference, IInvokable request, InvokeMet private async ValueTask InvokeMethodWithFiltersAsync(GrainReference reference, IInvokable request, InvokeMethodOptions options) { SetGrainCancellationTokensTarget(reference, request); - var invoker = new OutgoingCallInvoker(reference, request, options, this.sendRequest, this.filters); + using var invoker = new OutgoingCallInvoker(reference, request, options, this.sendRequest, this.filters); await invoker.Invoke(); } diff --git a/src/Orleans.Core/Runtime/OutgoingCallInvoker.cs b/src/Orleans.Core/Runtime/OutgoingCallInvoker.cs index 073d5ab0fb1..aebaf52933c 100644 --- a/src/Orleans.Core/Runtime/OutgoingCallInvoker.cs +++ b/src/Orleans.Core/Runtime/OutgoingCallInvoker.cs @@ -9,7 +9,7 @@ namespace Orleans.Runtime /// /// Invokes a request on a grain reference. /// - internal sealed class OutgoingCallInvoker : IOutgoingGrainCallContext + internal sealed class OutgoingCallInvoker : IOutgoingGrainCallContext, IDisposable { private readonly IInvokable request; private readonly InvokeMethodOptions options; @@ -18,6 +18,7 @@ internal sealed class OutgoingCallInvoker : IOutgoingGrainCallContext private readonly int stages; private readonly GrainReference grainReference; private readonly IOutgoingGrainCallFilter? requestFilter; + private ResponseOwnership responses; private int stage; /// @@ -58,7 +59,9 @@ public OutgoingCallInvoker( public object? Result { get => TypedResult; set => TypedResult = (TResult?)value; } - public Response? Response { get; set; } + public Response? Response { get => responses.Value; set => responses.Value = value; } + + public void Dispose() => responses.Dispose(); public TResult? TypedResult { get => Response!.GetResult(); set => Response = Response.FromResult(value); } diff --git a/src/Orleans.Serialization/Invocation/IResponseCompletionSource.cs b/src/Orleans.Serialization/Invocation/IResponseCompletionSource.cs index f68e7a888f7..a55947c7965 100644 --- a/src/Orleans.Serialization/Invocation/IResponseCompletionSource.cs +++ b/src/Orleans.Serialization/Invocation/IResponseCompletionSource.cs @@ -6,9 +6,13 @@ namespace Orleans.Serialization.Invocation public interface IResponseCompletionSource { /// - /// Sets the result. + /// Completes the promise and takes ownership of the response envelope. /// - /// The result value. + /// The response whose ownership is transferred to this instance. + /// + /// Typed completion extracts the payload and disposes the envelope. Untyped completion transfers a successful + /// envelope to its result consumer, which disposes it after use. + /// void Complete(Response value); /// diff --git a/src/Orleans.Serialization/Invocation/ResponseCompletionSource.cs b/src/Orleans.Serialization/Invocation/ResponseCompletionSource.cs index f9fe380fc1d..4f3c8a6dc51 100644 --- a/src/Orleans.Serialization/Invocation/ResponseCompletionSource.cs +++ b/src/Orleans.Serialization/Invocation/ResponseCompletionSource.cs @@ -18,12 +18,14 @@ public sealed class ResponseCompletionSource : IResponseCompletionSource, IValue /// Returns this instance as a . /// /// This instance, as a . + /// The consumer owns the returned response and disposes it after use. public ValueTask AsValueTask() => new(this, _core.Version); /// /// Returns this instance as a . /// /// This instance, as a . + /// Consuming the task disposes the response envelope. public ValueTask AsVoidValueTask() => new(this, _core.Version); /// @@ -50,23 +52,37 @@ public void Reset() /// /// Completes this instance with a result. /// - /// The result. + /// The response whose ownership is transferred to this instance. + /// + /// Successful responses are transferred to the result consumer. Exception responses are disposed after + /// their exception is extracted. + /// public void SetResult(Response result) { - if (result.Exception is not { } exception) + var transferred = false; + try { - _core.SetResult(result); + if (result.Exception is not { } exception) + { + _core.SetResult(result); + transferred = true; + } + else + { + _core.SetException(exception); + } } - else + finally { - _core.SetException(exception); + if (!transferred) result.Dispose(); } } /// /// Completes this instance with a result. /// - /// The result value. + /// The response whose ownership is transferred to this instance. + /// Successful envelopes remain owned by the result consumer until it finishes using them. public void Complete(Response value) => SetResult(value); /// @@ -97,7 +113,7 @@ void IValueTaskSource.GetResult(short token) bool isValid = token == _core.Version; try { - _ = _core.GetResult(token); + _core.GetResult(token).Dispose(); } finally { @@ -162,33 +178,40 @@ public void Reset() [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Complete(Response value) { - // Check exception first since it's a simple null check - if (value.Exception is { } exception) + try { - SetException(exception); - return; - } + // Check exception first since it's a simple null check + if (value.Exception is { } exception) + { + SetException(exception); + return; + } - // Check for typed response (common for void returns) - if (value is Response typed) - { - SetResult(typed.TypedResult); - return; - } + // Check for typed response (common for void returns) + if (value is Response typed) + { + SetResult(typed.TypedResult); + return; + } - // Handle untyped successful response - var result = value.Result; - if (result is null) - { - SetResult(default); - } - else if (result is TResult typedResult) - { - SetResult(typedResult); + // Handle untyped successful response + var result = value.Result; + if (result is null) + { + SetResult(default); + } + else if (result is TResult typedResult) + { + SetResult(typedResult); + } + else + { + SetInvalidCastException(result); + } } - else + finally { - SetInvalidCastException(result); + value.Dispose(); } } @@ -214,16 +237,17 @@ private void SetInvalidCastException(object result) /// /// Completes this instance with a result. /// - /// The result value. + /// The response whose ownership is transferred to this instance. + /// The envelope is disposed after extracting its result. The result payload remains available to the consumer. public void Complete(Response value) { - if (value.Exception is { } exception) + try { - SetException(exception); + SetResult(value.TypedResult); } - else + finally { - SetResult(value.TypedResult); + value.Dispose(); } } diff --git a/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs index cc3c8bccc78..49fa72d742a 100644 --- a/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs +++ b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs @@ -36,6 +36,83 @@ namespace UnitTests.Serialization; [TestCategory("BVT"), TestCategory("Serialization")] public sealed class SelfWritingResponseOwnershipTests { + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task RemoteCallback_ConsumesTypedOrVoidResponseExactlyOnce(bool voidCall) + { + var counts = new Counts(); + await using var fixture = new CallbackFixture(counts, []); + var request = new LegacyRequest(new Payload(), counts); + + if (voidCall) await fixture.Runtime.InvokeMethodAsync(fixture.Reference, request, InvokeMethodOptions.None); + else + { + var result = await fixture.Runtime.InvokeMethodAsync(fixture.Reference, request, InvokeMethodOptions.None); + Assert.Equal(new[] { 17, 25, 42 }, result!.Values); + } + + Assert.Equal(1, counts.Rents); + Assert.Equal(1, counts.Returns); + Assert.Null(fixture.ReceivedResponse!.Result); + Assert.False(fixture.ReceivedResponse.HasBinding); + Assert.Null(fixture.ReceivedMessage!._bodyObject); + } + + [Theory] + [InlineData(false, false, false)] + [InlineData(false, false, true)] + [InlineData(false, true, false)] + [InlineData(false, true, true)] + [InlineData(true, false, false)] + [InlineData(true, false, true)] + [InlineData(true, true, false)] + [InlineData(true, true, true)] + public async Task OutgoingFilter_RetainsSelectedAndSupersededResponsesUntilConsumption(bool voidCall, bool restore, bool fail) + { + var counts = new Counts(); + var failure = new InvalidOperationException("outgoing filter failed"); + CallbackFixture fixture = null!; + var filter = new OutgoingCallbackFilter(async context => + { + await context.Invoke(); + var original = Assert.IsType(context.Response); + Assert.Equal(new[] { 17, 25, 42 }, Assert.IsType(context.Result).Values); + Assert.Equal(0, counts.Returns); + context.Response = CountedResponse.Rent(new Payload { Values = [47, 59] }, counts, fixture.Codec); + if (restore) context.Response = original; + Assert.Equal(0, counts.Returns); + Assert.Equal(new[] { 17, 25, 42 }, Assert.IsType(original.Result).Values); + if (fail) throw failure; + }); + await using var ownedFixture = fixture = new CallbackFixture(counts, [filter]); + var request = new LegacyRequest(new Payload(), counts); + + async Task Invoke() + { + if (voidCall) await fixture.Runtime.InvokeMethodAsync(fixture.Reference, request, InvokeMethodOptions.None); + else + { + var result = await fixture.Runtime.InvokeMethodAsync(fixture.Reference, request, InvokeMethodOptions.None); + Assert.Equal(restore ? new[] { 17, 25, 42 } : new[] { 47, 59 }, result!.Values); + } + } + + if (fail) Assert.Same(failure, await Assert.ThrowsAsync(Invoke)); + else await Invoke(); + + Assert.Equal(2, counts.Rents); + Assert.Equal(2, counts.Returns); + Assert.Null(fixture.ReceivedResponse!.Result); + Assert.False(fixture.ReceivedResponse.HasBinding); + Assert.Null(fixture.ReceivedMessage!._bodyObject); + var first = ResponsePool.GetGenerated(); + var second = ResponsePool.GetGenerated(); + Assert.NotSame(first, second); + ResponsePool.ReturnGenerated(first); + ResponsePool.ReturnGenerated(second); + } + [Fact] public void MigrationArgumentCodec_RetainsOrdinaryHostDependencyResolution() { @@ -571,6 +648,7 @@ private sealed class CountedResponse : Response, IRawResponseWriter private Payload _value = null!; public CountedResponse() { } + public bool HasBinding => _counts is not null || _codec is not null; public static CountedResponse Rent(Payload value, Counts counts, IFieldCodec codec) { @@ -894,6 +972,71 @@ public async ValueTask DisposeAsync() } } + private sealed class OutgoingCallbackFilter(Func callback) : IOutgoingGrainCallFilter + { + public Task Invoke(IOutgoingGrainCallContext context) => callback(context); + } + + private sealed class CallbackFixture : IAsyncDisposable + { + private readonly ServiceProvider _services; + private readonly MessageSerializer _serializer; + public GrainReferenceRuntime Runtime { get; } + public GrainReference Reference { get; } + public IFieldCodec Codec { get; } + public CountedResponse? ReceivedResponse { get; private set; } + public Message? ReceivedMessage { get; private set; } + + public CallbackFixture(Counts counts, IOutgoingGrainCallFilter[] filters) + { + var services = new ServiceCollection().AddMetrics(); + services.AddSerializer(builder => builder.Configure(options => + options.AddRawResponseReader(provider => new OwnedRawReader(provider.GetCodec(), counts)))); + _services = services.BuildServiceProvider(); + Codec = _services.GetRequiredService().GetCodec(); + _serializer = new MessageSerializer(_services.GetRequiredService(), new SiloMessagingOptions()); + var runtimeClient = Substitute.For(); + Runtime = new GrainReferenceRuntime(runtimeClient, null!, filters, null!, null!); + var grainId = GrainId.Create("callback-ownership", "target"); + var referenceProvider = new UntypedReferenceProvider(_services, Runtime); + Assert.True(referenceProvider.TryGet(grainId.Type, GrainInterfaceType.Create("callback-ownership"), out var activator)); + Reference = activator.CreateReference(grainId); + var instruments = new ApplicationRequestInstruments(new OrleansInstruments(_services.GetRequiredService())); + runtimeClient.When(client => client.SendRequest( + Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any())) + .Do(call => + { + using var sender = Response.FromResult(new Payload { Values = [17, 25, 42] }); + var frame = SelfWritingResponseMessageTests.WriteFrame(_serializer, + new Message { Direction = Message.Directions.Response, BodyObject = sender }); + ReceivedMessage = SelfWritingResponseMessageTests.ReadFrame(_serializer, frame); + ReceivedResponse = Assert.IsType(ReceivedMessage.BodyObject); + var shared = new SharedCallbackData(_ => { }, NullLogger.Instance, + TimeProvider.System, TimeSpan.FromMinutes(1), false, false, null); + var callback = new CallbackData(shared, call.Arg(), + new Message { BodyObject = call.Arg() }, instruments); + callback.DoCallback(ReceivedMessage); + }); + } + + public async ValueTask DisposeAsync() + { + _serializer.Dispose(); + await _services.DisposeAsync(); + } + } + + private sealed class OwnedRawReader(IFieldCodec codec, Counts counts) : IRawResponseReader + { + private readonly PooledResponseCodec> _codec = new(codec); + public bool IsSupported => true; + public Response ReadRaw(ref Reader reader, scoped ref Orleans.Serialization.WireProtocol.Field field) + { + using var decoded = (Response)_codec.ReadRaw(ref reader, ref field); + return CountedResponse.Rent(decoded.TypedResult!, counts, codec); + } + } + private sealed class UntypedReferenceProvider(IServiceProvider services, IGrainReferenceRuntime runtime) : IGrainReferenceActivatorProvider { public bool TryGet(GrainType grainType, GrainInterfaceType interfaceType, [NotNullWhen(true)] out IGrainReferenceActivator? activator) diff --git a/test/Orleans.Serialization.UnitTests/ResponseCompletionSourceTests.cs b/test/Orleans.Serialization.UnitTests/ResponseCompletionSourceTests.cs index 56c36cb3fe1..eb424ef33b8 100644 --- a/test/Orleans.Serialization.UnitTests/ResponseCompletionSourceTests.cs +++ b/test/Orleans.Serialization.UnitTests/ResponseCompletionSourceTests.cs @@ -23,7 +23,7 @@ public async Task TypedCompletionRunsContinuationsAsynchronously() var awaiter = source.AsValueTask().GetAwaiter(); var continuation = RegisterContinuation(awaiter); - using var response = Response.FromResult(42); + var response = Response.FromResult(42); continuation.CompletionThreadId = Thread.CurrentThread.ManagedThreadId; source.Complete(response); @@ -60,6 +60,155 @@ public async Task UntypedCompletionRunsContinuationsAsynchronously() } } + [Fact] + public async Task TypedCompletionConsumesEnvelopeAndPreservesPayload() + { + var payload = new[] { 17, 25, 42 }; + var response = new TrackedResponse(payload); + var source = ResponseCompletionSourcePool.Get(); + + source.Complete(response); + + Assert.Equal(1, response.DisposeCount); + Assert.Null(response.Result); + Assert.Null(response.Binding); + Assert.Same(payload, await source.AsValueTask()); + Assert.Equal(new[] { 17, 25, 42 }, payload); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task TypedCompletionConsumesBothResponseOverloads(bool typedOverload) + { + var payload = new[] { 17, 25, 42 }; + var response = ResponsePool.Get(); + response.TypedResult = payload; + var source = ResponseCompletionSourcePool.Get(); + + if (typedOverload) source.Complete(response); + else source.Complete((Response)response); + + Assert.Null(response.TypedResult); + Assert.Same(payload, await source.AsValueTask()); + } + + [Fact] + public async Task TypedCompletionInvalidCastReleasesEnvelope() + { + var response = new TrackedResponse("wrong result type"); + var source = ResponseCompletionSourcePool.Get(); + + source.Complete(response); + + Assert.Equal(1, response.DisposeCount); + Assert.Null(response.Result); + Assert.Null(response.Binding); + var exception = await Assert.ThrowsAsync(() => source.AsValueTask().AsTask()); + Assert.Contains(typeof(int).ToString(), exception.Message); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task TypedCompletionPreservesDefaultResults(bool completed) + { + var source = ResponseCompletionSourcePool.Get(); + source.Complete(completed ? Response.Completed : new TrackedResponse(null)); + Assert.Equal(0, await source.AsValueTask()); + } + + [Fact] + public void FailedResultExtractionReleasesEnvelope() + { + var failure = new InvalidOperationException("result extraction failed"); + var response = new TrackedResponse(new[] { 17, 25, 42 }) { Failure = failure }; + var source = new ResponseCompletionSource(); + + Assert.Same(failure, Assert.Throws(() => source.Complete(response))); + + Assert.Equal(1, response.DisposeCount); + Assert.Null(response.Binding); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task ExceptionCompletionConsumesEnvelopeAndPreservesException(bool typed) + { + var failure = new InvalidOperationException("remote failure"); + var response = new TrackedResponse(null) { Exception = failure }; + Task completion; + if (typed) + { + var source = ResponseCompletionSourcePool.Get(); + source.Complete(response); + completion = source.AsValueTask().AsTask(); + } + else + { + var source = ResponseCompletionSourcePool.Get(); + source.Complete(response); + completion = source.AsValueTask().AsTask(); + } + + Assert.Equal(1, response.DisposeCount); + Assert.Null(response.Binding); + Assert.Same(failure, await Assert.ThrowsAsync(() => completion)); + } + + [Fact] + public async Task UntypedCompletionTransfersEnvelopeToConsumer() + { + var payload = new[] { 17, 25, 42 }; + var response = new TrackedResponse(payload); + var source = ResponseCompletionSourcePool.Get(); + + source.Complete(response); + var received = await source.AsValueTask(); + + Assert.Same(response, received); + Assert.Equal(0, response.DisposeCount); + Assert.Same(payload, received.GetResult()); + received.Dispose(); + Assert.Equal(1, response.DisposeCount); + Assert.Null(response.Result); + Assert.Null(response.Binding); + } + + [Fact] + public async Task UntypedVoidConsumptionReleasesEnvelope() + { + var response = new TrackedResponse(new[] { 17, 25, 42 }); + var source = ResponseCompletionSourcePool.Get(); + var completion = source.AsVoidValueTask(); + + source.Complete(response); + Assert.Equal(0, response.DisposeCount); + await completion; + + Assert.Equal(1, response.DisposeCount); + Assert.Null(response.Result); + Assert.Null(response.Binding); + } + + private sealed class TrackedResponse(object? payload) : Response + { + private object? _result = payload; + public int DisposeCount { get; private set; } + public object? Binding { get; private set; } = new(); + public Exception? Failure { get; init; } + public override object? Result { get => Failure is { } failure ? throw failure : _result; set => _result = value; } + public override Exception? Exception { get; set; } + public override T GetResult() => (T)Result!; + public override void Dispose() + { + DisposeCount++; + Result = null; + Binding = null; + } + } + private static ContinuationProbe RegisterContinuation(ValueTaskAwaiter awaiter) { var continuation = new ContinuationProbe(); From 8ad231eb5fb8440b0046207b8e7a7454521fabac Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Wed, 7 Oct 2026 08:41:57 -0700 Subject: [PATCH 45/54] fix(aot): align metadata smoke with generic constraint admission Register source-known metadata for constructor-constrained targets and apply the generator layout required by CI. --- .../SerializerFactoryGenerator.cs | 10 ++++++++-- test/Orleans.NativeAotSmoke/Metadata.cs | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs b/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs index 0339e57edef..40caf45312a 100644 --- a/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs +++ b/src/Orleans.CodeGenerator/SerializerFactoryGenerator.cs @@ -29,8 +29,14 @@ internal Registration Clone() { var result = new Registration(Type) { - Codec = Codec, Copier = Copier, CodecConstruction = CodecConstruction, CopierConstruction = CopierConstruction, - Model = Model, ResponseResult = ResponseResult, ReferencedCodec = ReferencedCodec, ReferencedCopier = ReferencedCopier + Codec = Codec, + Copier = Copier, + CodecConstruction = CodecConstruction, + CopierConstruction = CopierConstruction, + Model = Model, + ResponseResult = ResponseResult, + ReferencedCodec = ReferencedCodec, + ReferencedCopier = ReferencedCopier }; result.Dependencies.AddRange(Dependencies); result.CanonicalArrays.AddRange(CanonicalArrays); diff --git a/test/Orleans.NativeAotSmoke/Metadata.cs b/test/Orleans.NativeAotSmoke/Metadata.cs index 053930737ab..04cdbdca224 100644 --- a/test/Orleans.NativeAotSmoke/Metadata.cs +++ b/test/Orleans.NativeAotSmoke/Metadata.cs @@ -430,6 +430,8 @@ private static void ValidateGenericConstraints(IServiceProvider serializerServic options = new TypeManifestOptions(); options.AddSerializationContract(typeof(MetadataConstraintFallbackCopier<>), typeof(IDeepCopier<>), SerializationType.Parameter(0)); options.AddSerializationContract(typeof(MetadataConstructorConstrainedCopier<>), typeof(IDeepCopier<>), SerializationType.Parameter(0)); + options.AddGenericArgumentMetadata(typeof(MetadataPrivateConstructorTarget)); + options.AddGenericArgumentMetadata(typeof(MetadataPublicConstructorTarget)); provider = new CodecProvider(services, Options.Create(options)); if (provider.GetDeepCopier().GetType() != typeof(MetadataConstraintFallbackCopier) || provider.GetDeepCopier().GetType() != typeof(MetadataConstructorConstrainedCopier)) From 8d31c778bb1e36803d539db170c780678cc7332f Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Wed, 7 Oct 2026 12:20:50 -0700 Subject: [PATCH 46/54] refactor(rpc): unify invocation contracts and filter lifetimes Move InvokeAndCopy onto IInvokable, share request/stage/response lifetime in GrainCallInvoker, and remove the copy-boundary and ownership wrappers. Preserve original exceptions through filters and copy exception envelopes at delivery. --- .../docs/implementation/serialization.md | 2 +- .../InvokableGenerator.cs | 5 +- src/Orleans.Core/Core/GrainCallInvoker.cs | 94 +++++++++++++ src/Orleans.Core/Core/GrainMethodInvoker.cs | 130 +++--------------- src/Orleans.Core/Core/ResponseCopyBoundary.cs | 80 ----------- .../Runtime/InvokableObjectManager.cs | 7 +- .../Runtime/OutgoingCallInvoker.cs | 98 +++---------- .../Core/InsideRuntimeClient.cs | 7 +- .../Invocation/IInvokable.cs | 36 +++++ .../Invocation/IResponseInvokable.cs | 20 --- src/api/Orleans.Core/Orleans.Core.cs | 52 +++---- .../Orleans.Serialization.cs | 6 +- .../Orleans.Streaming/Orleans.Streaming.cs | 8 +- .../Orleans.Transactions.TestKit.Base.cs | 4 +- .../OrleansSourceGeneratorTests.cs | 6 +- .../RpcResponseHolderNamingTests.cs | 6 +- ...ests.TestBasicGrain.DotNet10_0.verified.cs | 6 +- ...Tests.TestBasicGrain.DotNet8_0.verified.cs | 6 +- ...rializersAnnotation.DotNet10_0.verified.cs | 6 +- ...erializersAnnotation.DotNet8_0.verified.cs | 6 +- ...stGrainComplexGrain.DotNet10_0.verified.cs | 6 +- ...estGrainComplexGrain.DotNet8_0.verified.cs | 6 +- ...thInvokableBaseType.DotNet10_0.verified.cs | 6 +- ...ithInvokableBaseType.DotNet8_0.verified.cs | 6 +- ...WithResponseTimeout.DotNet10_0.verified.cs | 6 +- ...dWithResponseTimeout.DotNet8_0.verified.cs | 6 +- ...thDifferentKeyTypes.DotNet10_0.verified.cs | 24 ++-- ...ithDifferentKeyTypes.DotNet8_0.verified.cs | 24 ++-- ...hMultipleInterfaces.DotNet10_0.verified.cs | 12 +- ...thMultipleInterfaces.DotNet8_0.verified.cs | 12 +- .../SelfWritingResponseFilterTests.cs | 2 +- .../SelfWritingResponseOwnershipTests.cs | 121 +++++++++++++++- .../RpcResponses.Contracts.cs | 4 +- .../RpcResponseTests.cs | 18 +-- 34 files changed, 435 insertions(+), 403 deletions(-) create mode 100644 src/Orleans.Core/Core/GrainCallInvoker.cs delete mode 100644 src/Orleans.Core/Core/ResponseCopyBoundary.cs delete mode 100644 src/Orleans.Serialization/Invocation/IResponseInvokable.cs diff --git a/docs/site/src/content/docs/implementation/serialization.md b/docs/site/src/content/docs/implementation/serialization.md index 418282e4821..b69f0d7f5ca 100644 --- a/docs/site/src/content/docs/implementation/serialization.md +++ b/docs/site/src/content/docs/implementation/serialization.md @@ -133,7 +133,7 @@ Arguments and result values use normal Orleans.Serialization codecs and copiers. ### Closed RPC response factories -For supported non-generic methods using the built-in task and value-task request bases, generated invokables also implement . The runtime selects this contract in the ordinary, incoming-filter, and observer paths. The invokable binds the selected serialization dependencies and rents a concrete, non-generic response holder after copying a mutable result. Immutable results retain their existing copy semantics. Isolation completes before incoming filters resume, and this path creates one pooled envelope for the successful result. +The runtime invokes in the ordinary, incoming-filter, and observer paths. Its default implementation copies successful responses using the selected response copier. For supported non-generic methods using the built-in task and value-task request bases, generated implementations bind the selected serialization dependencies and rent a concrete, non-generic response holder after copying a mutable result. Immutable results retain their existing copy semantics. Isolation completes before incoming filters resume, and the generated path creates one pooled envelope for the successful result. Exception envelopes retain the original exception through filters and are copied at delivery for every invocation. Incoming filters receive an isolated result and can transform its envelope or nested payload references. The invocation context retains each superseded response until completion, allowing filters to restore an earlier selection and releasing every unselected wrapper exactly once. After the filter chain completes, the runtime copies the selected result for delivery, preserving isolation for both local callers and deferred message serialization. Calls with no incoming filters transfer their invocation-time copy directly to the messaging pipeline. Expired and one-way requests release their owned response without an outgoing copy. diff --git a/src/Orleans.CodeGenerator/InvokableGenerator.cs b/src/Orleans.CodeGenerator/InvokableGenerator.cs index c86da6eb911..90f6413bc62 100644 --- a/src/Orleans.CodeGenerator/InvokableGenerator.cs +++ b/src/Orleans.CodeGenerator/InvokableGenerator.cs @@ -161,10 +161,10 @@ private ClassDeclarationSyntax GetClassDeclarationSyntax( { var type = result.TypeArguments[0].ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); var factory = $"global::{RpcResponseHolderGenerator.GetNamespace(_generationContext.Compilation)}.{responseName}Factory"; - classDeclaration = classDeclaration.AddBaseListTypes(SimpleBaseType(ParseTypeName("global::Orleans.Serialization.Invocation.IResponseInvokable"))); + classDeclaration = classDeclaration.AddBaseListTypes(SimpleBaseType(ParseTypeName("global::Orleans.Serialization.Invocation.IInvokable"))); classDeclaration = classDeclaration.AddMembers(ParseMemberDeclaration($$""" async global::System.Threading.Tasks.ValueTask - global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy( + global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy( global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) @@ -175,6 +175,7 @@ private ClassDeclarationSyntax GetClassDeclarationSyntax( if (!factory.IsSupported) { var original = await Invoke(); + if (original.Exception is not null) return original; return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } {{type}} value = await InvokeInner(); diff --git a/src/Orleans.Core/Core/GrainCallInvoker.cs b/src/Orleans.Core/Core/GrainCallInvoker.cs new file mode 100644 index 00000000000..e09bcccd774 --- /dev/null +++ b/src/Orleans.Core/Core/GrainCallInvoker.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Threading.Tasks; +using Orleans.Serialization.Invocation; + +namespace Orleans.Runtime; + +internal abstract class GrainCallInvoker(IInvokable request) : IGrainCallContext, IDisposable +{ + private Response? _response; + private HashSet? _ownedResponses; + private int _stage; + + public IInvokable Request { get; } = request; + public MethodInfo InterfaceMethod => Request.GetMethod(); + public string InterfaceName => Request.GetInterfaceName(); + public string MethodName => Request.GetMethodName(); + public abstract object Grain { get; } + public abstract GrainId? SourceId { get; } + public abstract GrainId TargetId { get; } + public abstract GrainInterfaceType InterfaceType { get; } + public abstract object? Result { get; set; } + protected abstract int FilterCount { get; } + + public Response? Response + { + get => _response; + set + { + if (ReferenceEquals(_response, value)) return; + if (_response is { } previous) + (_ownedResponses ??= new(ReferenceEqualityComparer.Instance)).Add(previous); + if (_ownedResponses is { } owned && value is not null) owned.Add(value); + _response = value; + } + } + + public async Task Invoke() + { + var stage = _stage++; + try + { + if (stage < FilterCount) + { + await InvokeFilter(stage); + if (Response is null) + throw new InvalidOperationException($"{GetType()}.{nameof(Invoke)}() invoked a broken filter: {GetFilterName(stage)}."); + } + else if (stage == FilterCount) + { + await InvokeInner(); + } + else + { + throw new InvalidOperationException($"{GetType()}.{nameof(Invoke)}() received an invalid call."); + } + } + finally + { + _stage--; + } + } + + protected abstract Task InvokeFilter(int index); + protected abstract string GetFilterName(int index); + protected abstract Task InvokeInner(); + + internal Response TakeResponse() + { + var result = _response!; + _response = null; + _ownedResponses?.Remove(result); + return result; + } + + public void Dispose() + { + var current = _response; + _response = null; + var owned = _ownedResponses; + _ownedResponses = null; + if (current is not null) owned?.Remove(current); + try + { + current?.Dispose(); + } + finally + { + if (owned is not null) + foreach (var response in owned) response.Dispose(); + } + } +} diff --git a/src/Orleans.Core/Core/GrainMethodInvoker.cs b/src/Orleans.Core/Core/GrainMethodInvoker.cs index 079234a3339..54f7257b97f 100644 --- a/src/Orleans.Core/Core/GrainMethodInvoker.cs +++ b/src/Orleans.Core/Core/GrainMethodInvoker.cs @@ -14,18 +14,15 @@ namespace Orleans.Runtime /// /// Invokes a request on a grain. /// - internal sealed class GrainMethodInvoker : IIncomingGrainCallContext, IDisposable + internal sealed class GrainMethodInvoker : GrainCallInvoker, IIncomingGrainCallContext { private readonly Message message; - private readonly IInvokable request; private readonly List filters; private readonly InterfaceToImplementationMappingCache interfaceToImplementationMapping; private readonly DeepCopier responseCopier; private readonly IGrainContext grainContext; private readonly ICodecProvider codecProvider; private readonly CopyContextPool copyContexts; - private ResponseOwnership responses; - private int stage; /// /// Initializes a new instance of the class. @@ -46,10 +43,9 @@ public GrainMethodInvoker( InterfaceToImplementationMappingCache interfaceToImplementationMapping, DeepCopier responseCopier, ICodecProvider codecProvider, - CopyContextPool copyContexts) + CopyContextPool copyContexts) : base(request) { this.message = message; - this.request = request; this.grainContext = grainContext; this.filters = filters; this.interfaceToImplementationMapping = interfaceToImplementationMapping; @@ -58,15 +54,11 @@ public GrainMethodInvoker( this.copyContexts = copyContexts; } - public IInvokable Request => request; - - public object Grain => grainContext.GrainInstance!; - - public MethodInfo InterfaceMethod => request.GetMethod(); + public override object Grain => grainContext.GrainInstance!; public MethodInfo ImplementationMethod => GetMethodEntry().ImplementationMethod; - public object? Result + public override object? Result { get => Response switch { @@ -76,117 +68,35 @@ public object? Result set => Response = Response.FromResult(value); } - public Response? Response - { - get => responses.Value; - set => responses.Value = value; - } - - internal Response TakeResponse() => responses.Take(); - - public void Dispose() => responses.Dispose(); - - public GrainId? SourceId => message.SendingGrain is { IsDefault: false } source ? source : null; + public override GrainId? SourceId => message.SendingGrain is { IsDefault: false } source ? source : null; public IGrainContext TargetContext => grainContext; - public GrainId TargetId => grainContext.GrainId; - - public GrainInterfaceType InterfaceType => message.InterfaceType; + public override GrainId TargetId => grainContext.GrainId; - public string InterfaceName => request.GetInterfaceName(); + public override GrainInterfaceType InterfaceType => message.InterfaceType; - public string MethodName => request.GetMethodName(); + protected override int FilterCount => filters.Count + (Grain is IIncomingGrainCallFilter ? 1 : 0); - public async Task Invoke() - { - try - { - // Execute each stage in the pipeline. Each successive call to this method will invoke the next stage. - // Stages which are not implemented (eg, because the user has not specified an interceptor) are skipped. - var numFilters = filters.Count; - if (stage < numFilters) - { - // Call each of the specified interceptors. - var systemWideFilter = this.filters[stage]; - stage++; - await systemWideFilter.Invoke(this); - - // If Response is null some filter did not continue the call chain - if (this.Response is null) - { - ThrowBrokenCallFilterChain(systemWideFilter.GetType().Name); - } - - return; - } - - if (stage == numFilters) - { - stage++; - - // Grain-level invoker, if present. - if (this.Grain is IIncomingGrainCallFilter grainClassLevelFilter) - { - await grainClassLevelFilter.Invoke(this); - - // If Response is null some filter did not continue the call chain - if (this.Response is null) - { - ThrowBrokenCallFilterChain(this.Grain.GetType().Name); - } - return; - } - } + protected override Task InvokeFilter(int index) => index < filters.Count + ? filters[index].Invoke(this) + : ((IIncomingGrainCallFilter)Grain).Invoke(this); - if (stage == numFilters + 1) - { - // Finally call the root-level invoker. - stage++; - var response = request is IResponseInvokable direct - ? await direct.InvokeAndCopy(codecProvider, copyContexts, responseCopier) - : await request.Invoke(); - - // Propagate exceptions to other filters. - if (response.Exception is { } exception) - { - Response = response; - ExceptionDispatchInfo.Capture(exception).Throw(); - } - - if (request is not IResponseInvokable) - response = ResponseCopyBoundary.CopyAndDispose(response, this.responseCopier); - - Response = response; - - return; - } - } - finally - { - stage--; - } - - // If this method has been called more than the expected number of times, that is invalid. - ThrowInvalidCall(); - } - - private static void ThrowInvalidCall() - { - throw new InvalidOperationException( - $"{nameof(GrainMethodInvoker)}.{nameof(Invoke)}() received an invalid call."); - } + protected override string GetFilterName(int index) => index < filters.Count + ? filters[index].GetType().Name : Grain.GetType().Name; - private static void ThrowBrokenCallFilterChain(string filterName) + protected override async Task InvokeInner() { - throw new InvalidOperationException($"{nameof(GrainMethodInvoker)}.{nameof(Invoke)}() invoked a broken filter: {filterName}."); + Response = await Request.InvokeAndCopy(codecProvider, copyContexts, responseCopier); + if (Response.Exception is { } exception) + ExceptionDispatchInfo.Capture(exception).Throw(); } private (MethodInfo ImplementationMethod, MethodInfo InterfaceMethod) GetMethodEntry() { - var interfaceType = this.request.GetInterfaceType(); - var implementationType = this.request.GetTarget()!.GetType(); + var interfaceType = Request.GetInterfaceType(); + var implementationType = Request.GetTarget()!.GetType(); // Get or create the implementation map for this object. var implementationMap = interfaceToImplementationMapping.GetOrCreate( @@ -194,7 +104,7 @@ private static void ThrowBrokenCallFilterChain(string filterName) interfaceType); // Get the method info for the method being invoked. - var method = request.GetMethod(); + var method = Request.GetMethod(); if (method.IsConstructedGenericMethod) { if (implementationMap.TryGetValue(method.GetGenericMethodDefinition(), out var entry)) diff --git a/src/Orleans.Core/Core/ResponseCopyBoundary.cs b/src/Orleans.Core/Core/ResponseCopyBoundary.cs deleted file mode 100644 index 86aab434b94..00000000000 --- a/src/Orleans.Core/Core/ResponseCopyBoundary.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using Orleans.Serialization; -using Orleans.Serialization.Cloning; -using Orleans.Serialization.GeneratedCodeHelpers; -using Orleans.Serialization.Invocation; -using Orleans.Serialization.Serializers; - -namespace Orleans.Runtime; - -internal static class ResponseCopyBoundary -{ - internal static ValueTask InvokeAndCopy( - IInvokable request, - ICodecProvider codecProvider, - CopyContextPool copyContexts, - DeepCopier responseCopier) - => request is IResponseInvokable direct - ? direct.InvokeAndCopy(codecProvider, copyContexts, responseCopier) - : InvokeLegacy(request, responseCopier); - - private static async ValueTask InvokeLegacy(IInvokable request, DeepCopier responseCopier) - => CopyAndDispose(await request.Invoke(), responseCopier); - - internal static Response CopyAndDispose(Response response, DeepCopier copier) - => OrleansGeneratedCodeHelper.CopyResponseAndDispose(response, copier); - - internal static Response CopyAndDispose(Response response, DeepCopier copier) - => OrleansGeneratedCodeHelper.CopyResponseAndDispose(response, copier); -} - -internal struct ResponseOwnership : IDisposable -{ - private Response? _current; - private List? _others; - - internal Response? Value - { - readonly get => _current; - set - { - if (ReferenceEquals(_current, value)) return; - if (_current is { } previous) (_others ??= []).Add(previous); - if (value is not null && _others is { } others) - { - for (var i = others.Count - 1; i >= 0; i--) - { - if (ReferenceEquals(value, others[i])) others.RemoveAt(i); - } - } - - _current = value; - } - } - - internal Response Take() - { - var result = _current!; - _current = null; - return result; - } - - public void Dispose() - { - var current = _current; - _current = null; - var others = _others; - _others = null; - try - { - current?.Dispose(); - } - finally - { - if (others is not null) - foreach (var response in others) response.Dispose(); - } - } -} diff --git a/src/Orleans.Core/Runtime/InvokableObjectManager.cs b/src/Orleans.Core/Runtime/InvokableObjectManager.cs index 3374b3c3db0..1a0d7c3dfac 100644 --- a/src/Orleans.Core/Runtime/InvokableObjectManager.cs +++ b/src/Orleans.Core/Runtime/InvokableObjectManager.cs @@ -11,6 +11,7 @@ using Orleans.Runtime; using Orleans.Serialization; using Orleans.Serialization.Invocation; +using Orleans.Serialization.GeneratedCodeHelpers; namespace Orleans { @@ -396,10 +397,10 @@ private async Task ProcessMessageAsync(Message message) } else { - response = await ResponseCopyBoundary.InvokeAndCopy(request, + response = await request.InvokeAndCopy( _manager.runtimeClient.ServiceProvider.GetRequiredService(), _manager.runtimeClient.ServiceProvider.GetRequiredService(), _manager._responseCopier); - isCopied = request is not IResponseInvokable || response.Exception is null; + isCopied = response.Exception is null; } if (message.Direction != Message.Directions.OneWay) @@ -484,7 +485,7 @@ private void SendResponseAsync(Message message, Response resultObject, bool isCo try { response = null; - response = ResponseCopyBoundary.CopyAndDispose(resultObject, _manager.deepCopier); + response = OrleansGeneratedCodeHelper.CopyResponseAndDispose(resultObject, _manager.deepCopier); } catch (Exception exc2) { diff --git a/src/Orleans.Core/Runtime/OutgoingCallInvoker.cs b/src/Orleans.Core/Runtime/OutgoingCallInvoker.cs index aebaf52933c..cd4a4193920 100644 --- a/src/Orleans.Core/Runtime/OutgoingCallInvoker.cs +++ b/src/Orleans.Core/Runtime/OutgoingCallInvoker.cs @@ -1,5 +1,4 @@ using System; -using System.Reflection; using System.Threading.Tasks; using Orleans.CodeGeneration; using Orleans.Serialization.Invocation; @@ -9,17 +8,14 @@ namespace Orleans.Runtime /// /// Invokes a request on a grain reference. /// - internal sealed class OutgoingCallInvoker : IOutgoingGrainCallContext, IDisposable + internal sealed class OutgoingCallInvoker : GrainCallInvoker, IOutgoingGrainCallContext { - private readonly IInvokable request; private readonly InvokeMethodOptions options; private readonly Action sendRequest; private readonly IOutgoingGrainCallFilter[] filters; private readonly int stages; private readonly GrainReference grainReference; private readonly IOutgoingGrainCallFilter? requestFilter; - private ResponseOwnership responses; - private int stage; /// /// Initializes a new instance of the class. @@ -34,9 +30,8 @@ public OutgoingCallInvoker( IInvokable request, InvokeMethodOptions options, Action sendRequest, - IOutgoingGrainCallFilter[] filters) + IOutgoingGrainCallFilter[] filters) : base(request) { - this.request = request; this.options = options; this.sendRequest = sendRequest; this.grainReference = grain; @@ -51,94 +46,33 @@ public OutgoingCallInvoker( } } - public IInvokable Request => this.request; + public override object Grain => this.grainReference; - public object Grain => this.grainReference; - - public MethodInfo InterfaceMethod => request.GetMethod(); - - public object? Result { get => TypedResult; set => TypedResult = (TResult?)value; } - - public Response? Response { get => responses.Value; set => responses.Value = value; } - - public void Dispose() => responses.Dispose(); + public override object? Result { get => TypedResult; set => TypedResult = (TResult?)value; } public TResult? TypedResult { get => Response!.GetResult(); set => Response = Response.FromResult(value); } public IGrainContext? SourceContext { get; } - public GrainId? SourceId => SourceContext?.GrainId; - - public GrainId TargetId => grainReference.GrainId; + public override GrainId? SourceId => SourceContext?.GrainId; - public GrainInterfaceType InterfaceType => grainReference.InterfaceType; - - public string InterfaceName => request.GetInterfaceName(); - - public string MethodName => request.GetMethodName(); - - public async Task Invoke() - { - try - { - // Execute each stage in the pipeline. Each successive call to this method will invoke the next stage. - // Stages which are not implemented (eg, because the user has not specified an interceptor) are skipped. - if (stage < this.filters.Length) - { - // Call each of the specified interceptors. - var systemWideFilter = this.filters[stage]; - stage++; - await systemWideFilter.Invoke(this); + public override GrainId TargetId => grainReference.GrainId; - // If Response is null some filter did not continue the call chain - if (this.Response is null) - { - ThrowBrokenCallFilterChain(systemWideFilter.GetType().Name); - } + public override GrainInterfaceType InterfaceType => grainReference.InterfaceType; - return; - } - else if (stage < this.stages) - { - stage++; - await this.requestFilter!.Invoke(this); + protected override int FilterCount => stages; - // If Response is null some filter did not continue the call chain - if (this.Response is null) - { - ThrowBrokenCallFilterChain(this.requestFilter.GetType().Name); - } + protected override Task InvokeFilter(int index) => index < filters.Length + ? filters[index].Invoke(this) : requestFilter!.Invoke(this); - return; - } - else if (stage == this.stages) - { - // Finally call the root-level invoker. - stage++; - var responseCompletionSource = ResponseCompletionSourcePool.Get(); - this.sendRequest(this.grainReference, responseCompletionSource, this.request, this.options); - this.Response = await responseCompletionSource.AsValueTask().ConfigureAwait(false); - - return; - } - } - finally - { - stage--; - } - - // If this method has been called more than the expected number of times, that is invalid. - ThrowInvalidCall(); - } - - private void ThrowInvalidCall() - { - throw new InvalidOperationException($"{typeof(OutgoingCallInvoker)}.{nameof(Invoke)}() received an invalid call."); - } + protected override string GetFilterName(int index) => index < filters.Length + ? filters[index].GetType().Name : requestFilter!.GetType().Name; - private void ThrowBrokenCallFilterChain(string filterName) + protected override async Task InvokeInner() { - throw new InvalidOperationException($"{typeof(OutgoingCallInvoker)}.{nameof(Invoke)}() invoked a broken filter: {filterName}."); + var completion = ResponseCompletionSourcePool.Get(); + sendRequest(grainReference, completion, Request, options); + Response = await completion.AsValueTask().ConfigureAwait(false); } } } diff --git a/src/Orleans.Runtime/Core/InsideRuntimeClient.cs b/src/Orleans.Runtime/Core/InsideRuntimeClient.cs index d265576225f..ccdd1a11888 100644 --- a/src/Orleans.Runtime/Core/InsideRuntimeClient.cs +++ b/src/Orleans.Runtime/Core/InsideRuntimeClient.cs @@ -18,6 +18,7 @@ using Orleans.Serialization; using Orleans.Serialization.Invocation; using Orleans.Serialization.Cloning; +using Orleans.Serialization.GeneratedCodeHelpers; using Orleans.Serialization.Serializers; using Orleans.Storage; using static Orleans.Internal.StandardExtensions; @@ -330,9 +331,9 @@ public async Task Invoke(IGrainContext target, Message message) } else { - response = await ResponseCopyBoundary.InvokeAndCopy(invokable, + response = await invokable.InvokeAndCopy( this.responseCodecProvider, this.responseCopyContexts, this.responseCopier); - isCopied = invokable is not IResponseInvokable || response.Exception is null; + isCopied = response.Exception is null; } invokable.Dispose(); @@ -408,7 +409,7 @@ private void SafeSendResponse(Message message, Response response, bool isCopied) if (!isCopied && !message.IsExpired) { ownedResponse = null; - ownedResponse = ResponseCopyBoundary.CopyAndDispose(response, this._deepCopier); + ownedResponse = OrleansGeneratedCodeHelper.CopyResponseAndDispose(response, this._deepCopier); } SendResponse(message, ownedResponse); diff --git a/src/Orleans.Serialization/Invocation/IInvokable.cs b/src/Orleans.Serialization/Invocation/IInvokable.cs index 1c1b8f59cf4..adf2df2a273 100644 --- a/src/Orleans.Serialization/Invocation/IInvokable.cs +++ b/src/Orleans.Serialization/Invocation/IInvokable.cs @@ -2,6 +2,9 @@ using System.Reflection; using System.Threading; using System.Threading.Tasks; +using Orleans.Serialization.Cloning; +using Orleans.Serialization.GeneratedCodeHelpers; +using Orleans.Serialization.Serializers; namespace Orleans.Serialization.Invocation { @@ -27,6 +30,39 @@ public interface IInvokable : IDisposable /// ValueTask Invoke(); + /// + /// Invokes the method and isolates its successful result before returning to incoming filters. + /// + /// The invocation's serialization provider. + /// The invocation's copy-context pool. + /// The selected copier for response implementations. + /// An owned response whose successful result is isolated. + /// Exception envelopes retain the original exception for filters and are copied at delivery. + async ValueTask InvokeAndCopy( + ICodecProvider codecProvider, + CopyContextPool copyContextPool, + DeepCopier responseCopier) + { + Response? response = await Invoke(); + try + { + if (response.Exception is not null) + { + var result = response; + response = null; + return result; + } + + var original = response; + response = null; + return OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); + } + finally + { + response?.Dispose(); + } + } + /// /// Gets the number of arguments. /// diff --git a/src/Orleans.Serialization/Invocation/IResponseInvokable.cs b/src/Orleans.Serialization/Invocation/IResponseInvokable.cs deleted file mode 100644 index b039ccf9f4f..00000000000 --- a/src/Orleans.Serialization/Invocation/IResponseInvokable.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Threading.Tasks; -using Orleans.Serialization.Cloning; -using Orleans.Serialization.Serializers; - -namespace Orleans.Serialization.Invocation; - -/// -/// Invokes a source-known method and creates a response whose result satisfies the runtime copy boundary. -/// -public interface IResponseInvokable -{ - /// - /// Invokes the method and isolates its successful result before returning to incoming filters. - /// - /// The invocation's serialization provider. - /// The invocation's copy-context pool. - /// The compatibility copier for custom response implementations. - /// The isolated response. - ValueTask InvokeAndCopy(ICodecProvider codecProvider, CopyContextPool copyContextPool, DeepCopier responseCopier); -} diff --git a/src/api/Orleans.Core/Orleans.Core.cs b/src/api/Orleans.Core/Orleans.Core.cs index 53b8ae3a3ff..f5e45365106 100644 --- a/src/api/Orleans.Core/Orleans.Core.cs +++ b/src/api/Orleans.Core/Orleans.Core.cs @@ -3106,7 +3106,7 @@ public Copier_MembershipTableData(global::Orleans.Serialization.Activators.IActi [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - public sealed partial class Invokable_IMembershipTable_GrainReference_00BCE16F : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed partial class Invokable_IMembershipTable_GrainReference_00BCE16F : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IInvokable, System.IDisposable { public override void Dispose() { } @@ -3124,7 +3124,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) { } } @@ -3133,7 +3133,7 @@ public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetH [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::Orleans.CompoundTypeAlias(new[] { "inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::Orleans.IMembershipTable), "00BCE16F" })] - public sealed partial class Invokable_IMembershipTable_GrainReference_4115A4B4 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed partial class Invokable_IMembershipTable_GrainReference_4115A4B4 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IInvokable, System.IDisposable { public System.Threading.CancellationToken arg0; public override bool IsCancellable { get { throw null; } } @@ -3160,7 +3160,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } public override void SetArgument(int index, object value) { } @@ -3173,7 +3173,7 @@ public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetH [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::Orleans.CompoundTypeAlias(new[] { "inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::Orleans.IMembershipTable), "E06D3DBC" })] - public sealed partial class Invokable_IMembershipTable_GrainReference_47733EA8 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed partial class Invokable_IMembershipTable_GrainReference_47733EA8 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IInvokable, System.IDisposable { public global::Orleans.MembershipEntry arg0; public string arg1; @@ -3203,7 +3203,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } public override void SetArgument(int index, object value) { } @@ -3216,7 +3216,7 @@ public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetH [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::Orleans.CompoundTypeAlias(new[] { "inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::Orleans.IMembershipTable), "FEF3AC5A" })] - public sealed partial class Invokable_IMembershipTable_GrainReference_60723C98 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed partial class Invokable_IMembershipTable_GrainReference_60723C98 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IInvokable, System.IDisposable { public global::Orleans.MembershipEntry arg0; public global::Orleans.TableVersion arg1; @@ -3245,7 +3245,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } public override void SetArgument(int index, object value) { } @@ -3289,7 +3289,7 @@ public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetH [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::Orleans.CompoundTypeAlias(new[] { "inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::Orleans.IMembershipTable), "D851FB33" })] - public sealed partial class Invokable_IMembershipTable_GrainReference_92AB4F4C : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed partial class Invokable_IMembershipTable_GrainReference_92AB4F4C : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IInvokable, System.IDisposable { public global::Orleans.Runtime.SiloAddress arg0; public System.Threading.CancellationToken arg1; @@ -3317,7 +3317,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } public override void SetArgument(int index, object value) { } @@ -3508,7 +3508,7 @@ public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetH [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - public sealed partial class Invokable_IMembershipTable_GrainReference_D851FB33 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed partial class Invokable_IMembershipTable_GrainReference_D851FB33 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IInvokable, System.IDisposable { public global::Orleans.Runtime.SiloAddress arg0; public override void Dispose() { } @@ -3531,7 +3531,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } public override void SetArgument(int index, object value) { } @@ -3541,7 +3541,7 @@ public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetH [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - public sealed partial class Invokable_IMembershipTable_GrainReference_E06D3DBC : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed partial class Invokable_IMembershipTable_GrainReference_E06D3DBC : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IInvokable, System.IDisposable { public global::Orleans.MembershipEntry arg0; public string arg1; @@ -3566,7 +3566,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } public override void SetArgument(int index, object value) { } @@ -3646,7 +3646,7 @@ public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetH [System.CodeDom.Compiler.GeneratedCode("OrleansCodeGen", "10.0.0.0")] [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] - public sealed partial class Invokable_IMembershipTable_GrainReference_FEF3AC5A : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed partial class Invokable_IMembershipTable_GrainReference_FEF3AC5A : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IInvokable, System.IDisposable { public global::Orleans.MembershipEntry arg0; public global::Orleans.TableVersion arg1; @@ -3670,7 +3670,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } public override void SetArgument(int index, object value) { } @@ -4274,7 +4274,7 @@ public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetH [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::Orleans.CompoundTypeAlias(new[] { "inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::Orleans.Placement.Rebalancing.IActivationRebalancer), "D7EB6469" })] - public sealed partial class Invokable_IActivationRebalancer_GrainReference_D7EB6469 : global::Orleans.Runtime.Request, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed partial class Invokable_IActivationRebalancer_GrainReference_D7EB6469 : global::Orleans.Runtime.Request, global::Orleans.Serialization.Invocation.IInvokable, System.IDisposable { public bool arg0; public override void Dispose() { } @@ -4297,7 +4297,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.ValueTask InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } public override void SetArgument(int index, object value) { } @@ -5990,7 +5990,7 @@ public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetH [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::Orleans.CompoundTypeAlias(new[] { "inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::Orleans.Runtime.IManagementGrain), "AEDE93F6" })] - public sealed partial class Invokable_IManagementGrain_GrainReference_4C2438F7 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed partial class Invokable_IManagementGrain_GrainReference_4C2438F7 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IInvokable, System.IDisposable { public global::Orleans.Runtime.GrainReference arg0; public System.Threading.CancellationToken arg1; @@ -6018,7 +6018,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } public override void SetArgument(int index, object value) { } @@ -6347,7 +6347,7 @@ public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetH [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::Orleans.CompoundTypeAlias(new[] { "inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::Orleans.Runtime.IManagementGrain), "GetGrainActivationCount" })] - public sealed partial class Invokable_IManagementGrain_GrainReference_AEDE93F6 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed partial class Invokable_IManagementGrain_GrainReference_AEDE93F6 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IInvokable, System.IDisposable { public global::Orleans.Runtime.GrainReference arg0; public override void Dispose() { } @@ -6370,7 +6370,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } public override void SetArgument(int index, object value) { } @@ -6381,7 +6381,7 @@ public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetH [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::Orleans.CompoundTypeAlias(new[] { "inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::Orleans.Runtime.IManagementGrain), "D7365B43" })] - public sealed partial class Invokable_IManagementGrain_GrainReference_B15A0F47 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed partial class Invokable_IManagementGrain_GrainReference_B15A0F47 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IInvokable, System.IDisposable { public System.Threading.CancellationToken arg0; public override bool IsCancellable { get { throw null; } } @@ -6408,7 +6408,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } public override void SetArgument(int index, object value) { } @@ -6525,7 +6525,7 @@ public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetH [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::Orleans.CompoundTypeAlias(new[] { "inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::Orleans.Runtime.IManagementGrain), "GetTotalActivationCount" })] - public sealed partial class Invokable_IManagementGrain_GrainReference_D7365B43 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed partial class Invokable_IManagementGrain_GrainReference_D7365B43 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IInvokable, System.IDisposable { public override void Dispose() { } @@ -6543,7 +6543,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) { } } diff --git a/src/api/Orleans.Serialization/Orleans.Serialization.cs b/src/api/Orleans.Serialization/Orleans.Serialization.cs index b60c03a61ba..bdf49d45b03 100644 --- a/src/api/Orleans.Serialization/Orleans.Serialization.cs +++ b/src/api/Orleans.Serialization/Orleans.Serialization.cs @@ -3609,6 +3609,7 @@ public partial interface IInvokable : System.IDisposable string GetMethodName(); object? GetTarget(); System.Threading.Tasks.ValueTask Invoke(); + System.Threading.Tasks.ValueTask InvokeAndCopy(Serializers.ICodecProvider codecProvider, Cloning.CopyContextPool copyContextPool, DeepCopier responseCopier); void SetArgument(int index, object value); void SetTarget(ITargetHolder holder); bool TryCancel(); @@ -3642,11 +3643,6 @@ public partial interface IResponseCompletionSource void Complete(Response value); } - public partial interface IResponseInvokable - { - System.Threading.Tasks.ValueTask InvokeAndCopy(Serializers.ICodecProvider codecProvider, Cloning.CopyContextPool copyContextPool, DeepCopier responseCopier); - } - public partial interface ITargetHolder { object? GetComponent(System.Type componentType); diff --git a/src/api/Orleans.Streaming/Orleans.Streaming.cs b/src/api/Orleans.Streaming/Orleans.Streaming.cs index 0a98960d7f0..d273a9f92de 100644 --- a/src/api/Orleans.Streaming/Orleans.Streaming.cs +++ b/src/api/Orleans.Streaming/Orleans.Streaming.cs @@ -3407,7 +3407,7 @@ public void DeepCopy(global::Orleans.Streams.StreamSubscriptionHandle input, [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::Orleans.CompoundTypeAlias(new[] { "inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::Orleans.Streams.IStreamCheckpointerGrain), "7AB50A87" })] - public sealed partial class Invokable_IStreamCheckpointerGrain_GrainReference_7AB50A87 : global::Orleans.Runtime.Request, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed partial class Invokable_IStreamCheckpointerGrain_GrainReference_7AB50A87 : global::Orleans.Runtime.Request, global::Orleans.Serialization.Invocation.IInvokable, System.IDisposable { public string arg0; public string arg1; @@ -3436,7 +3436,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.ValueTask InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } public override void SetArgument(int index, object value) { } @@ -3449,7 +3449,7 @@ public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetH [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::Orleans.CompoundTypeAlias(new[] { "inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::Orleans.Streams.IStreamCheckpointerGrain), "DE3727A1" })] - public sealed partial class Invokable_IStreamCheckpointerGrain_GrainReference_DE3727A1 : global::Orleans.Runtime.Request, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed partial class Invokable_IStreamCheckpointerGrain_GrainReference_DE3727A1 : global::Orleans.Runtime.Request, global::Orleans.Serialization.Invocation.IInvokable, System.IDisposable { public System.Threading.CancellationToken arg0; public override bool IsCancellable { get { throw null; } } @@ -3476,7 +3476,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.ValueTask InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } public override void SetArgument(int index, object value) { } diff --git a/src/api/Orleans.Transactions.TestKit.Base/Orleans.Transactions.TestKit.Base.cs b/src/api/Orleans.Transactions.TestKit.Base/Orleans.Transactions.TestKit.Base.cs index 5f4249bf6b1..8eb7baf55f6 100644 --- a/src/api/Orleans.Transactions.TestKit.Base/Orleans.Transactions.TestKit.Base.cs +++ b/src/api/Orleans.Transactions.TestKit.Base/Orleans.Transactions.TestKit.Base.cs @@ -2749,7 +2749,7 @@ public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetH [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] [global::Orleans.CompoundTypeAlias(new[] { "inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::Orleans.Transactions.TestKit.INoAttributionGrain), "BC7E3A79" })] - public sealed partial class Invokable_INoAttributionGrain_GrainReference_BC7E3A79 : global::Orleans.Runtime.TaskRequest[]>, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed partial class Invokable_INoAttributionGrain_GrainReference_BC7E3A79 : global::Orleans.Runtime.TaskRequest[]>, global::Orleans.Serialization.Invocation.IInvokable, System.IDisposable { public int arg0; public System.Collections.Generic.List[] arg1; @@ -2773,7 +2773,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task[]> InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } public override void SetArgument(int index, object value) { } diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index 369184e7869..f987ec36429 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -2288,7 +2288,7 @@ public partial class Context : Orleans.Serialization.SerializerContext { } frameworkSymbol.GeneratedSources.OrderBy(static source => source.HintName, StringComparer.Ordinal) .Select(static source => (source.HintName, Source: source.SourceText.ToString()))); var source = ConcatenateGeneratedSources(managed); - Assert.Contains("IResponseInvokable", source); + Assert.Contains("IInvokable.InvokeAndCopy", source); Assert.Contains("IRawResponseWriter", source); Assert.Contains("AddRawResponseReader", source); Assert.DoesNotContain("#if NET5_0_OR_GREATER", source); @@ -3563,7 +3563,7 @@ public interface IWriter : IGrainWithIntegerKey { {{returnType}} Get(); } Assert.Contains("ResponsePool.GetGenerated<", response); Assert.Contains("_factory = null", response); Assert.Contains("options.AddRawResponseReader", response); - Assert.Contains("IResponseInvokable.InvokeAndCopy", proxy); + Assert.Contains("IInvokable.InvokeAndCopy", proxy); Assert.Contains("factory.RentCopied(value, contexts)", proxy); Assert.Contains("var original = await Invoke();", proxy); Assert.Contains("OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier)", proxy); @@ -3601,7 +3601,7 @@ public interface ICompatibility : IGrainWithIntegerKey var result = RunSourceGenerator(compilation); Assert.Empty(result.Diagnostics); var proxy = Assert.Single(result.GeneratedSources, static item => item.HintName.Contains(".orleans.proxy.", StringComparison.Ordinal)).SourceText.ToString(); - Assert.DoesNotContain("IResponseInvokable", proxy); + Assert.DoesNotContain("IInvokable.InvokeAndCopy", proxy); } private static GeneratorRunResult RunSourceGenerator( diff --git a/test/Orleans.CodeGenerator.Tests/RpcResponseHolderNamingTests.cs b/test/Orleans.CodeGenerator.Tests/RpcResponseHolderNamingTests.cs index 132e397b878..2ed7a6d22ff 100644 --- a/test/Orleans.CodeGenerator.Tests/RpcResponseHolderNamingTests.cs +++ b/test/Orleans.CodeGenerator.Tests/RpcResponseHolderNamingTests.cs @@ -84,7 +84,7 @@ public async Task CollidingResultsCompileAndUseDistinctFactories(bool compatibil var copier = services.GetRequiredService().GetCopier(); var target = Activator.CreateInstance(assembly.GetType("TestProject.CollisionTarget")!); var requests = assembly.GetTypes() - .Where(static type => typeof(IResponseInvokable).IsAssignableFrom(type)) + .Where(static type => !type.IsAbstract && typeof(IInvokable).IsAssignableFrom(type)) .Select(static type => (IInvokable)Activator.CreateInstance(type)!) .OrderBy(static request => request.GetMethodName(), StringComparer.Ordinal) .ToArray(); @@ -93,8 +93,8 @@ public async Task CollidingResultsCompileAndUseDistinctFactories(bool compatibil using var secondRequest = requests[1]; firstRequest.SetTarget(new TargetHolder(target!)); secondRequest.SetTarget(new TargetHolder(target!)); - using var first = await ((IResponseInvokable)firstRequest).InvokeAndCopy(provider, contexts, copier); - using var second = await ((IResponseInvokable)secondRequest).InvokeAndCopy(provider, contexts, copier); + using var first = await firstRequest.InvokeAndCopy(provider, contexts, copier); + using var second = await secondRequest.InvokeAndCopy(provider, contexts, copier); Assert.IsAssignableFrom(first); Assert.IsAssignableFrom(second); Assert.NotEqual(first.GetType(), second.GetType()); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs index ea5c970541d..ee97e87fe45 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs @@ -13,7 +13,7 @@ namespace OrleansCodeGen.TestProject [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IBasicGrain), "6B0E24A1")] - public sealed class Invokable_IBasicGrain_GrainReference_6B0E24A1 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed class Invokable_IBasicGrain_GrainReference_6B0E24A1 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IInvokable { public string arg0; global::TestProject.IBasicGrain _target; @@ -57,7 +57,7 @@ public override void SetArgument(int index, object value) } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.SayHello(arg0); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { try { @@ -65,6 +65,8 @@ public override void SetArgument(int index, object value) if (!factory.IsSupported) { var original = await Invoke(); + if (original.Exception is not null) + return original; return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs index 2d867721db1..46953355865 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs @@ -13,7 +13,7 @@ namespace OrleansCodeGen.TestProject [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IBasicGrain), "6B0E24A1")] - public sealed class Invokable_IBasicGrain_GrainReference_6B0E24A1 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed class Invokable_IBasicGrain_GrainReference_6B0E24A1 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IInvokable { public string arg0; global::TestProject.IBasicGrain _target; @@ -57,7 +57,7 @@ public override void SetArgument(int index, object value) } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.SayHello(arg0); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { try { @@ -65,6 +65,8 @@ public override void SetArgument(int index, object value) if (!factory.IsSupported) { var original = await Invoke(); + if (original.Exception is not null) + return original; return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs index dbd04300ced..e4a847c9b25 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs @@ -13,7 +13,7 @@ namespace OrleansCodeGen [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::IMyGrain), "6D39E404")] - public sealed class Invokable_IMyGrain_GrainReference_6D39E404 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed class Invokable_IMyGrain_GrainReference_6D39E404 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IInvokable { public string arg0; global::IMyGrain _target; @@ -57,7 +57,7 @@ public override void SetArgument(int index, object value) } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.SayHello(arg0); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { try { @@ -65,6 +65,8 @@ public override void SetArgument(int index, object value) if (!factory.IsSupported) { var original = await Invoke(); + if (original.Exception is not null) + return original; return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs index ec0de93ed3a..4b021caf541 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs @@ -13,7 +13,7 @@ namespace OrleansCodeGen [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::IMyGrain), "6D39E404")] - public sealed class Invokable_IMyGrain_GrainReference_6D39E404 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed class Invokable_IMyGrain_GrainReference_6D39E404 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IInvokable { public string arg0; global::IMyGrain _target; @@ -57,7 +57,7 @@ public override void SetArgument(int index, object value) } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.SayHello(arg0); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { try { @@ -65,6 +65,8 @@ public override void SetArgument(int index, object value) if (!factory.IsSupported) { var original = await Invoke(); + if (original.Exception is not null) + return original; return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs index af3a75d66b4..1c84331ceff 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs @@ -13,7 +13,7 @@ namespace OrleansCodeGen.TestProject [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IComplexGrain), "67FE5808")] - public sealed class Invokable_IComplexGrain_GrainReference_67FE5808 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed class Invokable_IComplexGrain_GrainReference_67FE5808 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IInvokable { public int arg0; public string arg1; @@ -101,7 +101,7 @@ public override bool TryCancel() public override bool IsCancellable => true; - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { try { @@ -109,6 +109,8 @@ public override bool TryCancel() if (!factory.IsSupported) { var original = await Invoke(); + if (original.Exception is not null) + return original; return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs index 5da47180864..ae6548f6de5 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs @@ -13,7 +13,7 @@ namespace OrleansCodeGen.TestProject [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IComplexGrain), "67FE5808")] - public sealed class Invokable_IComplexGrain_GrainReference_67FE5808 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed class Invokable_IComplexGrain_GrainReference_67FE5808 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IInvokable { public int arg0; public string arg1; @@ -100,7 +100,7 @@ public override bool TryCancel() } public override bool IsCancellable => true; - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { try { @@ -108,6 +108,8 @@ public override bool TryCancel() if (!factory.IsSupported) { var original = await Invoke(); + if (original.Exception is not null) + return original; return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs index fddb557a078..55e0f611a53 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs @@ -13,7 +13,7 @@ namespace OrleansCodeGen.TestProject [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IHelloGrain), "5336307F")] - public sealed class Invokable_IHelloGrain_GrainReference_5336307F : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed class Invokable_IHelloGrain_GrainReference_5336307F : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IInvokable { public string arg0; global::TestProject.IHelloGrain _target; @@ -62,7 +62,7 @@ public override void SetArgument(int index, object value) } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.SayHello(arg0); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { try { @@ -70,6 +70,8 @@ public override void SetArgument(int index, object value) if (!factory.IsSupported) { var original = await Invoke(); + if (original.Exception is not null) + return original; return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs index 235dc76e11c..e223279cdac 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs @@ -13,7 +13,7 @@ namespace OrleansCodeGen.TestProject [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IHelloGrain), "5336307F")] - public sealed class Invokable_IHelloGrain_GrainReference_5336307F : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed class Invokable_IHelloGrain_GrainReference_5336307F : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IInvokable { public string arg0; global::TestProject.IHelloGrain _target; @@ -62,7 +62,7 @@ public override void SetArgument(int index, object value) } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.SayHello(arg0); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { try { @@ -70,6 +70,8 @@ public override void SetArgument(int index, object value) if (!factory.IsSupported) { var original = await Invoke(); + if (original.Exception is not null) + return original; return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs index d2acbee0f0f..662ff772a7d 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs @@ -13,7 +13,7 @@ namespace OrleansCodeGen.TestProject [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IResponseTimeoutGrain), "6BE752C8")] - public sealed class Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed class Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IInvokable { public string arg0; global::TestProject.IResponseTimeoutGrain _target; @@ -59,7 +59,7 @@ public override void SetArgument(int index, object value) } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.LongRunningMethod(arg0); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { try { @@ -67,6 +67,8 @@ public override void SetArgument(int index, object value) if (!factory.IsSupported) { var original = await Invoke(); + if (original.Exception is not null) + return original; return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs index 24b23c61011..6a53646690a 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs @@ -13,7 +13,7 @@ namespace OrleansCodeGen.TestProject [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IResponseTimeoutGrain), "6BE752C8")] - public sealed class Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed class Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IInvokable { public string arg0; global::TestProject.IResponseTimeoutGrain _target; @@ -59,7 +59,7 @@ public override void SetArgument(int index, object value) } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.LongRunningMethod(arg0); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { try { @@ -67,6 +67,8 @@ public override void SetArgument(int index, object value) if (!factory.IsSupported) { var original = await Invoke(); + if (original.Exception is not null) + return original; return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs index e857f6744a7..f636a261019 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs @@ -13,7 +13,7 @@ namespace OrleansCodeGen.TestProject [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IMyGrainWithGuidKey), "8F0FEC0E")] - public sealed class Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed class Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IInvokable { global::TestProject.IMyGrainWithGuidKey _target; private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IMyGrainWithGuidKey).GetMethod("GetGuidValue", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, global::System.Type.EmptyTypes, null); @@ -30,7 +30,7 @@ public override void Dispose() } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.GetGuidValue(); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { try { @@ -38,6 +38,8 @@ public override void Dispose() if (!factory.IsSupported) { var original = await Invoke(); + if (original.Exception is not null) + return original; return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } @@ -67,7 +69,7 @@ public Proxy_IMyGrainWithGuidKey(global::Orleans.Runtime.GrainReferenceShared ar [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IMyGrainWithStringKey), "43570316")] - public sealed class Invokable_IMyGrainWithStringKey_GrainReference_43570316 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed class Invokable_IMyGrainWithStringKey_GrainReference_43570316 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IInvokable { global::TestProject.IMyGrainWithStringKey _target; private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IMyGrainWithStringKey).GetMethod("GetStringKey", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, global::System.Type.EmptyTypes, null); @@ -84,7 +86,7 @@ public override void Dispose() } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.GetStringKey(); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { try { @@ -92,6 +94,8 @@ public override void Dispose() if (!factory.IsSupported) { var original = await Invoke(); + if (original.Exception is not null) + return original; return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } @@ -121,7 +125,7 @@ public Proxy_IMyGrainWithStringKey(global::Orleans.Runtime.GrainReferenceShared [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IMyGrainWithGuidCompoundKey), "A9FEF7AF")] - public sealed class Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF : global::Orleans.Runtime.TaskRequest>, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed class Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF : global::Orleans.Runtime.TaskRequest>, global::Orleans.Serialization.Invocation.IInvokable { global::TestProject.IMyGrainWithGuidCompoundKey _target; private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IMyGrainWithGuidCompoundKey).GetMethod("GetGuidAndStringKey", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, global::System.Type.EmptyTypes, null); @@ -138,7 +142,7 @@ public override void Dispose() } protected override global::System.Threading.Tasks.Task> InvokeInner() => _target.GetGuidAndStringKey(); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { try { @@ -146,6 +150,8 @@ public override void Dispose() if (!factory.IsSupported) { var original = await Invoke(); + if (original.Exception is not null) + return original; return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } @@ -175,7 +181,7 @@ public Proxy_IMyGrainWithGuidCompoundKey(global::Orleans.Runtime.GrainReferenceS [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IMyGrainWithIntegerCompoundKey), "9814021A")] - public sealed class Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A : global::Orleans.Runtime.TaskRequest>, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed class Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A : global::Orleans.Runtime.TaskRequest>, global::Orleans.Serialization.Invocation.IInvokable { global::TestProject.IMyGrainWithIntegerCompoundKey _target; private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IMyGrainWithIntegerCompoundKey).GetMethod("GetIntegerAndStringKey", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, global::System.Type.EmptyTypes, null); @@ -192,7 +198,7 @@ public override void Dispose() } protected override global::System.Threading.Tasks.Task> InvokeInner() => _target.GetIntegerAndStringKey(); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { try { @@ -200,6 +206,8 @@ public override void Dispose() if (!factory.IsSupported) { var original = await Invoke(); + if (original.Exception is not null) + return original; return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs index f6f42ce68b2..67522ce0465 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs @@ -13,7 +13,7 @@ namespace OrleansCodeGen.TestProject [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IMyGrainWithGuidKey), "8F0FEC0E")] - public sealed class Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed class Invokable_IMyGrainWithGuidKey_GrainReference_8F0FEC0E : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IInvokable { global::TestProject.IMyGrainWithGuidKey _target; private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IMyGrainWithGuidKey).GetMethod("GetGuidValue", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, global::System.Type.EmptyTypes, null); @@ -30,7 +30,7 @@ public override void Dispose() } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.GetGuidValue(); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { try { @@ -38,6 +38,8 @@ public override void Dispose() if (!factory.IsSupported) { var original = await Invoke(); + if (original.Exception is not null) + return original; return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } @@ -67,7 +69,7 @@ public Proxy_IMyGrainWithGuidKey(global::Orleans.Runtime.GrainReferenceShared ar [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IMyGrainWithStringKey), "43570316")] - public sealed class Invokable_IMyGrainWithStringKey_GrainReference_43570316 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed class Invokable_IMyGrainWithStringKey_GrainReference_43570316 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IInvokable { global::TestProject.IMyGrainWithStringKey _target; private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IMyGrainWithStringKey).GetMethod("GetStringKey", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, global::System.Type.EmptyTypes, null); @@ -84,7 +86,7 @@ public override void Dispose() } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.GetStringKey(); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { try { @@ -92,6 +94,8 @@ public override void Dispose() if (!factory.IsSupported) { var original = await Invoke(); + if (original.Exception is not null) + return original; return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } @@ -121,7 +125,7 @@ public Proxy_IMyGrainWithStringKey(global::Orleans.Runtime.GrainReferenceShared [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IMyGrainWithGuidCompoundKey), "A9FEF7AF")] - public sealed class Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF : global::Orleans.Runtime.TaskRequest>, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed class Invokable_IMyGrainWithGuidCompoundKey_GrainReference_A9FEF7AF : global::Orleans.Runtime.TaskRequest>, global::Orleans.Serialization.Invocation.IInvokable { global::TestProject.IMyGrainWithGuidCompoundKey _target; private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IMyGrainWithGuidCompoundKey).GetMethod("GetGuidAndStringKey", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, global::System.Type.EmptyTypes, null); @@ -138,7 +142,7 @@ public override void Dispose() } protected override global::System.Threading.Tasks.Task> InvokeInner() => _target.GetGuidAndStringKey(); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { try { @@ -146,6 +150,8 @@ public override void Dispose() if (!factory.IsSupported) { var original = await Invoke(); + if (original.Exception is not null) + return original; return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } @@ -175,7 +181,7 @@ public Proxy_IMyGrainWithGuidCompoundKey(global::Orleans.Runtime.GrainReferenceS [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IMyGrainWithIntegerCompoundKey), "9814021A")] - public sealed class Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A : global::Orleans.Runtime.TaskRequest>, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed class Invokable_IMyGrainWithIntegerCompoundKey_GrainReference_9814021A : global::Orleans.Runtime.TaskRequest>, global::Orleans.Serialization.Invocation.IInvokable { global::TestProject.IMyGrainWithIntegerCompoundKey _target; private static readonly global::System.Reflection.MethodInfo MethodBackingField = typeof(global::TestProject.IMyGrainWithIntegerCompoundKey).GetMethod("GetIntegerAndStringKey", 0, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, global::System.Type.EmptyTypes, null); @@ -192,7 +198,7 @@ public override void Dispose() } protected override global::System.Threading.Tasks.Task> InvokeInner() => _target.GetIntegerAndStringKey(); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { try { @@ -200,6 +206,8 @@ public override void Dispose() if (!factory.IsSupported) { var original = await Invoke(); + if (original.Exception is not null) + return original; return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs index 1edd539a351..f333f425393 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs @@ -13,7 +13,7 @@ namespace OrleansCodeGen.TestProject [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IGrainA), "11405B98")] - public sealed class Invokable_IGrainA_GrainReference_11405B98 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed class Invokable_IGrainA_GrainReference_11405B98 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IInvokable { public string arg0; global::TestProject.IGrainA _target; @@ -57,7 +57,7 @@ public override void SetArgument(int index, object value) } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.MethodA(arg0); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { try { @@ -65,6 +65,8 @@ public override void SetArgument(int index, object value) if (!factory.IsSupported) { var original = await Invoke(); + if (original.Exception is not null) + return original; return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } @@ -95,7 +97,7 @@ public Proxy_IGrainA(global::Orleans.Runtime.GrainReferenceShared arg0, global:: [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IGrainB), "6B5D7809")] - public sealed class Invokable_IGrainB_GrainReference_6B5D7809 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed class Invokable_IGrainB_GrainReference_6B5D7809 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IInvokable { public string arg0; global::TestProject.IGrainB _target; @@ -139,7 +141,7 @@ public override void SetArgument(int index, object value) } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.MethodB(arg0); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { try { @@ -147,6 +149,8 @@ public override void SetArgument(int index, object value) if (!factory.IsSupported) { var original = await Invoke(); + if (original.Exception is not null) + return original; return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs index c9a439f3663..6c376a9419f 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs @@ -13,7 +13,7 @@ namespace OrleansCodeGen.TestProject [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IGrainA), "11405B98")] - public sealed class Invokable_IGrainA_GrainReference_11405B98 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed class Invokable_IGrainA_GrainReference_11405B98 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IInvokable { public string arg0; global::TestProject.IGrainA _target; @@ -57,7 +57,7 @@ public override void SetArgument(int index, object value) } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.MethodA(arg0); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { try { @@ -65,6 +65,8 @@ public override void SetArgument(int index, object value) if (!factory.IsSupported) { var original = await Invoke(); + if (original.Exception is not null) + return original; return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } @@ -95,7 +97,7 @@ public Proxy_IGrainA(global::Orleans.Runtime.GrainReferenceShared arg0, global:: [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "10.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IGrainB), "6B5D7809")] - public sealed class Invokable_IGrainB_GrainReference_6B5D7809 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IResponseInvokable + public sealed class Invokable_IGrainB_GrainReference_6B5D7809 : global::Orleans.Runtime.TaskRequest, global::Orleans.Serialization.Invocation.IInvokable { public string arg0; global::TestProject.IGrainB _target; @@ -139,7 +141,7 @@ public override void SetArgument(int index, object value) } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.MethodB(arg0); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IResponseInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { try { @@ -147,6 +149,8 @@ public override void SetArgument(int index, object value) if (!factory.IsSupported) { var original = await Invoke(); + if (original.Exception is not null) + return original; return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); } diff --git a/test/Orleans.Core.Tests/Serialization/SelfWritingResponseFilterTests.cs b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseFilterTests.cs index 99ba36f6f56..c33657e477a 100644 --- a/test/Orleans.Core.Tests/Serialization/SelfWritingResponseFilterTests.cs +++ b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseFilterTests.cs @@ -236,7 +236,7 @@ public void Dispose() { } } private sealed class DirectInvocation(List payload, Exception? failure = null) - : LegacyInvocation(new PayloadResponse(payload), payload), IResponseInvokable + : LegacyInvocation(new PayloadResponse(payload), payload), IInvokable { public int DirectCalls { get; private set; } public int CopyCalls { get; private set; } diff --git a/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs index 49fa72d742a..f4bfd56b5bb 100644 --- a/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs +++ b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs @@ -36,6 +36,83 @@ namespace UnitTests.Serialization; [TestCategory("BVT"), TestCategory("Serialization")] public sealed class SelfWritingResponseOwnershipTests { + [Theory] + [InlineData("Distinct")] + [InlineData("Same")] + [InlineData("Throw")] + public async Task DefaultInvokableContractCopiesAndTransfersOneOwner(string behavior) + { + using var services = new ServiceCollection().AddSerializer().BuildServiceProvider(); + var provider = services.GetRequiredService(); + var contexts = services.GetRequiredService(); + var counts = new Counts { ReturnInput = behavior == "Same", ThrowCopy = behavior == "Throw" }; + var payload = new Payload { Values = [17, 25, 42] }; + var request = new LegacyRequest(payload, counts); + request.Bind(provider); + var copier = new DeepCopier(new CountingResponseCopier(counts, provider), contexts); + + if (behavior == "Throw") + { + var exception = await Assert.ThrowsAsync(async () => + await ((IInvokable)request).InvokeAndCopy(provider, contexts, copier)); + Assert.Same(counts.CopyFailure, exception); + Assert.Equal(1, counts.Rents); + Assert.Equal(1, counts.Returns); + Assert.Null(request.ReturnedResponse!.Result); + } + else + { + var response = await ((IInvokable)request).InvokeAndCopy(provider, contexts, copier); + Assert.Equal(1, counts.ResponseCopies); + Assert.Equal(behavior == "Same" ? 0 : 1, counts.PayloadCopies); + Assert.Equal(behavior == "Same" ? 0 : 1, counts.Returns); + var result = Assert.IsType(response.Result); + Assert.Equal(new[] { 17, 25, 42 }, result.Values); + if (behavior == "Same") Assert.Same(request.ReturnedResponse, response); + else + { + Assert.NotSame(request.ReturnedResponse, response); + Assert.NotSame(payload, result); + payload.Values.Clear(); + Assert.Equal(new[] { 17, 25, 42 }, result.Values); + } + response.Dispose(); + Assert.Equal(counts.Rents, counts.Returns); + } + } + + [Theory] + [InlineData(false, false, false)] + [InlineData(false, false, true)] + [InlineData(false, true, false)] + [InlineData(false, true, true)] + [InlineData(true, false, false)] + [InlineData(true, false, true)] + [InlineData(true, true, false)] + [InlineData(true, true, true)] + public async Task ExceptionEnvelopesCopyAtDeliveryAfterFilters(bool observer, bool direct, bool filtered) + { + var counts = new Counts(); + var failure = new InvalidOperationException("original invocation exception"); + var filter = filtered ? new CallbackFilter(async context => + { + Assert.Same(failure, await Assert.ThrowsAsync(context.Invoke)); + Assert.Same(failure, context.Response!.Exception); + Assert.Equal(0, counts.ExceptionCopies); + counts.FilterFinished = true; + }) : null; + await using var fixture = new SendFixture(counts, filter, recordExceptionCopies: true); + LegacyRequest request = direct ? new DirectExceptionRequest(failure, counts) : new ExceptionRequest(failure, counts); + + using var response = await fixture.Invoke(request, observer); + + Assert.Same(failure, response.Exception); + Assert.Equal(1, counts.ExceptionCopies); + Assert.Equal(filtered, counts.FilterFinished); + Assert.Equal(filtered, counts.ExceptionCopiedAfterFilter); + Assert.Equal(0, counts.PayloadCopies); + } + [Theory] [InlineData(false)] [InlineData(true)] @@ -162,7 +239,7 @@ public async Task GeneratedCompatibilityFallback_TransfersOrReturnsOriginalExact && type.Name.StartsWith("Invokable_IConcurrentGrain_", StringComparison.Ordinal)) .Select(static type => (IInvokable)Activator.CreateInstance(type)!) .Single(static request => request.GetMethodName() == nameof(IConcurrentGrain.ModifyReturnList_Test)); - Assert.IsAssignableFrom(request); + Assert.IsAssignableFrom(request); var filter = filtered ? new CallbackFilter(context => context.Invoke()) : null; await using var fixture = new SendFixture(counts, filter, target); using var response = await fixture.Invoke(request, observer); @@ -626,6 +703,9 @@ private sealed class Counts public int ResponseCopies; public int Rents; public int Returns; + public int ExceptionCopies; + public bool FilterFinished; + public bool ExceptionCopiedAfterFilter; public bool ThrowCopy; public bool ReturnInput; public Exception CopyFailure { get; } = new InvalidOperationException("payload copy failed"); @@ -712,7 +792,7 @@ public virtual ValueTask Invoke() } } - private sealed class DirectRequest(Payload payload, Counts counts) : LegacyRequest(payload, counts), IResponseInvokable + private sealed class DirectRequest(Payload payload, Counts counts) : LegacyRequest(payload, counts), IInvokable { public override ValueTask Invoke() => throw new InvalidOperationException("The direct request uses InvokeAndCopy."); @@ -724,6 +804,39 @@ public ValueTask InvokeAndCopy(ICodecProvider provider, CopyContextPoo } } + private class ExceptionRequest(Exception failure, Counts counts) : LegacyRequest(new Payload(), counts) + { + protected Exception Failure { get; } = failure; + public override ValueTask Invoke() => ValueTask.FromResult(Response.FromException(Failure)); + } + + private sealed class DirectExceptionRequest(Exception failure, Counts counts) : ExceptionRequest(failure, counts), IInvokable + { + public override ValueTask Invoke() => throw new InvalidOperationException("Use the isolated invocation contract."); + public ValueTask InvokeAndCopy(ICodecProvider provider, CopyContextPool contexts, DeepCopier copier) + => ValueTask.FromResult(Response.FromException(Failure)); + } + + private sealed class ExceptionDeliveryCopier(Counts counts) : IDeepCopier + { + [return: NotNullIfNotNull(nameof(input))] + public ExceptionResponse? DeepCopy(ExceptionResponse? input, CopyContext context) + { + if (input is null) return null; + counts.ExceptionCopies++; + counts.ExceptionCopiedAfterFilter = counts.FilterFinished; + return input; + } + } + + private sealed class UnusedExceptionCodec : IFieldCodec + { + public ExceptionResponse ReadValue(ref Reader reader, Orleans.Serialization.WireProtocol.Field field) + => throw new NotSupportedException("The exception delivery control exercises copying."); + public void WriteField(ref Writer writer, uint delta, Type? expected, ExceptionResponse? value) + where TBufferWriter : IBufferWriter => throw new NotSupportedException("The exception delivery control exercises copying."); + } + private sealed class CountingResponseCopier(Counts counts, ICodecProvider provider) : IDeepCopier { [return: NotNullIfNotNull(nameof(input))] @@ -809,13 +922,15 @@ private sealed class SendFixture : IAsyncDisposable, IResponseCompletionSource public Dictionary? InitialContext { get; set; } public CodecProvider Provider => _services.GetRequiredService(); - public SendFixture(Counts counts, IIncomingGrainCallFilter? filter, IAddressable? target = null) + public SendFixture(Counts counts, IIncomingGrainCallFilter? filter, IAddressable? target = null, bool recordExceptionCopies = false) { _counts = counts; _observer = target ?? new Observer(); var services = new ServiceCollection(); services.AddSerializer(builder => builder.Configure(options => { + if (recordExceptionCopies) + options.AddSerializer(_ => new UnusedExceptionCodec(), _ => new ExceptionDeliveryCopier(counts)); options.AddSerializer(_ => new UnusedResponseCodec(), provider => new CountingResponseCopier(counts, provider)); options.AddSerializer(_ => new UnusedHolderCodec(), provider => new CountingHolderCopier(counts, provider)); options.AddCopier(typeof(SendFailureCopier)); diff --git a/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs b/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs index c44ea80ce59..0c01e10ce08 100644 --- a/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs +++ b/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs @@ -29,7 +29,7 @@ public static async System.Threading.Tasks.Task GeneratedInvokablesWriteCopiedRe _ = proxy.Payload(); using var request = ((RpcTupleProxyBase)proxy).Captured!; request.SetTarget(target); - using var response = await ((IResponseInvokable)request).InvokeAndCopy(provider, contexts, + using var response = await request.InvokeAndCopy(provider, contexts, new DeepCopier(provider.GetDeepCopier(), contexts)); Ensure(response is IRawResponseWriter && !response.GetType().IsGenericType, "The actual generated invokable creates a non-generic self-writing holder."); @@ -55,7 +55,7 @@ async System.Threading.Tasks.Task Check(IInvokable invocation, T expected) { using var request = invocation; request.SetTarget(target); - using var result = await ((IResponseInvokable)request).InvokeAndCopy(provider, contexts, + using var result = await request.InvokeAndCopy(provider, contexts, new DeepCopier(provider.GetDeepCopier(), contexts)); Ensure(result is IRawResponseWriter && Equals(expected, result.GetResult()), "Generated primitive responses bind direct writers."); var output = new ArrayBufferWriter(); diff --git a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs index e15607fb699..c6091a05da1 100644 --- a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs +++ b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs @@ -605,7 +605,7 @@ public async Task GeneratedResponseHoldersCopyAndWriteDirectly(string methodName var target = new RpcResponseTarget(); using var invokable = CreateInvokable(methodName); invokable.SetTarget(new TargetHolder(target)); - var direct = Assert.IsAssignableFrom(invokable); + var direct = invokable; var provider = _services.GetRequiredService(); var contexts = _services.GetRequiredService(); var compatibility = new CountingResponseCopier(); @@ -682,7 +682,7 @@ public async Task GeneratedResponseHoldersUseContextInJit(string methodName, Typ var compatibility = new CountingResponseCopier(); using var invokable = CreateInvokable(methodName); invokable.SetTarget(new TargetHolder(target)); - using var response = await Assert.IsAssignableFrom(invokable).InvokeAndCopy( + using var response = await invokable.InvokeAndCopy( provider, contexts, new DeepCopier(compatibility, contexts)); Assert.IsAssignableFrom(response); @@ -722,7 +722,7 @@ public async Task GeneratedResponseHolderPreservesRawWireBytesAndPoolReset() invokable.SetTarget(new TargetHolder(new RpcResponseTarget())); var provider = _services.GetRequiredService(); var contexts = _services.GetRequiredService(); - var direct = Assert.IsAssignableFrom(invokable); + var direct = invokable; var response = await direct.InvokeAndCopy(provider, contexts, _services.GetRequiredService().GetCopier()); var body = new ArrayBufferWriter(); var legacy = new ArrayBufferWriter(); @@ -758,7 +758,7 @@ public async Task GeneratedResponseHolderKeepsExceptionBehavior() invokable.SetTarget(new TargetHolder(new RpcResponseTarget { Fail = true })); var contexts = _services.GetRequiredService(); var compatibility = new CountingResponseCopier(); - using var response = await Assert.IsAssignableFrom(invokable).InvokeAndCopy( + using var response = await invokable.InvokeAndCopy( _services.GetRequiredService(), contexts, new DeepCopier(compatibility, contexts)); Assert.IsType(response); Assert.Equal("response failure", response.Exception!.Message); @@ -775,7 +775,7 @@ public async Task GeneratedResponseHolderPreservesCyclesAndNullPayloads() invokable.SetTarget(new TargetHolder(target)); var provider = _services.GetRequiredService(); var contexts = _services.GetRequiredService(); - using var response = await Assert.IsAssignableFrom(invokable).InvokeAndCopy( + using var response = await invokable.InvokeAndCopy( provider, contexts, _services.GetRequiredService().GetCopier()); var value = response.GetResult(); Assert.NotNull(value); @@ -800,7 +800,7 @@ public async Task GeneratedResponseHolderPreservesCyclesAndNullPayloads() Assert.Same(copied.Left, copied.Right); invokable.SetTarget(new TargetHolder(new NullPayloadTarget())); - using var empty = await ((IResponseInvokable)invokable).InvokeAndCopy(provider, contexts, _services.GetRequiredService().GetCopier()); + using var empty = await invokable.InvokeAndCopy(provider, contexts, _services.GetRequiredService().GetCopier()); Assert.IsAssignableFrom(empty); Assert.Null(empty.GetResult()); } @@ -815,7 +815,7 @@ public async Task GeneratedResponseHolderHonorsCustomPayloadCopier() var target = new RpcResponseTarget(); using var invokable = CreateInvokable("Payload"); invokable.SetTarget(new TargetHolder(target)); - using var result = await Assert.IsAssignableFrom(invokable).InvokeAndCopy( + using var result = await invokable.InvokeAndCopy( provider, contexts, services.GetRequiredService().GetCopier()); Assert.IsType>(result); Assert.Same(target.Result, result.GetResult()); @@ -848,7 +848,7 @@ public async Task GeneratedResponseHolderHonorsCustomResultAndResponseServices(s var contexts = services.GetRequiredService(); using var invokable = CreateInvokable("Integer"); invokable.SetTarget(new TargetHolder(new RpcResponseTarget())); - using var result = await Assert.IsAssignableFrom(invokable).InvokeAndCopy( + using var result = await invokable.InvokeAndCopy( provider, contexts, services.GetRequiredService().GetCopier()); Assert.Null(result.Exception); @@ -869,7 +869,7 @@ public async Task GeneratedResponseReaderReturnsHolderAfterMalformedPayload() invokable.SetTarget(new TargetHolder(new RpcResponseTarget())); var provider = _services.GetRequiredService(); var contexts = _services.GetRequiredService(); - var direct = Assert.IsAssignableFrom(invokable); + var direct = invokable; var copier = _services.GetRequiredService().GetCopier(); var original = await direct.InvokeAndCopy(provider, contexts, copier); original.Dispose(); From eed5c6449b0d33223dee930031d9bc0ce74ca4a4 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Wed, 7 Oct 2026 13:04:26 -0700 Subject: [PATCH 47/54] fix(codegen): retain shared response graph for explicit RPC contracts --- .../docs/implementation/serialization.md | 2 +- .../RpcResponseGenerator.cs | 9 +- .../OrleansSourceGeneratorTests.cs | 107 +++++++++++++++++- 3 files changed, 111 insertions(+), 7 deletions(-) diff --git a/docs/site/src/content/docs/implementation/serialization.md b/docs/site/src/content/docs/implementation/serialization.md index b69f0d7f5ca..7d39d3b6fd7 100644 --- a/docs/site/src/content/docs/implementation/serialization.md +++ b/docs/site/src/content/docs/implementation/serialization.md @@ -147,7 +147,7 @@ The receiving message serializer first consults ` and `ValueTask` method results, the generator emits identical invocation code and closed response registrations for JIT and NativeAOT execution. Provider registration precedence selects the services in both execution modes. The graph uses the concrete result implementations in and . Recursive result dependencies resolve with a construction caller after the response implementation has been allocated. Reference payload codecs and copiers preserve payload cycles and shared references, and the pooled response envelope retains the existing field and raw-message encoding. -The graph also registers polymorphic codec and copier dispatch for the non-generic boundary used by the runtime client. That dispatch selects the closed implementation for the actual response type and preserves the identity of immutable completed and exception responses. The native smoke uses with `Response`, matching the runtime's response-copy boundary. +Every response-returning RPC also registers polymorphic codec and copier dispatch for the non-generic boundary used by the runtime client, including results supplied entirely by explicit closed contracts. That dispatch selects the closed implementation for the actual response type and preserves the identity of immutable completed and exception responses. The native smoke uses with `Response`, matching the runtime's response-copy boundary. Completed response transport uses the existing generated codec and its canonical singleton activator, restoring after a round-trip. Interfaces containing only non-generic `Task` or `ValueTask` methods also generate this shared response/completion graph. diff --git a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs index b11c9364991..53c7e632fe3 100644 --- a/src/Orleans.CodeGenerator/RpcResponseGenerator.cs +++ b/src/Orleans.CodeGenerator/RpcResponseGenerator.cs @@ -49,7 +49,7 @@ internal static ImmutableArray Generate( var constructorServices = GetConstructorServices(preparation.SourceOutputs, cancellationToken); var results = new Dictionary(SymbolEqualityComparer.Default); var arguments = new Dictionary(SymbolEqualityComparer.Default); - var hasCompletionMethods = false; + var hasResponseMethods = false; var output = ImmutableArray.CreateBuilder(); foreach (var proxy in proxies) { @@ -95,10 +95,10 @@ internal static ImmutableArray Generate( continue; } + hasResponseMethods = true; if (SymbolEqualityComparer.Default.Equals(returnType, services.LibraryTypes.Task) || SymbolEqualityComparer.Default.Equals(returnType, services.LibraryTypes.ValueTask)) { - hasCompletionMethods = true; continue; } @@ -160,7 +160,6 @@ internal static ImmutableArray Generate( } } - var hasResponseRoots = supportedResults.Count > 0 || metadataModelRoots.Count > 0 || hasCompletionMethods; foreach (var argument in arguments.OrderBy(static entry => entry.Key.ToDisplayString(), StringComparer.Ordinal)) { if (coveredConstructionTypes.Contains(argument.Key)) continue; @@ -180,7 +179,7 @@ internal static ImmutableArray Generate( } } - if (supportedResults.Count == 0 && metadataModelRoots.Count == 0 && argumentRoots.Count == 0 && responseHolders.Count == 0 && !hasCompletionMethods) + if (supportedResults.Count == 0 && metadataModelRoots.Count == 0 && argumentRoots.Count == 0 && responseHolders.Count == 0 && !hasResponseMethods) { return output.ToImmutable(); } @@ -234,7 +233,7 @@ internal static ImmutableArray Generate( source.AppendLine(metadataRoot.ConfigurationStatements); } } - if (hasResponseRoots) + if (hasResponseMethods) { source.AppendLine("options.AddDefaultSerializerService(static provider => new ResponseFieldCodec());"); source.AppendLine("options.AddDefaultSerializerService(static provider => new ResponseFieldCopier());"); diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index f987ec36429..20f7efbe2de 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -2486,12 +2486,117 @@ public interface IResponses : IGrainWithIntegerKey { Task<{{resultType}}> Get(); Assert.Equal("ORLEANS0116", diagnostic.Id); Assert.Contains("comparer contract", diagnostic.GetMessage()); Assert.Contains("Dictionary", diagnostic.GetMessage()); - Assert.DoesNotContain(native.GeneratedSources, static source => source.HintName.EndsWith(".orleans.rpcresponses.g.cs", StringComparison.Ordinal)); + var shared = Assert.Single(native.GeneratedSources, static source => source.HintName.EndsWith(".orleans.rpcresponses.g.cs", StringComparison.Ordinal)).SourceText.ToString(); + Assert.Contains("options.AddDefaultSerializer", shared); + Assert.DoesNotContain("PooledResponseCodec<", shared); var jit = RunSourceGenerator(compilation); Assert.Empty(jit.Diagnostics); Assert.Contains(jit.GeneratedSources, static source => source.HintName.Contains(".orleans.proxy.", StringComparison.Ordinal)); } + [Theory] + [InlineData("Task> Get();")] + [InlineData("ValueTask> Get();")] + [InlineData("Task>> Get();")] + [InlineData("Task Get();")] + [InlineData("ValueTask Get();")] + public async Task RpcResponseFactoriesKeepSharedGraphForExplicitOnlyContracts(string declaration) + { + var compilation = await CreateCompilation($$""" + using Orleans; + using System.Collections.Generic; + using System.Threading.Tasks; + namespace TestProject; + public interface IExplicit : IGrainWithIntegerKey { {{declaration}} } + """); + var managed = RunSourceGenerator(compilation); + var native = RunSourceGenerator(compilation, new Dictionary + { + ["build_property.publishaot"] = "true", + ["build_property.orleansvalidaterpcresponsefactories"] = "false", + }); + Assert.Empty(managed.Diagnostics); + Assert.Empty(native.Diagnostics); + var source = Assert.Single(native.GeneratedSources, + static item => item.HintName.EndsWith(".orleans.rpcresponses.g.cs", StringComparison.Ordinal)).SourceText.ToString(); + Assert.Equal(1, CountOccurrences(source, "options.AddDefaultSerializer")); + Assert.Contains("new ResponseFieldCodec()", source); + Assert.Contains("new ResponseFieldCopier()", source); + Assert.Contains("options.AddDefaultSerializer", source); + Assert.DoesNotContain("PooledResponseCodec<", source); + Assert.Equal(ConcatenateGeneratedSources(managed), ConcatenateGeneratedSources(native)); + var output = compilation.AddReferences(MetadataReference.CreateFromFile(typeof(Microsoft.Extensions.Options.IConfigureOptions<>).Assembly.Location)) + .AddSyntaxTrees(native.GeneratedSources.Select(static item => CSharpSyntaxTree.ParseText(item.SourceText, path: item.HintName))); + Assert.Empty(output.GetDiagnostics(TestContext.Current.CancellationToken).Where(static item => item.Severity == DiagnosticSeverity.Error)); + } + + [Fact] + public async Task ExplicitOnlyRpcGraphResolvesAndExecutesRuntimeResponseCopier() + { + var compilation = await CreateCompilation(""" + using Orleans; + using System.Collections.Generic; + using System.Threading.Tasks; + namespace TestProject; + public interface IExplicit : IGrainWithIntegerKey { Task> Get(); } + """, $"ExplicitResponseProof{Guid.NewGuid():N}"); + var generated = RunSourceGenerator(compilation, new Dictionary + { + ["build_property.publishaot"] = "true", + ["build_property.orleansvalidaterpcresponsefactories"] = "false", + }); + Assert.Empty(generated.Diagnostics); + var exercise = $$""" + using System; + using System.Collections.Generic; + using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.Options; + using Orleans.Serialization; + using Orleans.Serialization.Cloning; + using Orleans.Serialization.Codecs; + using Orleans.Serialization.Configuration; + using Orleans.Serialization.Invocation; + using Orleans.Serialization.Serializers; + public static class ExplicitResponseProof + { + public static bool Run() + { + var options = new TypeManifestOptions(); + ((IConfigureOptions)new OrleansCodeGen.{{compilation.AssemblyName}}.RpcResponseFactories()).Configure(options); + var codec = new DictionaryCodec(new StringCodec(), new Int32Codec()); + var copier = new DictionaryCopier(new ShallowCopier(), new ShallowCopier()); + options.AddSerializer>>( + _ => new PooledResponseCodec, DictionaryCodec>(codec), + _ => new PooledResponseCopier, DictionaryCopier>(copier)); + using var services = new ServiceCollection().BuildServiceProvider(); + var provider = new CodecProvider(services, Options.Create(options)); + using var contexts = new CopyContextPool(provider); + var runtimeCopier = new DeepCopier(provider.GetDeepCopier(), contexts); + var original = new Dictionary(StringComparer.OrdinalIgnoreCase) { ["Key"] = 47 }; + using var response = Response.FromResult(original); + using var copied = runtimeCopier.Copy(response); + var result = copied.GetResult>(); + original.Clear(); + return provider.GetCodec().GetType().Assembly == typeof(ExplicitResponseProof).Assembly + && provider.GetDeepCopier().GetType().Assembly == typeof(ExplicitResponseProof).Assembly + && !ReferenceEquals(response, copied) && !ReferenceEquals(original, result) + && ReferenceEquals(StringComparer.OrdinalIgnoreCase, result.Comparer) + && result.Count == 1 && result["key"] == 47; + } + } + """; + var output = compilation.AddReferences( + MetadataReference.CreateFromFile(typeof(Microsoft.Extensions.Options.IConfigureOptions<>).Assembly.Location), + MetadataReference.CreateFromFile(typeof(ServiceProvider).Assembly.Location)) + .AddSyntaxTrees(generated.GeneratedSources.Select(static item => CSharpSyntaxTree.ParseText(item.SourceText, path: item.HintName))) + .AddSyntaxTrees(CSharpSyntaxTree.ParseText(exercise, cancellationToken: TestContext.Current.CancellationToken)); + using var image = new System.IO.MemoryStream(); + var emit = output.Emit(image, cancellationToken: TestContext.Current.CancellationToken); + Assert.True(emit.Success, string.Join(Environment.NewLine, emit.Diagnostics)); + var assembly = System.Reflection.Assembly.Load(image.ToArray()); + Assert.Equal(true, assembly.GetType("ExplicitResponseProof")!.GetMethod("Run")!.Invoke(null, null)); + } + [Fact] public async Task RpcResponseFactoriesRootCanonicalModelsInCommonPipeline() { From e3cc8d16f0459fab623176d9a9d96e92f1f71cec Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Wed, 7 Oct 2026 13:23:55 -0700 Subject: [PATCH 48/54] fix(rpc): release response bodies on terminal message ownership transitions --- .../docs/implementation/serialization.md | 2 +- src/Orleans.Core/Messaging/Message.cs | 24 ++++-- .../Networking/MessageWriteRequest.cs | 9 +- src/Orleans.Core/Runtime/CallbackData.cs | 3 +- .../MessageTransportLifecycleTests.cs | 82 +++++++++++++++++++ .../SelfWritingResponseOwnershipTests.cs | 3 +- 6 files changed, 102 insertions(+), 21 deletions(-) diff --git a/docs/site/src/content/docs/implementation/serialization.md b/docs/site/src/content/docs/implementation/serialization.md index 7d39d3b6fd7..2550a35976b 100644 --- a/docs/site/src/content/docs/implementation/serialization.md +++ b/docs/site/src/content/docs/implementation/serialization.md @@ -139,7 +139,7 @@ Incoming filters receive an isolated result and can transform its envelope or ne Generated holders implement . The message serializer selects their direct writer before runtime-type codec lookup. Primitive holders call the existing static primitive codecs; reference holders use their bound concrete result codec and the message's serialization session. The wire representation retains the result-type header, field zero, end marker, null behavior, cycles, and shared references. Returning a holder to its pool clears both its result and its provider-owned factory binding. -Successful remote write completion releases each response envelope and clears the message's reference to it after recording the send. Serialization and transport-write failures retain the envelope for retry or rerouting, preserving its payload until the successful write completes. +Successful remote write completion releases each response envelope and clears the message's reference to it after recording the send. A transport-write failure retains the envelope for retry or rerouting. Terminal message disposal and body replacement release the owned envelope; serialization failure replaces it with an exception response or releases it on a terminal drop. On receipt, the callback transfers envelope ownership to . Typed completion extracts the result and releases the envelope, preserving the result payload for the caller. Untyped completion transfers a successful envelope to its awaiting consumer; void consumption releases it directly. Outgoing filters retain selected and superseded envelopes through their continuations, and the invocation releases them after extracting the final result or unwinding a failure. Application code calling `Complete` transfers ownership and leaves envelope disposal to the completion pipeline. diff --git a/src/Orleans.Core/Messaging/Message.cs b/src/Orleans.Core/Messaging/Message.cs index 64a2b2cca3d..fe8c20f10e1 100644 --- a/src/Orleans.Core/Messaging/Message.cs +++ b/src/Orleans.Core/Messaging/Message.cs @@ -36,7 +36,8 @@ public object? BodyObject set { - (_bodyObject as MessageReadRequest)?.Reset(); + if (ReferenceEquals(_bodyObject, value)) return; + Dispose(); _bodyObject = value; } } @@ -111,26 +112,33 @@ private void DeserializeRequestBody(MessageReadRequest readRequest) [MethodImpl(MethodImplOptions.AggressiveInlining)] internal void SetMessageReadRequest(MessageReadRequest request) { - if (_bodyObject is MessageReadRequest current && !ReferenceEquals(current, request)) - { - current.Reset(); - } + BodyObject = request; + } - _bodyObject = request; + internal object? TakeBodyObject() + { + var result = BodyObject; + _bodyObject = null; + return result; } - internal void ReleaseBodyBuffer() + internal void ReleaseBody() { if (_bodyObject is MessageReadRequest readRequest) { _bodyObject = null; readRequest.Reset(); } + else if (_bodyObject is Response response) + { + _bodyObject = null; + response.Dispose(); + } } public void Dispose() { - (_bodyObject as MessageReadRequest)?.Reset(); + ReleaseBody(); _bodyObject = null; } diff --git a/src/Orleans.Core/Networking/MessageWriteRequest.cs b/src/Orleans.Core/Networking/MessageWriteRequest.cs index ef8014359ac..1a3315264ea 100644 --- a/src/Orleans.Core/Networking/MessageWriteRequest.cs +++ b/src/Orleans.Core/Networking/MessageWriteRequest.cs @@ -4,7 +4,6 @@ using Orleans.Connections.Transport; using Microsoft.Extensions.Logging; using System.Collections.Generic; -using Orleans.Serialization.Invocation; namespace Orleans.Runtime.Messaging; @@ -88,13 +87,7 @@ public override void SetResult() { foreach (var (message, _, _) in _messages) { - if (message._bodyObject is Response response) - { - message._bodyObject = null; - response.Dispose(); - } - - message.ReleaseBodyBuffer(); + message.ReleaseBody(); } Reset(); diff --git a/src/Orleans.Core/Runtime/CallbackData.cs b/src/Orleans.Core/Runtime/CallbackData.cs index f43a8449836..2bad4462487 100644 --- a/src/Orleans.Core/Runtime/CallbackData.cs +++ b/src/Orleans.Core/Runtime/CallbackData.cs @@ -239,8 +239,7 @@ private static void ResponseCallback(Message message, IResponseCompletionSource { try { - var body = message.BodyObject; - message._bodyObject = null; + var body = message.TakeBodyObject(); if (body is Response response) { context.Complete(response); diff --git a/test/Orleans.Core.Tests/Networking/MessageTransportLifecycleTests.cs b/test/Orleans.Core.Tests/Networking/MessageTransportLifecycleTests.cs index badb0f2f05c..bd11896b021 100644 --- a/test/Orleans.Core.Tests/Networking/MessageTransportLifecycleTests.cs +++ b/test/Orleans.Core.Tests/Networking/MessageTransportLifecycleTests.cs @@ -667,6 +667,85 @@ public async Task MessageWriteRequest_SerializationFailure_RetainsResponseAndVal await connection.CloseAsync(null); } + [Theory] + [InlineData(false)] + [InlineData(true)] + public void Message_TerminalDisposeOrReplacement_ReleasesResponseOnce(bool replace) + { + var response = new TrackedRawResponse("owned payload"); + var message = new Message { Direction = Message.Directions.Response, BodyObject = response }; + message.BodyObject = response; + Assert.Equal(0, response.DisposeCount); + + if (replace) message.BodyObject = Response.FromException(new IOException("replacement")); + else message.Dispose(); + + Assert.Equal(1, response.DisposeCount); + Assert.Null(response.Result); + message.Dispose(); + message.Dispose(); + Assert.Null(message._bodyObject); + Assert.Equal(1, response.DisposeCount); + } + + [Fact] + public async Task MessageWriteRequest_FailedWriteThenTerminalDrop_ReleasesRetainedResponse() + { + using var services = CreateServiceProvider(); + using var shared = CreateMessageHandlerShared(services); + await using var transport = new CapturingTransport(); + var connection = new ResponseSendConnection(transport, CreateConnectionCommon(services, shared), shared.MessageCenter); + var response = new TrackedRawResponse("failed write"); + var message = new Message { Direction = Message.Directions.Response, BodyObject = response }; + var request = shared.GetSendMessageHandler(connection); + request.WriteMessage(message); + + request.SetException(new IOException("reroute")); + var retry = await connection.Retried.WaitAsync(TestContext.Current.CancellationToken); + Assert.Same(response, retry.Message._bodyObject); + Assert.Equal(0, response.DisposeCount); + retry.Message.Dispose(); + + Assert.Equal(1, response.DisposeCount); + Assert.Null(response.Result); + Assert.Null(message._bodyObject); + await connection.CloseAsync(null); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task Connection_SerializationFailure_ReleasesReplacedOrDroppedResponse(bool exhaustedRetries) + { + using var services = CreateServiceProvider(); + using var shared = CreateMessageHandlerShared(services); + await using var transport = new CapturingTransport(); + var sent = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var connection = new ResponseSendConnection(transport, CreateConnectionCommon(services, shared), shared.MessageCenter, + message => + { + Assert.IsType(message._bodyObject); + sent.TrySetResult(); + }); + var response = new TrackedRawResponse("bad serialization") { FailWriting = true }; + var message = new Message + { + Direction = Message.Directions.Response, + BodyObject = response, + RetryCount = (short)(exhaustedRetries ? MessagingOptions.DEFAULT_MAX_MESSAGE_SEND_RETRIES : 0), + }; + + connection.Send(message); + if (!exhaustedRetries) await sent.Task.WaitAsync(TimeSpan.FromSeconds(10), TestContext.Current.CancellationToken); + await response.Disposed.WaitAsync(TimeSpan.FromSeconds(10), TestContext.Current.CancellationToken); + await connection.CloseAsync(null); + + Assert.Equal(1, response.DisposeCount); + Assert.Null(response.Result); + Assert.Null(message._bodyObject); + Assert.Equal(exhaustedRetries ? MessagingOptions.DEFAULT_MAX_MESSAGE_SEND_RETRIES : 1, message.RetryCount); + } + [Fact] public void MessageWriteRequest_LargeMessageState_TracksFramesAndAdaptsPageSize() { @@ -1120,7 +1199,9 @@ protected internal override void RecordMessageReceive(Message message, int total private sealed class TrackedRawResponse(string payload) : Response, IRawResponseWriter { + private readonly TaskCompletionSource _disposed = new(TaskCreationOptions.RunContinuationsAsynchronously); public int DisposeCount { get; private set; } + public Task Disposed => _disposed.Task; public bool FailWriting { get; set; } public override object? Result { get; set; } = payload; public override Exception? Exception { get; set; } @@ -1130,6 +1211,7 @@ public override void Dispose() { DisposeCount++; Result = null; + _disposed.TrySetResult(); } public void WriteRaw(ref Writer writer) where TBufferWriter : IBufferWriter diff --git a/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs index f4bfd56b5bb..bca6e2efbfd 100644 --- a/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs +++ b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs @@ -1051,9 +1051,8 @@ public Task AssertFrameRoundTrip(Response response) using var received = SelfWritingResponseMessageTests.ReadFrame(_serializer, frame); Assert.Equal(message.Direction, received.Direction); Assert.Equal(message.Id, received.Id); - using var result = Assert.IsAssignableFrom(received.BodyObject); + using var result = Assert.IsAssignableFrom(received.TakeBodyObject()); Assert.Equal(Assert.IsType(response.Result).Values, Assert.IsType(result.Result).Values); - received.BodyObject = null; return Task.CompletedTask; } From 37d97ce9b224248cddb1e1ff63775496271d088c Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Wed, 7 Oct 2026 13:52:54 -0700 Subject: [PATCH 49/54] fix(rpc): preserve custom response codec and copier subclasses --- .../docs/implementation/serialization.md | 2 +- .../RpcResponseHolderGenerator.cs | 8 +- ...ests.TestBasicGrain.DotNet10_0.verified.cs | 2 +- ...Tests.TestBasicGrain.DotNet8_0.verified.cs | 2 +- ...rializersAnnotation.DotNet10_0.verified.cs | 2 +- ...erializersAnnotation.DotNet8_0.verified.cs | 2 +- ...stGrainComplexGrain.DotNet10_0.verified.cs | 2 +- ...estGrainComplexGrain.DotNet8_0.verified.cs | 2 +- ...thInvokableBaseType.DotNet10_0.verified.cs | 2 +- ...ithInvokableBaseType.DotNet8_0.verified.cs | 2 +- ...WithResponseTimeout.DotNet10_0.verified.cs | 2 +- ...dWithResponseTimeout.DotNet8_0.verified.cs | 2 +- ...thDifferentKeyTypes.DotNet10_0.verified.cs | 8 +- ...ithDifferentKeyTypes.DotNet8_0.verified.cs | 8 +- ...hMultipleInterfaces.DotNet10_0.verified.cs | 2 +- ...thMultipleInterfaces.DotNet8_0.verified.cs | 2 +- .../RpcResponseTests.cs | 90 +++++++++++++++++++ 17 files changed, 115 insertions(+), 25 deletions(-) diff --git a/docs/site/src/content/docs/implementation/serialization.md b/docs/site/src/content/docs/implementation/serialization.md index 2550a35976b..d90761bf715 100644 --- a/docs/site/src/content/docs/implementation/serialization.md +++ b/docs/site/src/content/docs/implementation/serialization.md @@ -143,7 +143,7 @@ Successful remote write completion releases each response envelope and clears th On receipt, the callback transfers envelope ownership to . Typed completion extracts the result and releases the envelope, preserving the result payload for the caller. Untyped completion transfers a successful envelope to its awaiting consumer; void consumption releases it directly. Outgoing filters retain selected and superseded envelopes through their continuations, and the invocation releases them after extracting the final result or unwinding a failure. Application code calling `Complete` transfers ownership and leaves envelope disposal to the completion pipeline. -The receiving message serializer first consults using the result type from the wire header. Generated registrations reconstruct a bound holder directly. Compatibility paths retain ordinary response codecs for custom response/payload implementations, custom invokable bases, and unresolved generic contracts. Generated direct factories activate only when the selected result and response codecs/copiers match the canonical implementations, so explicit application behavior retains precedence. +The receiving message serializer first consults using the result type from the wire header. Generated registrations reconstruct a bound holder directly. Compatibility paths retain ordinary response codecs for custom response/payload implementations, custom invokable bases, and unresolved generic contracts. Generated direct factories activate only when the selected result services match the canonical implementations and the response codecs/copiers have the exact canonical types. Custom response subclasses retain their selected raw wire and copying behavior through the compatibility path. For concrete `Task` and `ValueTask` method results, the generator emits identical invocation code and closed response registrations for JIT and NativeAOT execution. Provider registration precedence selects the services in both execution modes. The graph uses the concrete result implementations in and . Recursive result dependencies resolve with a construction caller after the response implementation has been allocated. Reference payload codecs and copiers preserve payload cycles and shared references, and the pooled response envelope retains the existing field and raw-message encoding. diff --git a/src/Orleans.CodeGenerator/RpcResponseHolderGenerator.cs b/src/Orleans.CodeGenerator/RpcResponseHolderGenerator.cs index b459e953678..bcf6eaedba2 100644 --- a/src/Orleans.CodeGenerator/RpcResponseHolderGenerator.cs +++ b/src/Orleans.CodeGenerator/RpcResponseHolderGenerator.cs @@ -154,10 +154,10 @@ internal sealed class {{factory}} : global::Orleans.Serialization.Invocation.Res var responseCodec = provider.GetCodec>(); var responseCopier = provider.GetDeepCopier>(); IsSupported = _codec is not null && _copier is not null - && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec<{{type}}, {{codec}}> - || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec<{{type}}, global::Orleans.Serialization.Codecs.IFieldCodec<{{type}}>>) - && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier<{{type}}, {{copier}}> - || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier<{{type}}, global::Orleans.Serialization.Cloning.IDeepCopier<{{type}}>>); + && (responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec<{{type}}, {{codec}}>) + || responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec<{{type}}, global::Orleans.Serialization.Codecs.IFieldCodec<{{type}}>>)) + && (responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier<{{type}}, {{copier}}>) + || responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier<{{type}}, global::Orleans.Serialization.Cloning.IDeepCopier<{{type}}>>)); } internal global::Orleans.Serialization.Invocation.Response RentCopied({{type}} value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) { diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs index ee97e87fe45..a60d7a57013 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs @@ -400,7 +400,7 @@ public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICo _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; var responseCodec = provider.GetCodec>(); var responseCopier = provider.GetDeepCopier>(); - IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + IsSupported = _codec is not null && _copier is not null && (responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec) || responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec>)) && (responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier>) || responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier>)); } internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs index 46953355865..fe10ac95101 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs @@ -401,7 +401,7 @@ public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICo _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; var responseCodec = provider.GetCodec>(); var responseCopier = provider.GetDeepCopier>(); - IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + IsSupported = _codec is not null && _copier is not null && (responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec) || responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec>)) && (responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier>) || responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier>)); } internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs index e4a847c9b25..91e813b5c6b 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs @@ -308,7 +308,7 @@ public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICo _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; var responseCodec = provider.GetCodec>(); var responseCopier = provider.GetDeepCopier>(); - IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + IsSupported = _codec is not null && _copier is not null && (responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec) || responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec>)) && (responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier>) || responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier>)); } internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs index 4b021caf541..bcd21d09769 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs @@ -309,7 +309,7 @@ public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICo _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; var responseCodec = provider.GetCodec>(); var responseCopier = provider.GetDeepCopier>(); - IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + IsSupported = _codec is not null && _copier is not null && (responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec) || responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec>)) && (responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier>) || responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier>)); } internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs index 1c84331ceff..4876eaf9179 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs @@ -600,7 +600,7 @@ public RpcResponse_FC7DD5BDFactory(global::Orleans.Serialization.Serializers.ICo _copier = provider.GetDeepCopier() as global::OrleansCodeGen.TestProject.Copier_ComplexData; var responseCodec = provider.GetCodec>(); var responseCopier = provider.GetDeepCopier>(); - IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + IsSupported = _codec is not null && _copier is not null && (responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec) || responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec>)) && (responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier) || responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier>)); } internal global::Orleans.Serialization.Invocation.Response RentCopied(global::TestProject.ComplexData value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs index ae6548f6de5..6d53463b850 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs @@ -600,7 +600,7 @@ public RpcResponse_FC7DD5BDFactory(global::Orleans.Serialization.Serializers.ICo _copier = provider.GetDeepCopier() as global::OrleansCodeGen.TestProject.Copier_ComplexData; var responseCodec = provider.GetCodec>(); var responseCopier = provider.GetDeepCopier>(); - IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + IsSupported = _codec is not null && _copier is not null && (responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec) || responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec>)) && (responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier) || responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier>)); } internal global::Orleans.Serialization.Invocation.Response RentCopied(global::TestProject.ComplexData value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs index 55e0f611a53..4c3c2139018 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs @@ -405,7 +405,7 @@ public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICo _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; var responseCodec = provider.GetCodec>(); var responseCopier = provider.GetDeepCopier>(); - IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + IsSupported = _codec is not null && _copier is not null && (responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec) || responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec>)) && (responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier>) || responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier>)); } internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs index e223279cdac..8980c0a018e 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs @@ -406,7 +406,7 @@ public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICo _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; var responseCodec = provider.GetCodec>(); var responseCopier = provider.GetDeepCopier>(); - IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + IsSupported = _codec is not null && _copier is not null && (responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec) || responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec>)) && (responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier>) || responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier>)); } internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs index 662ff772a7d..409081c13f3 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs @@ -307,7 +307,7 @@ public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICo _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; var responseCodec = provider.GetCodec>(); var responseCopier = provider.GetDeepCopier>(); - IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + IsSupported = _codec is not null && _copier is not null && (responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec) || responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec>)) && (responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier>) || responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier>)); } internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs index 6a53646690a..69ba2592892 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs @@ -308,7 +308,7 @@ public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICo _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; var responseCodec = provider.GetCodec>(); var responseCopier = provider.GetDeepCopier>(); - IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + IsSupported = _codec is not null && _copier is not null && (responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec) || responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec>)) && (responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier>) || responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier>)); } internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs index f636a261019..4a39f414383 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs @@ -1021,7 +1021,7 @@ public RpcResponse_5C3A711CFactory(global::Orleans.Serialization.Serializers.ICo _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; var responseCodec = provider.GetCodec>(); var responseCopier = provider.GetDeepCopier>(); - IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + IsSupported = _codec is not null && _copier is not null && (responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec) || responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec>)) && (responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier>) || responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier>)); } internal global::Orleans.Serialization.Invocation.Response RentCopied(global::System.Guid value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) @@ -1154,7 +1154,7 @@ public RpcResponse_6A3EE8F4Factory(global::Orleans.Serialization.Serializers.ICo _copier = provider.GetDeepCopier>() as global::Orleans.Serialization.Codecs.TupleCopier; var responseCodec = provider.GetCodec>>(); var responseCopier = provider.GetDeepCopier>>(); - IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec> || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec>>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Cloning.IDeepCopier>>); + IsSupported = _codec is not null && _copier is not null && (responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>) || responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec>>)) && (responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>) || responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Cloning.IDeepCopier>>)); } internal global::Orleans.Serialization.Invocation.Response RentCopied(global::System.Tuple value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) @@ -1295,7 +1295,7 @@ public RpcResponse_AFB713E4Factory(global::Orleans.Serialization.Serializers.ICo _copier = provider.GetDeepCopier>() as global::Orleans.Serialization.Codecs.TupleCopier; var responseCodec = provider.GetCodec>>(); var responseCopier = provider.GetDeepCopier>>(); - IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec> || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec>>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Cloning.IDeepCopier>>); + IsSupported = _codec is not null && _copier is not null && (responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>) || responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec>>)) && (responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>) || responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Cloning.IDeepCopier>>)); } internal global::Orleans.Serialization.Invocation.Response RentCopied(global::System.Tuple value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) @@ -1442,7 +1442,7 @@ public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICo _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; var responseCodec = provider.GetCodec>(); var responseCopier = provider.GetDeepCopier>(); - IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + IsSupported = _codec is not null && _copier is not null && (responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec) || responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec>)) && (responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier>) || responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier>)); } internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs index 67522ce0465..eef0f6d5d4f 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs @@ -1022,7 +1022,7 @@ public RpcResponse_5C3A711CFactory(global::Orleans.Serialization.Serializers.ICo _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; var responseCodec = provider.GetCodec>(); var responseCopier = provider.GetDeepCopier>(); - IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + IsSupported = _codec is not null && _copier is not null && (responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec) || responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec>)) && (responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier>) || responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier>)); } internal global::Orleans.Serialization.Invocation.Response RentCopied(global::System.Guid value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) @@ -1156,7 +1156,7 @@ public RpcResponse_6A3EE8F4Factory(global::Orleans.Serialization.Serializers.ICo _copier = provider.GetDeepCopier>() as global::Orleans.Serialization.Codecs.TupleCopier; var responseCodec = provider.GetCodec>>(); var responseCopier = provider.GetDeepCopier>>(); - IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec> || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec>>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Cloning.IDeepCopier>>); + IsSupported = _codec is not null && _copier is not null && (responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>) || responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec>>)) && (responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>) || responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Cloning.IDeepCopier>>)); } internal global::Orleans.Serialization.Invocation.Response RentCopied(global::System.Tuple value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) @@ -1298,7 +1298,7 @@ public RpcResponse_AFB713E4Factory(global::Orleans.Serialization.Serializers.ICo _copier = provider.GetDeepCopier>() as global::Orleans.Serialization.Codecs.TupleCopier; var responseCodec = provider.GetCodec>>(); var responseCopier = provider.GetDeepCopier>>(); - IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec> || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec>>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Cloning.IDeepCopier>>); + IsSupported = _codec is not null && _copier is not null && (responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.TupleCodec>) || responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec, global::Orleans.Serialization.Codecs.IFieldCodec>>)) && (responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Codecs.TupleCopier>) || responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier, global::Orleans.Serialization.Cloning.IDeepCopier>>)); } internal global::Orleans.Serialization.Invocation.Response RentCopied(global::System.Tuple value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) @@ -1446,7 +1446,7 @@ public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICo _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; var responseCodec = provider.GetCodec>(); var responseCopier = provider.GetDeepCopier>(); - IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + IsSupported = _codec is not null && _copier is not null && (responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec) || responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec>)) && (responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier>) || responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier>)); } internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs index f333f425393..12a080ccbcf 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs @@ -465,7 +465,7 @@ public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICo _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; var responseCodec = provider.GetCodec>(); var responseCopier = provider.GetDeepCopier>(); - IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + IsSupported = _codec is not null && _copier is not null && (responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec) || responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec>)) && (responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier>) || responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier>)); } internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs index 6c376a9419f..0515cd36f85 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs @@ -466,7 +466,7 @@ public RpcResponse_9146C7E3Factory(global::Orleans.Serialization.Serializers.ICo _copier = provider.GetDeepCopier() as global::Orleans.Serialization.Cloning.ShallowCopier; var responseCodec = provider.GetCodec>(); var responseCopier = provider.GetDeepCopier>(); - IsSupported = _codec is not null && _copier is not null && (responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec || responseCodec is global::Orleans.Serialization.Invocation.PooledResponseCodec>) && (responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier> || responseCopier is global::Orleans.Serialization.Invocation.PooledResponseCopier>); + IsSupported = _codec is not null && _copier is not null && (responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec) || responseCodec.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCodec>)) && (responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier>) || responseCopier.GetType() == typeof(global::Orleans.Serialization.Invocation.PooledResponseCopier>)); } internal global::Orleans.Serialization.Invocation.Response RentCopied(string value, global::Orleans.Serialization.Cloning.CopyContextPool contexts) diff --git a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs index c6091a05da1..56b45437bf6 100644 --- a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs +++ b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs @@ -901,6 +901,96 @@ public async Task GeneratedResponseReaderReturnsHolderAfterMalformedPayload() Assert.Equal(42, reused.GetResult()); } + [Theory] + [InlineData(false, false)] + [InlineData(false, true)] + [InlineData(true, false)] + [InlineData(true, true)] + public async Task GeneratedResponseHolderHonorsCanonicalResponseSubclasses(bool interfaceServices, bool customCodec) + { + var counts = new SubclassCounts(); + ResponseCodec codec = interfaceServices + ? new CustomRawResponseCodec>(new Int32Codec(), counts) + : new CustomRawResponseCodec(new Int32Codec(), counts); + IDeepCopier> copier = interfaceServices + ? new CustomResponseSubclassCopier>(new ShallowCopier(), counts) + : new CustomResponseSubclassCopier>(new ShallowCopier(), counts); + using var services = new ServiceCollection().AddSerializer(builder => builder.Configure(options => + options.AddSerializer>( + _ => customCodec ? (IFieldCodec>)codec : new PooledResponseCodec(new Int32Codec()), + _ => customCodec ? new PooledResponseCopier>(new ShallowCopier()) : copier))) + .BuildServiceProvider(); + var provider = services.GetRequiredService(); + var contexts = services.GetRequiredService(); + using var invokable = CreateInvokable("Integer"); + invokable.SetTarget(new TargetHolder(new RpcResponseTarget())); + + using var response = await invokable.InvokeAndCopy(provider, contexts, services.GetRequiredService().GetCopier()); + + Assert.IsType>(response); + Assert.Equal(customCodec ? 42 : 43, response.GetResult()); + Assert.Equal(customCodec ? 0 : 1, counts.Copies); + Assert.False(provider.TryGetRawResponseReader(typeof(int), out _)); + if (customCodec) + { + Assert.Same(codec, provider.GetCodec>()); + var buffer = new ArrayBufferWriter(); + using (var session = services.GetRequiredService().GetSession()) + { + var writer = Writer.Create(buffer, session); + ((ResponseCodec)provider.GetCodec(response.GetType())).WriteRaw(ref writer, response); + writer.Commit(); + } + using var readSession = services.GetRequiredService().GetSession(); + var reader = Reader.Create(buffer.WrittenMemory, readSession); + var field = reader.ReadFieldHeader(); + using var decoded = (Response)codec.ReadRaw(ref reader, ref field); + Assert.Equal(142, decoded.GetResult()); + Assert.Equal(1, counts.Writes); + Assert.Equal(1, counts.Reads); + } + else + { + Assert.Same(copier, provider.GetDeepCopier>()); + } + } + + private sealed class SubclassCounts + { + public int Writes; + public int Reads; + public int Copies; + } + + private sealed class CustomRawResponseCodec(TCodec codec, SubclassCounts counts) : PooledResponseCodec(codec) + where TCodec : class, IFieldCodec + { + public override void WriteRaw(ref Writer writer, object value) + { + counts.Writes++; + using var transformed = Response.FromResult(((Response)value).TypedResult + 100); + base.WriteRaw(ref writer, transformed); + } + public override object ReadRaw(ref Reader reader, scoped ref Field field) + { + counts.Reads++; + return base.ReadRaw(ref reader, ref field); + } + } + + private sealed class CustomResponseSubclassCopier(TCopier copier, SubclassCounts counts) + : PooledResponseCopier(copier), IDeepCopier> + where TCopier : class, IDeepCopier + { + [return: System.Diagnostics.CodeAnalysis.NotNullIfNotNull(nameof(input))] + public new Response? DeepCopy(Response? input, CopyContext context) + { + if (input is null) return null; + counts.Copies++; + return (Response)Response.FromResult(input.TypedResult + 1); + } + } + private sealed class DelegatingCodec(IFieldCodec codec) : IFieldCodec { public int Writes { get; private set; } From 4b8a52d4d4b46ea5aa2c4829802af33155093252 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Tue, 6 Oct 2026 17:16:23 -0700 Subject: [PATCH 50/54] perf(serialization): avoid allocating on published service lookups Read an initialized published serializer service before constructing another graph scope. Keep admission and fault checks, and isolate the allocating factory closure on the cold path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Serializers/CodecProvider.cs | 10 +++- .../DefaultFactoryDependencyAdmissionTests.cs | 59 +++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/src/Orleans.Serialization/Serializers/CodecProvider.cs b/src/Orleans.Serialization/Serializers/CodecProvider.cs index 3ed78a827f4..a0a9c84a671 100644 --- a/src/Orleans.Serialization/Serializers/CodecProvider.cs +++ b/src/Orleans.Serialization/Serializers/CodecProvider.cs @@ -777,10 +777,18 @@ internal bool TryGetSerializerService(Type type, [NotNullWhen(true)] out object? return true; } - result = ConstructService(type, () => factory(this)); + if ((_initialized || IsInitializationLockHeld) && TryGetCached(_serializerServices, type, out result)) + { + return true; + } + + result = ConstructRegisteredService(type, factory); return true; } + private object ConstructRegisteredService(Type type, Func factory) + => ConstructService(type, () => factory(this)); + private object ConstructService(Type type, Func create, bool beginGraph = true) { if (beginGraph && !_initialized && !IsInitializationLockHeld) diff --git a/test/Orleans.Serialization.UnitTests/DefaultFactoryDependencyAdmissionTests.cs b/test/Orleans.Serialization.UnitTests/DefaultFactoryDependencyAdmissionTests.cs index 3d10152589e..e33a8dd1cbc 100644 --- a/test/Orleans.Serialization.UnitTests/DefaultFactoryDependencyAdmissionTests.cs +++ b/test/Orleans.Serialization.UnitTests/DefaultFactoryDependencyAdmissionTests.cs @@ -137,6 +137,65 @@ void RegisterExplicit() => options.AddSerializerService>( static _ => throw new InvalidOperationException("Admission examines the declared dependency without constructing it.")); } + [Fact] + public void PublishedClosedService_ResolutionDoesNotAllocate() + { + var dependency = new Dependency(); + var factoryCalls = 0; + using var services = new ServiceCollection().AddSerializer(builder => builder.Configure(options => + { + options.AddSerializerService(_ => + { + factoryCalls++; + return dependency; + }); + })).BuildServiceProvider(); + var provider = services.GetRequiredService(); + for (var i = 0; i < 100; i++) + { + _ = OrleansGeneratedCodeHelper.GetService(null!, provider); + } + + Dependency? actual = null; + var allocatedBefore = GC.GetAllocatedBytesForCurrentThread(); + for (var i = 0; i < 1_000; i++) + { + actual = OrleansGeneratedCodeHelper.GetService(null!, provider); + } + var allocated = GC.GetAllocatedBytesForCurrentThread() - allocatedBefore; + + Assert.Same(dependency, actual); + Assert.Equal(1, factoryCalls); + Assert.Equal(0, allocated); + Assert.False(provider.IsConstructionPending); + } + + [Fact] + public void PublishedClosedService_ReadInsideFaultedGraphPreservesFailure() + { + var dependency = new Dependency(); + var failure = new InvalidOperationException("graph failed before reading a published service"); + using var services = new ServiceCollection().AddSerializer(builder => builder.Configure(options => + { + options.AddSerializerService(_ => dependency); + options.AddSerializerService(_ => throw failure); + options.AddSerializerService(provider => + { + Assert.Same(failure, Assert.Throws( + () => OrleansGeneratedCodeHelper.GetService(null!, provider))); + _ = OrleansGeneratedCodeHelper.GetService(null!, provider); + return new State(); + }); + })).BuildServiceProvider(); + var provider = services.GetRequiredService(); + Assert.Same(dependency, OrleansGeneratedCodeHelper.GetService(null!, provider)); + + Assert.Same(failure, Assert.Throws( + () => OrleansGeneratedCodeHelper.GetService(null!, provider))); + Assert.False(provider.IsConstructionPending); + Assert.Same(dependency, OrleansGeneratedCodeHelper.GetService(null!, provider)); + } + private static void RegisterDefaults(TypeManifestOptions options, State state) { options.AddSerializer(typeof(DependentCodec)); From 0eae5550001915771e75937545bf02b8f57c8fcb Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Tue, 6 Oct 2026 17:39:12 -0700 Subject: [PATCH 51/54] perf(serialization): reuse default admission traversal state Borrow a cleared, bounded per-thread visited set without caching admission decisions. Preserve provider-specific overrides and graph boundaries while removing 176 bytes from each warmed default-service lookup. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Serializers/CodecProvider.cs | 34 ++++++++++-- .../DefaultFactoryDependencyAdmissionTests.cs | 55 +++++++++++++++++++ 2 files changed, 84 insertions(+), 5 deletions(-) diff --git a/src/Orleans.Serialization/Serializers/CodecProvider.cs b/src/Orleans.Serialization/Serializers/CodecProvider.cs index a0a9c84a671..3dc28105d28 100644 --- a/src/Orleans.Serialization/Serializers/CodecProvider.cs +++ b/src/Orleans.Serialization/Serializers/CodecProvider.cs @@ -23,6 +23,7 @@ namespace Orleans.Serialization.Serializers public sealed class CodecProvider : ICodecProvider { private static readonly Type ObjectType = typeof(object); + private static readonly Invocation.ConcurrentObjectPool> DefaultAdmissionVisitedPool = new() { MaxPoolSize = 1 }; #if NET9_0_OR_GREATER private readonly Lock _initializationLock = new(); @@ -672,11 +673,34 @@ private object ActivateService(Type type, object[]? constructorArguments) // Inferred defaults preserve an automatic caller's DI boundary instead of starting a transaction inside it. private bool IsDefaultServiceEligible(Type service) - => !_manifest.IsDefaultSerializerService(service) - || (OrleansGeneratedCodeHelper.GetConstructionScope(this) is not { IsPending: false } - && IsDefaultImplementationEligible(service) - && (!_manifest.DefaultSerializerContracts.TryGetValue(service, out var contract) - || IsDefaultContractEligible(contract, []))); + { + if (!_manifest.IsDefaultSerializerService(service)) + { + return true; + } + + if (OrleansGeneratedCodeHelper.GetConstructionScope(this) is { IsPending: false } + || !IsDefaultImplementationEligible(service)) + { + return false; + } + + if (!_manifest.DefaultSerializerContracts.TryGetValue(service, out var contract)) + { + return true; + } + + var visited = DefaultAdmissionVisitedPool.Get(); + try + { + return IsDefaultContractEligible(contract, visited); + } + finally + { + visited.Clear(); + DefaultAdmissionVisitedPool.Return(visited); + } + } private bool IsDefaultImplementationEligible(Type implementation) { diff --git a/test/Orleans.Serialization.UnitTests/DefaultFactoryDependencyAdmissionTests.cs b/test/Orleans.Serialization.UnitTests/DefaultFactoryDependencyAdmissionTests.cs index e33a8dd1cbc..a17a639e9a2 100644 --- a/test/Orleans.Serialization.UnitTests/DefaultFactoryDependencyAdmissionTests.cs +++ b/test/Orleans.Serialization.UnitTests/DefaultFactoryDependencyAdmissionTests.cs @@ -196,6 +196,61 @@ public void PublishedClosedService_ReadInsideFaultedGraphPreservesFailure() Assert.Same(dependency, OrleansGeneratedCodeHelper.GetService(null!, provider)); } + [Fact] + public void PublishedDefaultService_AdmissionDoesNotAllocate() + { + var dependency = new Dependency(); + using var services = new ServiceCollection().AddSerializer(builder => builder.Configure(options => + { + options.AddDefaultSerializerService(_ => dependency); + })).BuildServiceProvider(); + var provider = services.GetRequiredService(); + for (var i = 0; i < 100; i++) + { + _ = OrleansGeneratedCodeHelper.GetService(null!, provider); + } + + Dependency? actual = null; + var allocatedBefore = GC.GetAllocatedBytesForCurrentThread(); + for (var i = 0; i < 1_000; i++) + { + actual = OrleansGeneratedCodeHelper.GetService(null!, provider); + } + var allocated = GC.GetAllocatedBytesForCurrentThread() - allocatedBefore; + + Assert.Same(dependency, actual); + Assert.Equal(0, allocated); + Assert.False(provider.IsConstructionPending); + } + + [Fact] + public void DefaultAdmission_VisitedTypesAreClearedBetweenProviders() + { + var dependency = new Dependency(); + var admitted = new State(); + using (var services = new ServiceCollection().AddSerializer(builder => builder.Configure(options => + { + options.AddSerializerService(_ => dependency); + RegisterDefaults(options, admitted); + })).BuildServiceProvider()) + { + var provider = services.GetRequiredService(); + Assert.Same(dependency, Assert.IsType(provider.GetCodec()).Dependency); + Assert.Equal(1, admitted.FactoryCalls); + } + + var declined = new State(); + using var otherServices = new ServiceCollection() + .AddSingleton(dependency) + .AddSerializer(builder => builder.Configure(options => RegisterDefaults(options, declined))) + .BuildServiceProvider(); + var otherProvider = otherServices.GetRequiredService(); + + Assert.Same(dependency, Assert.IsType(otherProvider.GetCodec()).Dependency); + Assert.Equal(0, declined.FactoryCalls); + Assert.False(otherProvider.IsConstructionPending); + } + private static void RegisterDefaults(TypeManifestOptions options, State state) { options.AddSerializer(typeof(DependentCodec)); From 1ff125c39775ebaf068525d427fd9dc4a9054df0 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Wed, 7 Oct 2026 13:18:18 -0700 Subject: [PATCH 52/54] perf(rpc): resolve response dependencies only during construction Retain provider-scoped transactional factory resolution and constructor compatibility checks instead of repeating four codec/copier lookups on every invocation. Cover cold initialization and retry, warmed zero-allocation resolution, overrides, canonical identities, rollback, fault propagation and NativeAOT publication. Regenerate both framework snapshots. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 2fd2ecd7-0e1d-4526-b715-71eff94612a5 --- .../docs/implementation/serialization.md | 2 + .../RpcResponseHolderGenerator.cs | 4 - .../OrleansSourceGeneratorTests.cs | 9 + ...ests.TestBasicGrain.DotNet10_0.verified.cs | 4 - ...Tests.TestBasicGrain.DotNet8_0.verified.cs | 4 - ...rializersAnnotation.DotNet10_0.verified.cs | 4 - ...erializersAnnotation.DotNet8_0.verified.cs | 4 - ...stGrainComplexGrain.DotNet10_0.verified.cs | 4 - ...estGrainComplexGrain.DotNet8_0.verified.cs | 4 - ...thInvokableBaseType.DotNet10_0.verified.cs | 4 - ...ithInvokableBaseType.DotNet8_0.verified.cs | 4 - ...WithResponseTimeout.DotNet10_0.verified.cs | 4 - ...dWithResponseTimeout.DotNet8_0.verified.cs | 4 - ...thDifferentKeyTypes.DotNet10_0.verified.cs | 16 -- ...ithDifferentKeyTypes.DotNet8_0.verified.cs | 16 -- ...hMultipleInterfaces.DotNet10_0.verified.cs | 4 - ...thMultipleInterfaces.DotNet8_0.verified.cs | 4 - .../RpcResponses.Contracts.cs | 41 +++- test/Orleans.NativeAotSmoke/RpcResponses.cs | 1 + .../RpcResponseTests.cs | 175 ++++++++++++++++++ 20 files changed, 225 insertions(+), 87 deletions(-) diff --git a/docs/site/src/content/docs/implementation/serialization.md b/docs/site/src/content/docs/implementation/serialization.md index d90761bf715..c191fabc483 100644 --- a/docs/site/src/content/docs/implementation/serialization.md +++ b/docs/site/src/content/docs/implementation/serialization.md @@ -139,6 +139,8 @@ Incoming filters receive an isolated result and can transform its envelope or ne Generated holders implement . The message serializer selects their direct writer before runtime-type codec lookup. Primitive holders call the existing static primitive codecs; reference holders use their bound concrete result codec and the message's serialization session. The wire representation retains the result-type header, field zero, end marker, null behavior, cycles, and shared references. Returning a holder to its pool clears both its result and its provider-owned factory binding. +The response factory constructor resolves and checks the selected result and response codecs and copiers. Subsequent invocations resolve the provider-owned factory through the existing transactional service cache without repeating those dependency lookups. Factory construction retains serializer initialization, recursive dependency resolution, and graph publication or rollback; a failed graph cannot publish a response factory. + Successful remote write completion releases each response envelope and clears the message's reference to it after recording the send. A transport-write failure retains the envelope for retry or rerouting. Terminal message disposal and body replacement release the owned envelope; serialization failure replaces it with an exception response or releases it on a terminal drop. On receipt, the callback transfers envelope ownership to . Typed completion extracts the result and releases the envelope, preserving the result payload for the caller. Untyped completion transfers a successful envelope to its awaiting consumer; void consumption releases it directly. Outgoing filters retain selected and superseded envelopes through their continuations, and the invocation releases them after extracting the final result or unwinding a failure. Application code calling `Complete` transfers ownership and leaves envelope disposal to the completion pipeline. diff --git a/src/Orleans.CodeGenerator/RpcResponseHolderGenerator.cs b/src/Orleans.CodeGenerator/RpcResponseHolderGenerator.cs index bcf6eaedba2..e744ff5805d 100644 --- a/src/Orleans.CodeGenerator/RpcResponseHolderGenerator.cs +++ b/src/Orleans.CodeGenerator/RpcResponseHolderGenerator.cs @@ -141,10 +141,6 @@ internal sealed class {{factory}} : global::Orleans.Serialization.Invocation.Res public override bool IsSupported { get; } internal static {{factory}} Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { - provider.GetCodec<{{type}}>(); - provider.GetDeepCopier<{{type}}>(); - provider.GetCodec>(); - provider.GetDeepCopier>(); return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService<{{factory}}>(null, provider); } public {{factory}}(global::Orleans.Serialization.Serializers.ICodecProvider provider) diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index 20f7efbe2de..27a32cce351 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -3678,6 +3678,15 @@ public interface IWriter : IGrainWithIntegerKey { {{returnType}} Get(); } .OfType().Where(static type => type.BaseList?.ToString().Contains("IRawResponseWriter", StringComparison.Ordinal) == true).ToArray(); var holder = Assert.Single(holders); Assert.Null(holder.TypeParameterList); + var factory = CSharpSyntaxTree.ParseText(response, cancellationToken: TestContext.Current.CancellationToken) + .GetCompilationUnitRoot(TestContext.Current.CancellationToken).DescendantNodes() + .OfType().Single(static type => type.Identifier.ValueText.EndsWith("Factory", StringComparison.Ordinal)); + var resolver = Assert.Single(factory.Members.OfType(), + static method => method.Identifier.ValueText == "Resolve"); + Assert.IsType(Assert.Single(resolver.Body!.Statements)); + var constructor = Assert.Single(factory.Members.OfType()); + Assert.Equal(4, constructor.DescendantNodes().OfType().Count( + static invocation => invocation.Expression is MemberAccessExpressionSyntax { Expression: IdentifierNameSyntax { Identifier.ValueText: "provider" } })); var output = compilation.AddReferences(MetadataReference.CreateFromFile(typeof(Microsoft.Extensions.Options.IConfigureOptions<>).Assembly.Location)) .AddSyntaxTrees(result.GeneratedSources.Select(static item => CSharpSyntaxTree.ParseText(item.SourceText, options: new CSharpParseOptions().WithPreprocessorSymbols("NET5_0_OR_GREATER"), path: item.HintName))); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs index a60d7a57013..d65055da134 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs @@ -387,10 +387,6 @@ internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serializatio internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { - provider.GetCodec(); - provider.GetDeepCopier(); - provider.GetCodec>(); - provider.GetDeepCopier>(); return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs index fe10ac95101..fd1d2dc9ee5 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs @@ -388,10 +388,6 @@ internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serializatio internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { - provider.GetCodec(); - provider.GetDeepCopier(); - provider.GetCodec>(); - provider.GetDeepCopier>(); return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs index 91e813b5c6b..364bef45f5f 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs @@ -295,10 +295,6 @@ internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serializatio internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { - provider.GetCodec(); - provider.GetDeepCopier(); - provider.GetCodec>(); - provider.GetDeepCopier>(); return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs index bcd21d09769..30d5ab98303 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs @@ -296,10 +296,6 @@ internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serializatio internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { - provider.GetCodec(); - provider.GetDeepCopier(); - provider.GetCodec>(); - provider.GetDeepCopier>(); return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs index 4876eaf9179..17e95187ee4 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs @@ -587,10 +587,6 @@ internal sealed class RpcResponse_FC7DD5BDFactory : global::Orleans.Serializatio internal static RpcResponse_FC7DD5BDFactory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { - provider.GetCodec(); - provider.GetDeepCopier(); - provider.GetCodec>(); - provider.GetDeepCopier>(); return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs index 6d53463b850..0a7a68f45a9 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs @@ -587,10 +587,6 @@ internal sealed class RpcResponse_FC7DD5BDFactory : global::Orleans.Serializatio internal static RpcResponse_FC7DD5BDFactory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { - provider.GetCodec(); - provider.GetDeepCopier(); - provider.GetCodec>(); - provider.GetDeepCopier>(); return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs index 4c3c2139018..a407ca52dcc 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs @@ -392,10 +392,6 @@ internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serializatio internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { - provider.GetCodec(); - provider.GetDeepCopier(); - provider.GetCodec>(); - provider.GetDeepCopier>(); return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs index 8980c0a018e..3b480a34576 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs @@ -393,10 +393,6 @@ internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serializatio internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { - provider.GetCodec(); - provider.GetDeepCopier(); - provider.GetCodec>(); - provider.GetDeepCopier>(); return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs index 409081c13f3..9c7077c2876 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs @@ -294,10 +294,6 @@ internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serializatio internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { - provider.GetCodec(); - provider.GetDeepCopier(); - provider.GetCodec>(); - provider.GetDeepCopier>(); return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs index 69ba2592892..4c7e7dbc2a5 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs @@ -295,10 +295,6 @@ internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serializatio internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { - provider.GetCodec(); - provider.GetDeepCopier(); - provider.GetCodec>(); - provider.GetDeepCopier>(); return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs index 4a39f414383..2f120a0df68 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs @@ -1008,10 +1008,6 @@ internal sealed class RpcResponse_5C3A711CFactory : global::Orleans.Serializatio internal static RpcResponse_5C3A711CFactory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { - provider.GetCodec(); - provider.GetDeepCopier(); - provider.GetCodec>(); - provider.GetDeepCopier>(); return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); } @@ -1141,10 +1137,6 @@ internal sealed class RpcResponse_6A3EE8F4Factory : global::Orleans.Serializatio internal static RpcResponse_6A3EE8F4Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { - provider.GetCodec>(); - provider.GetDeepCopier>(); - provider.GetCodec>>(); - provider.GetDeepCopier>>(); return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); } @@ -1282,10 +1274,6 @@ internal sealed class RpcResponse_AFB713E4Factory : global::Orleans.Serializatio internal static RpcResponse_AFB713E4Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { - provider.GetCodec>(); - provider.GetDeepCopier>(); - provider.GetCodec>>(); - provider.GetDeepCopier>>(); return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); } @@ -1429,10 +1417,6 @@ internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serializatio internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { - provider.GetCodec(); - provider.GetDeepCopier(); - provider.GetCodec>(); - provider.GetDeepCopier>(); return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs index eef0f6d5d4f..8a7f0ec4943 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs @@ -1009,10 +1009,6 @@ internal sealed class RpcResponse_5C3A711CFactory : global::Orleans.Serializatio internal static RpcResponse_5C3A711CFactory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { - provider.GetCodec(); - provider.GetDeepCopier(); - provider.GetCodec>(); - provider.GetDeepCopier>(); return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); } @@ -1143,10 +1139,6 @@ internal sealed class RpcResponse_6A3EE8F4Factory : global::Orleans.Serializatio internal static RpcResponse_6A3EE8F4Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { - provider.GetCodec>(); - provider.GetDeepCopier>(); - provider.GetCodec>>(); - provider.GetDeepCopier>>(); return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); } @@ -1285,10 +1277,6 @@ internal sealed class RpcResponse_AFB713E4Factory : global::Orleans.Serializatio internal static RpcResponse_AFB713E4Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { - provider.GetCodec>(); - provider.GetDeepCopier>(); - provider.GetCodec>>(); - provider.GetDeepCopier>>(); return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); } @@ -1433,10 +1421,6 @@ internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serializatio internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { - provider.GetCodec(); - provider.GetDeepCopier(); - provider.GetCodec>(); - provider.GetDeepCopier>(); return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs index 12a080ccbcf..bf846fa59f0 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs @@ -452,10 +452,6 @@ internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serializatio internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { - provider.GetCodec(); - provider.GetDeepCopier(); - provider.GetCodec>(); - provider.GetDeepCopier>(); return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); } diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs index 0515cd36f85..3762b49dadb 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs @@ -453,10 +453,6 @@ internal sealed class RpcResponse_9146C7E3Factory : global::Orleans.Serializatio internal static RpcResponse_9146C7E3Factory Resolve(global::Orleans.Serialization.Serializers.ICodecProvider provider) { - provider.GetCodec(); - provider.GetDeepCopier(); - provider.GetCodec>(); - provider.GetDeepCopier>(); return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService(null, provider); } diff --git a/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs b/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs index 0c01e10ce08..463c651fb21 100644 --- a/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs +++ b/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs @@ -6,6 +6,8 @@ using Orleans.Serialization.Buffers; using Orleans.Serialization.Cloning; using Orleans.Serialization.Codecs; +using Orleans.Serialization.Configuration; +using Orleans.Serialization.GeneratedCodeHelpers; using Orleans.Serialization.Invocation; using Orleans.Serialization.Serializers; using Orleans.Serialization.Session; @@ -14,6 +16,37 @@ namespace Orleans.NativeAotSmoke; public static class RpcResponseContracts { + public static void GeneratedFactoryPublication() + { + IRawResponseReader? unpublished = null; + var failure = new InvalidOperationException("response construction failed"); + using var services = CreateServices(options => options.AddSerializerService(provider => + { + Ensure(((CodecProvider)provider).TryGetRawResponseReader(typeof(int), out unpublished), + "A response factory resolves inside the construction graph."); + throw failure; + })); + var provider = services.GetRequiredService(); + try + { + OrleansGeneratedCodeHelper.GetService(null!, provider); + throw new InvalidOperationException("The construction failure must propagate."); + } + catch (InvalidOperationException exception) when (ReferenceEquals(exception, failure)) + { + } + Ensure(unpublished is not null, "The failed graph constructed its response factory."); + Ensure(provider.TryGetRawResponseReader(typeof(int), out var published), "A response factory resolves after rollback."); + Ensure(!ReferenceEquals(unpublished, published), "A failed graph must not publish its response factory."); + Ensure(provider.TryGetRawResponseReader(typeof(int), out var repeated) + && ReferenceEquals(published, repeated), "Successful construction publishes a canonical provider-owned response factory."); + using var other = CreateServices(); + Ensure(other.GetRequiredService().TryGetRawResponseReader(typeof(int), out var isolated) + && !ReferenceEquals(published, isolated), "Response factories retain their provider isolation."); + } + + private sealed class PublicationRoot; + public static async System.Threading.Tasks.Task GeneratedInvokablesWriteCopiedResponses() { #if NATIVE_AOT_SMOKE @@ -292,13 +325,15 @@ static void Check(Action lookup) } #endif - private static ServiceProvider CreateServices() + private static ServiceProvider CreateServices(Action? configure = null) { #if NATIVE_AOT_SMOKE - return new ServiceCollection().AddSerializerContext(new global::OrleansCodeGen.OrleansNativeAotSmoke.RpcResponseFactories()).BuildServiceProvider(); + var collection = new ServiceCollection().AddSerializerContext(new global::OrleansCodeGen.OrleansNativeAotSmoke.RpcResponseFactories()); #else - return new ServiceCollection().AddSerializer(builder => builder.AddAssembly(typeof(IRpcResponses).Assembly)).BuildServiceProvider(); + var collection = new ServiceCollection().AddSerializer(builder => builder.AddAssembly(typeof(IRpcResponses).Assembly)); #endif + if (configure is not null) collection.Configure(configure); + return collection.BuildServiceProvider(); } private static Response Copy(ServiceProvider services, Response response) diff --git a/test/Orleans.NativeAotSmoke/RpcResponses.cs b/test/Orleans.NativeAotSmoke/RpcResponses.cs index 0e7553caeff..ba2b6de962d 100644 --- a/test/Orleans.NativeAotSmoke/RpcResponses.cs +++ b/test/Orleans.NativeAotSmoke/RpcResponses.cs @@ -2,6 +2,7 @@ using Orleans.NativeAotSmoke; RpcResponseContracts.PrimitiveResponses(); +RpcResponseContracts.GeneratedFactoryPublication(); await RpcResponseContracts.GeneratedInvokablesWriteCopiedResponses(); RpcResponseContracts.CanonicalValueAndArrayServices(); RpcResponseContracts.ConstructTupleArgumentProxyBeforeInvocation(); diff --git a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs index 56b45437bf6..79728cb5721 100644 --- a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs +++ b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs @@ -101,6 +101,10 @@ public void ConcreteResponseFactoriesValidateResultDependencies() public void GeneratedResponseFactoriesCopyAndSerializePrimitiveResults() => NativeAotSmoke.RpcResponseContracts.PrimitiveResponses(); + [Fact] + public void GeneratedResponseFactoriesPreserveNativePublicationContracts() + => NativeAotSmoke.RpcResponseContracts.GeneratedFactoryPublication(); + [Fact] public void GeneratedResponseFactoriesPreserveReferencePayloadCycles() => NativeAotSmoke.RpcResponseContracts.ReferenceResponsePreservesCycles(); @@ -596,6 +600,177 @@ private static IInvokable CreateInvokable(string methodName) return result; } + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task GeneratedResponseFactoryResolvesDependenciesOnlyDuringConstruction(bool readerFirst) + { + var options = _services.GetRequiredService>().Value; + var resultCodec = options.CodecFactories[typeof(int)]; + var resultCopier = options.CopierFactories[typeof(int)]; + var responseCodec = options.CodecFactories[typeof(Response)]; + var responseCopier = options.CopierFactories[typeof(Response)]; + var codecCalls = 0; + var copierCalls = 0; + var responseCodecCalls = 0; + var responseCopierCalls = 0; + options.CodecFactories[typeof(int)] = resultCodec with + { + Factory = provider => { codecCalls++; return resultCodec.Factory(provider); } + }; + options.CopierFactories[typeof(int)] = resultCopier with + { + Factory = provider => { copierCalls++; return resultCopier.Factory(provider); } + }; + options.CodecFactories[typeof(Response)] = responseCodec with + { + Factory = provider => { responseCodecCalls++; return responseCodec.Factory(provider); } + }; + options.CopierFactories[typeof(Response)] = responseCopier with + { + Factory = provider => { responseCopierCalls++; return responseCopier.Factory(provider); } + }; + + var provider = _services.GetRequiredService(); + var contexts = _services.GetRequiredService(); + var copier = _services.GetRequiredService().GetCopier(); + if (readerFirst) Assert.True(provider.TryGetRawResponseReader(typeof(int), out _)); + using var invokable = CreateInvokable("Integer"); + invokable.SetTarget(new TargetHolder(new RpcResponseTarget())); + using var response = await invokable.InvokeAndCopy(provider, contexts, copier); + Assert.IsAssignableFrom(response); + Assert.Equal(42, response.GetResult()); + Assert.True(provider.TryGetRawResponseReader(typeof(int), out var reader)); + for (var i = 0; i < 100; i++) provider.TryGetRawResponseReader(typeof(int), out _); + + IRawResponseReader? actual = null; + var allocatedBefore = GC.GetAllocatedBytesForCurrentThread(); + for (var i = 0; i < 1_000; i++) provider.TryGetRawResponseReader(typeof(int), out actual); + var allocated = GC.GetAllocatedBytesForCurrentThread() - allocatedBefore; + + Assert.Same(reader, actual); + Assert.Equal(1, codecCalls); + Assert.Equal(1, copierCalls); + Assert.Equal(1, responseCodecCalls); + Assert.Equal(1, responseCopierCalls); + Assert.Equal(0, allocated); + Assert.False(provider.IsConstructionPending); + } + + [Fact] + public void GeneratedResponseFactoryInitializesBeforeBeginningItsGraphAndRetriesInitializationFailure() + { + var initializationCalls = 0; + var failure = new InvalidOperationException("serializer initialization failed"); + using var services = new ServiceCollection().AddSerializer() + .AddSingleton(services => + { + initializationCalls++; + Assert.False(services.GetRequiredService().IsConstructionPending); + if (initializationCalls == 1) throw failure; + return new InitializationCodec(); + }).BuildServiceProvider(); + var provider = services.GetRequiredService(); + + Assert.Same(failure, Assert.Throws( + () => provider.TryGetRawResponseReader(typeof(int), out _))); + Assert.False(provider.IsConstructionPending); + Assert.True(provider.TryGetRawResponseReader(typeof(int), out var reader)); + Assert.Equal(2, initializationCalls); + Assert.True(provider.TryGetRawResponseReader(typeof(int), out var repeated)); + Assert.Same(reader, repeated); + Assert.Equal(2, initializationCalls); + } + + [Fact] + public void GeneratedResponseFactoryRollsBackWithItsConstructionGraph() + { + IRawResponseReader? unpublished = null; + var failure = new InvalidOperationException("response graph failed"); + using var services = new ServiceCollection().AddSerializer(builder => builder.Configure(options => + options.AddSerializerService(provider => + { + Assert.True(((CodecProvider)provider).TryGetRawResponseReader(typeof(int), out unpublished)); + throw failure; + }))).BuildServiceProvider(); + var provider = services.GetRequiredService(); + + Assert.Same(failure, Assert.Throws( + () => OrleansGeneratedCodeHelper.GetService(null!, provider))); + Assert.NotNull(unpublished); + Assert.False(provider.IsConstructionPending); + Assert.True(provider.TryGetRawResponseReader(typeof(int), out var published)); + Assert.NotSame(unpublished, published); + Assert.True(provider.TryGetRawResponseReader(typeof(int), out var repeated)); + Assert.Same(published, repeated); + } + + [Fact] + public void PublishedGeneratedResponseFactoryPropagatesPendingGraphFailure() + { + var failure = new InvalidOperationException("response graph already faulted"); + using var services = new ServiceCollection().AddSerializer(builder => builder.Configure(options => + { + options.AddSerializerService(_ => throw failure); + options.AddSerializerService(provider => + { + Assert.Same(failure, Assert.Throws(() => + OrleansGeneratedCodeHelper.GetService(null!, provider))); + ((CodecProvider)provider).TryGetRawResponseReader(typeof(int), out _); + return new ResponseFactoryRoot(); + }); + })).BuildServiceProvider(); + var provider = services.GetRequiredService(); + Assert.True(provider.TryGetRawResponseReader(typeof(int), out var published)); + + Assert.Same(failure, Assert.Throws( + () => OrleansGeneratedCodeHelper.GetService(null!, provider))); + Assert.False(provider.IsConstructionPending); + Assert.True(provider.TryGetRawResponseReader(typeof(int), out var repeated)); + Assert.Same(published, repeated); + } + + [Fact] + public async Task GeneratedResponseFactoryKeepsProviderSpecificOverridesWhenInvokableIsReused() + { + var payloadCopier = new TransformingIntCopier(); + using var overridden = new ServiceCollection().AddSerializer(builder => builder.Configure(options => + options.AddSerializer(static _ => new Int32Codec(), _ => payloadCopier))).BuildServiceProvider(); + using var invokable = CreateInvokable("Integer"); + invokable.SetTarget(new TargetHolder(new RpcResponseTarget())); + var provider = _services.GetRequiredService(); + Assert.True(provider.TryGetRawResponseReader(typeof(int), out var originalReader)); + + for (var i = 0; i < 6; i++) + { + var selected = i % 2 == 0 ? _services : overridden; + var selectedProvider = selected.GetRequiredService(); + using var response = await invokable.InvokeAndCopy( + selectedProvider, selected.GetRequiredService(), + selected.GetRequiredService().GetCopier()); + Assert.Null(response.Exception); + Assert.Equal(i % 2 == 0 ? 42 : 43, response.GetResult()); + Assert.Equal(i % 2 == 0, response is IRawResponseWriter); + } + + Assert.Equal(3, payloadCopier.Copies); + Assert.False(overridden.GetRequiredService().TryGetRawResponseReader(typeof(int), out _)); + Assert.True(provider.TryGetRawResponseReader(typeof(int), out var repeated)); + Assert.Same(originalReader, repeated); + } + + private sealed class ResponseFactoryRoot; + private sealed class FailedResponseFactoryRoot; + + private sealed class InitializationCodec : IGeneralizedCodec + { + public bool IsSupportedType(Type type) => false; + public void WriteField(ref Writer writer, uint fieldIdDelta, + [System.Diagnostics.CodeAnalysis.AllowNull] Type expectedType, object? value) + where TBufferWriter : IBufferWriter => throw new NotSupportedException(); + public object? ReadValue(ref Reader reader, Field field) => throw new NotSupportedException(); + } + [Theory] [InlineData("Boolean")] [InlineData("Integer")] From e139213e520b8071d4e01a69b2fbf02254d54cfa Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Wed, 7 Oct 2026 20:51:48 -0700 Subject: [PATCH 53/54] refactor(rpc): streamline generated invocation and response pooling Use a shared InvocationContext with generated synchronous completion and concrete async slow paths. Centralize compatibility adaptation in non-generic code, remove delegate-based response release dispatch, and unify pools by envelope type. Preserve construction-only dependency resolution, service precedence, exception timing and consuming ownership. --- .../docs/implementation/serialization.md | 8 +- .../InvokableGenerator.cs | 39 +- src/Orleans.Core/Core/GrainMethodInvoker.cs | 21 +- .../Runtime/InvokableObjectManager.cs | 18 +- .../Core/InsideRuntimeClient.cs | 18 +- .../OrleansGeneratedCodeHelper.cs | 25 +- .../Invocation/IInvokable.cs | 32 +- .../Invocation/InvocationContext.cs | 86 +++ .../Invocation/Pools/ResponsePool.cs | 17 +- src/api/Orleans.Core/Orleans.Core.cs | 26 +- .../Orleans.Serialization.cs | 15 +- .../Orleans.Streaming/Orleans.Streaming.cs | 4 +- .../Orleans.Transactions.TestKit.Base.cs | 2 +- .../OrleansSourceGeneratorTests.cs | 21 +- .../RpcResponseHolderNamingTests.cs | 5 +- ...ests.TestBasicGrain.DotNet10_0.verified.cs | 27 +- ...Tests.TestBasicGrain.DotNet8_0.verified.cs | 27 +- ...rializersAnnotation.DotNet10_0.verified.cs | 27 +- ...erializersAnnotation.DotNet8_0.verified.cs | 27 +- ...stGrainComplexGrain.DotNet10_0.verified.cs | 27 +- ...estGrainComplexGrain.DotNet8_0.verified.cs | 27 +- ...thInvokableBaseType.DotNet10_0.verified.cs | 27 +- ...ithInvokableBaseType.DotNet8_0.verified.cs | 27 +- ...WithResponseTimeout.DotNet10_0.verified.cs | 27 +- ...dWithResponseTimeout.DotNet8_0.verified.cs | 27 +- ...thDifferentKeyTypes.DotNet10_0.verified.cs | 108 ++-- ...ithDifferentKeyTypes.DotNet8_0.verified.cs | 108 ++-- ...hMultipleInterfaces.DotNet10_0.verified.cs | 54 +- ...thMultipleInterfaces.DotNet8_0.verified.cs | 54 +- .../SelfWritingResponseFilterTests.cs | 11 +- .../SelfWritingResponseOwnershipTests.cs | 12 +- .../RpcResponses.Contracts.cs | 42 +- .../InvocationContextTests.cs | 539 ++++++++++++++++++ .../RpcResponseTests.cs | 40 +- 34 files changed, 1215 insertions(+), 360 deletions(-) create mode 100644 src/Orleans.Serialization/Invocation/InvocationContext.cs create mode 100644 test/Orleans.Serialization.UnitTests/InvocationContextTests.cs diff --git a/docs/site/src/content/docs/implementation/serialization.md b/docs/site/src/content/docs/implementation/serialization.md index c191fabc483..ff90e28729f 100644 --- a/docs/site/src/content/docs/implementation/serialization.md +++ b/docs/site/src/content/docs/implementation/serialization.md @@ -133,11 +133,11 @@ Arguments and result values use normal Orleans.Serialization codecs and copiers. ### Closed RPC response factories -The runtime invokes in the ordinary, incoming-filter, and observer paths. Its default implementation copies successful responses using the selected response copier. For supported non-generic methods using the built-in task and value-task request bases, generated implementations bind the selected serialization dependencies and rent a concrete, non-generic response holder after copying a mutable result. Immutable results retain their existing copy semantics. Isolation completes before incoming filters resume, and the generated path creates one pooled envelope for the successful result. Exception envelopes retain the original exception through filters and are copied at delivery for every invocation. +The runtime invokes with a shared, provider-owned in the ordinary, incoming-filter, and observer paths. Its default implementation copies successful responses using the context's selected response copier. For supported non-generic methods using the built-in task and value-task request bases, generated implementations bind the selected serialization dependencies and rent a concrete, non-generic response holder after copying a mutable result. Completed tasks and value tasks consume their result directly; pending operations use a separate asynchronous completion method. Immutable results retain their existing copy semantics. Isolation completes before incoming filters resume, and the generated path creates one pooled envelope for the successful result. Exception envelopes retain the original exception through filters and are copied at delivery for every invocation. -Incoming filters receive an isolated result and can transform its envelope or nested payload references. The invocation context retains each superseded response until completion, allowing filters to restore an earlier selection and releasing every unselected wrapper exactly once. After the filter chain completes, the runtime copies the selected result for delivery, preserving isolation for both local callers and deferred message serialization. Calls with no incoming filters transfer their invocation-time copy directly to the messaging pipeline. Expired and one-way requests release their owned response without an outgoing copy. +Incoming filters receive an isolated result and can transform its envelope or nested payload references. The call-filter invoker retains each superseded response until completion, allowing filters to restore an earlier selection and releasing every unselected wrapper exactly once. After the filter chain completes, the runtime copies the selected result for delivery, preserving isolation for both local callers and deferred message serialization. Calls with no incoming filters transfer their invocation-time copy directly to the messaging pipeline. Expired and one-way requests release their owned response without an outgoing copy. -Generated holders implement . The message serializer selects their direct writer before runtime-type codec lookup. Primitive holders call the existing static primitive codecs; reference holders use their bound concrete result codec and the message's serialization session. The wire representation retains the result-type header, field zero, end marker, null behavior, cycles, and shared references. Returning a holder to its pool clears both its result and its provider-owned factory binding. +Generated holders implement . The message serializer selects their direct writer before runtime-type codec lookup. Primitive holders call the existing static primitive codecs; reference holders use their bound concrete result codec and the message's serialization session. The wire representation retains the result-type header, field zero, end marker, null behavior, cycles, and shared references. Generated and compatibility responses share the pool implementation keyed by their concrete envelope type. Returning a generated holder to its pool clears both its result and its provider-owned factory binding. The response factory constructor resolves and checks the selected result and response codecs and copiers. Subsequent invocations resolve the provider-owned factory through the existing transactional service cache without repeating those dependency lookups. Factory construction retains serializer initialization, recursive dependency resolution, and graph publication or rollback; a failed graph cannot publish a response factory. @@ -157,7 +157,7 @@ The finite response graph supplies successful typed results and completed-respon The generator prepares one response plan for holder naming, graph admission, and factory emission. Complete, partial, and referenced graphs share constructor-service descriptions and a registration emitter, so each dependency edge identifies the service consumed by its factory. Generated graphs register closed generic-argument metadata through . Candidate selection validates bound generic constraints before choosing an implementation, using the same validation for inferred defaults and ordinary lookup. Managed lookup retains runtime constraint validation for application-selected types whose metadata is supplied at runtime. -Generated invocation fallbacks and runtime delivery boundaries share envelope copy-and-dispose ownership logic. The selected copier retains its typed or runtime-type dispatch behavior, including immutable exception envelopes and custom copiers that return their input. Raw response transport resolves one reader per result type; adapts compatibility codecs to , and supported generated readers retain precedence. +Generated invocation fallbacks and runtime delivery boundaries share non-generic envelope copy-and-dispose ownership logic. The selected copier retains its typed or runtime-type dispatch behavior, including immutable exception envelopes and custom copiers that return their input. Raw response transport resolves one reader per result type; adapts compatibility codecs to , and supported generated readers retain precedence. These supplemental registrations are emitted unconditionally and are defaults: explicit closed factory registrations take precedence in either configuration order. Inferred parent factories preserve each child's selected service: replacing a child contract selects parent construction through that contract, while parents consuming the explicit contract directly remain eligible. This applies throughout the dependency graph, including concrete canonical services and their codec, copier, and activator aliases. Generated factories and registered metadata use one resolution pipeline, with closed services selected first. Direct-holder factories and raw-reader registrations bind the selected provider implementations in both JIT and native execution. Custom application codec/copier selection uses the compatibility invocation and serialization path. diff --git a/src/Orleans.CodeGenerator/InvokableGenerator.cs b/src/Orleans.CodeGenerator/InvokableGenerator.cs index 90f6413bc62..5035e3679dd 100644 --- a/src/Orleans.CodeGenerator/InvokableGenerator.cs +++ b/src/Orleans.CodeGenerator/InvokableGenerator.cs @@ -1,8 +1,8 @@ -using Orleans.CodeGenerator.SyntaxGeneration; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Orleans.CodeGenerator.Diagnostics; +using Orleans.CodeGenerator.SyntaxGeneration; using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; namespace Orleans.CodeGenerator; @@ -160,25 +160,38 @@ private ClassDeclarationSyntax GetClassDeclarationSyntax( result.TypeArguments[0].ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat), out var responseName)) { var type = result.TypeArguments[0].ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); + var returnType = method.Method.ReturnType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); var factory = $"global::{RpcResponseHolderGenerator.GetNamespace(_generationContext.Compilation)}.{responseName}Factory"; classDeclaration = classDeclaration.AddBaseListTypes(SimpleBaseType(ParseTypeName("global::Orleans.Serialization.Invocation.IInvokable"))); classDeclaration = classDeclaration.AddMembers(ParseMemberDeclaration($$""" - async global::System.Threading.Tasks.ValueTask - global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy( - global::Orleans.Serialization.Serializers.ICodecProvider provider, - global::Orleans.Serialization.Cloning.CopyContextPool contexts, - global::Orleans.Serialization.DeepCopier responseCopier) + global::System.Threading.Tasks.ValueTask + global::Orleans.Serialization.Invocation.IInvokable.Invoke( + global::Orleans.Serialization.Invocation.InvocationContext context) { try { - var factory = {{factory}}.Resolve(provider); + var factory = {{factory}}.Resolve(context.CodecProvider); if (!factory.IsSupported) - { - var original = await Invoke(); - if (original.Exception is not null) return original; - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); - } - {{type}} value = await InvokeInner(); + return context.InvokeCompatibility(this); + var resultTask = InvokeInner(); + if (resultTask.IsCompleted) + return new(factory.RentCopied(resultTask.GetAwaiter().GetResult(), context.CopyContextPool)); + return CompleteInvokeAsync(resultTask, factory, context.CopyContextPool); + } + catch (global::System.Exception exception) + { + return new(global::Orleans.Serialization.Invocation.Response.FromException(exception)); + } + } + """)!, + ParseMemberDeclaration($$""" + private static async global::System.Threading.Tasks.ValueTask + CompleteInvokeAsync({{returnType}} resultTask, {{factory}} factory, + global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + try + { + {{type}} value = await resultTask; return factory.RentCopied(value, contexts); } catch (global::System.Exception exception) diff --git a/src/Orleans.Core/Core/GrainMethodInvoker.cs b/src/Orleans.Core/Core/GrainMethodInvoker.cs index 54f7257b97f..33512011375 100644 --- a/src/Orleans.Core/Core/GrainMethodInvoker.cs +++ b/src/Orleans.Core/Core/GrainMethodInvoker.cs @@ -4,10 +4,7 @@ using System.Reflection; using System.Runtime.ExceptionServices; using System.Threading.Tasks; -using Orleans.Serialization; using Orleans.Serialization.Invocation; -using Orleans.Serialization.Cloning; -using Orleans.Serialization.Serializers; namespace Orleans.Runtime { @@ -19,10 +16,8 @@ internal sealed class GrainMethodInvoker : GrainCallInvoker, IIncomingGrainCallC private readonly Message message; private readonly List filters; private readonly InterfaceToImplementationMappingCache interfaceToImplementationMapping; - private readonly DeepCopier responseCopier; private readonly IGrainContext grainContext; - private readonly ICodecProvider codecProvider; - private readonly CopyContextPool copyContexts; + private readonly InvocationContext invocationContext; /// /// Initializes a new instance of the class. @@ -32,26 +27,20 @@ internal sealed class GrainMethodInvoker : GrainCallInvoker, IIncomingGrainCallC /// The request. /// The invocation interceptors. /// The implementation map. - /// The response copier. - /// The provider for generated response dependencies. - /// The pool for isolating source-known invocation results. + /// The provider-owned services used to isolate invocation results. public GrainMethodInvoker( Message message, IGrainContext grainContext, IInvokable request, List filters, InterfaceToImplementationMappingCache interfaceToImplementationMapping, - DeepCopier responseCopier, - ICodecProvider codecProvider, - CopyContextPool copyContexts) : base(request) + InvocationContext invocationContext) : base(request) { this.message = message; this.grainContext = grainContext; this.filters = filters; this.interfaceToImplementationMapping = interfaceToImplementationMapping; - this.responseCopier = responseCopier; - this.codecProvider = codecProvider; - this.copyContexts = copyContexts; + this.invocationContext = invocationContext; } public override object Grain => grainContext.GrainInstance!; @@ -87,7 +76,7 @@ protected override string GetFilterName(int index) => index < filters.Count protected override async Task InvokeInner() { - Response = await Request.InvokeAndCopy(codecProvider, copyContexts, responseCopier); + Response = await Request.Invoke(invocationContext); if (Response.Exception is { } exception) ExceptionDispatchInfo.Capture(exception).Throw(); } diff --git a/src/Orleans.Core/Runtime/InvokableObjectManager.cs b/src/Orleans.Core/Runtime/InvokableObjectManager.cs index 1a0d7c3dfac..835b64efca3 100644 --- a/src/Orleans.Core/Runtime/InvokableObjectManager.cs +++ b/src/Orleans.Core/Runtime/InvokableObjectManager.cs @@ -10,8 +10,10 @@ using Orleans.Internal; using Orleans.Runtime; using Orleans.Serialization; -using Orleans.Serialization.Invocation; +using Orleans.Serialization.Cloning; using Orleans.Serialization.GeneratedCodeHelpers; +using Orleans.Serialization.Invocation; +using Orleans.Serialization.Serializers; namespace Orleans { @@ -24,7 +26,7 @@ internal sealed partial class InvokableObjectManager private readonly IRuntimeClient runtimeClient; private readonly ILogger logger; private readonly DeepCopier deepCopier; - private readonly DeepCopier _responseCopier; + private readonly InvocationContext _invocationContext; private readonly MessagingTrace messagingTrace; private readonly AdmissionGate _invocations = new(); private readonly AdmissionGate _cancellations = new(); @@ -46,7 +48,10 @@ public InvokableObjectManager( this.runtimeClient = runtimeClient; this.deepCopier = deepCopier; this.messagingTrace = messagingTrace; - _responseCopier = responseCopier; + _invocationContext = new( + runtimeClient.ServiceProvider.GetRequiredService(), + runtimeClient.ServiceProvider.GetRequiredService(), + responseCopier); _interfaceToImplementationMapping = interfaceToImplementationMapping; this.logger = logger; } @@ -388,8 +393,7 @@ private async Task ProcessMessageAsync(Message message) if (filters is { Count: > 0 } || LocalObject is IIncomingGrainCallFilter) { using var invoker = new GrainMethodInvoker(message, this, request, filters, _manager._interfaceToImplementationMapping, - _manager._responseCopier, _manager.runtimeClient.ServiceProvider.GetRequiredService(), - _manager.runtimeClient.ServiceProvider.GetRequiredService()); + _manager._invocationContext); await invoker.Invoke(); response = invoker.TakeResponse(); // Filters can introduce grain-owned references anywhere in the result graph. @@ -397,9 +401,7 @@ private async Task ProcessMessageAsync(Message message) } else { - response = await request.InvokeAndCopy( - _manager.runtimeClient.ServiceProvider.GetRequiredService(), - _manager.runtimeClient.ServiceProvider.GetRequiredService(), _manager._responseCopier); + response = await request.Invoke(_manager._invocationContext); isCopied = response.Exception is null; } diff --git a/src/Orleans.Runtime/Core/InsideRuntimeClient.cs b/src/Orleans.Runtime/Core/InsideRuntimeClient.cs index ccdd1a11888..d26b5ae7459 100644 --- a/src/Orleans.Runtime/Core/InsideRuntimeClient.cs +++ b/src/Orleans.Runtime/Core/InsideRuntimeClient.cs @@ -16,9 +16,9 @@ using Orleans.Runtime.GrainDirectory; using Orleans.Runtime.Messaging; using Orleans.Serialization; -using Orleans.Serialization.Invocation; using Orleans.Serialization.Cloning; using Orleans.Serialization.GeneratedCodeHelpers; +using Orleans.Serialization.Invocation; using Orleans.Serialization.Serializers; using Orleans.Storage; using static Orleans.Internal.StandardExtensions; @@ -54,9 +54,7 @@ internal sealed partial class InsideRuntimeClient : IRuntimeClient, ILifecyclePa private IGrainReferenceRuntime grainReferenceRuntime = null!; private Task? callbackTimerTask; private readonly MessagingTrace messagingTrace; - private readonly DeepCopier responseCopier; - private readonly ICodecProvider responseCodecProvider; - private readonly CopyContextPool responseCopyContexts; + private readonly InvocationContext invocationContext; public InsideRuntimeClient( ILocalSiloDetails siloDetails, @@ -87,9 +85,10 @@ public InsideRuntimeClient( this.loggerFactory = loggerFactory; this.messagingOptions = messagingOptions.Value; this.messagingTrace = messagingTrace; - this.responseCopier = deepCopier.GetCopier(); - this.responseCodecProvider = serviceProvider.GetRequiredService(); - this.responseCopyContexts = serviceProvider.GetRequiredService(); + this.invocationContext = new( + serviceProvider.GetRequiredService(), + serviceProvider.GetRequiredService(), + deepCopier.GetCopier()); var period = Max(TimeSpan.FromMilliseconds(1), Min(this.messagingOptions.ResponseTimeout, TimeSpan.FromSeconds(1))); this.callbackTimer = new PeriodicTimer(period, timeProvider); @@ -325,14 +324,13 @@ public async Task Invoke(IGrainContext target, Message message) if (GrainCallFilters is { Count: > 0 } || target.GrainInstance is IIncomingGrainCallFilter) { using var invoker = new GrainMethodInvoker(message, target, invokable, GrainCallFilters, this.interfaceToImplementationMapping, - this.responseCopier, this.responseCodecProvider, this.responseCopyContexts); + this.invocationContext); await invoker.Invoke(); response = invoker.TakeResponse(); } else { - response = await invokable.InvokeAndCopy( - this.responseCodecProvider, this.responseCopyContexts, this.responseCopier); + response = await invokable.Invoke(this.invocationContext); isCopied = response.Exception is null; } diff --git a/src/Orleans.Serialization/GeneratedCodeHelpers/OrleansGeneratedCodeHelper.cs b/src/Orleans.Serialization/GeneratedCodeHelpers/OrleansGeneratedCodeHelper.cs index 769d5f3fe01..8abe5e5a777 100644 --- a/src/Orleans.Serialization/GeneratedCodeHelpers/OrleansGeneratedCodeHelper.cs +++ b/src/Orleans.Serialization/GeneratedCodeHelpers/OrleansGeneratedCodeHelper.cs @@ -31,7 +31,16 @@ public static class OrleansGeneratedCodeHelper public static Response CopyResponseAndDispose(Response response, DeepCopier copier) { ArgumentNullExceptionPolyfill.ThrowIfNull(copier); - return CopyResponseAndDispose(response, copier, static (value, service) => service.Copy(value)!); + ArgumentNullExceptionPolyfill.ThrowIfNull(response); + Response? copy = null; + try + { + return copy = copier.Copy(response)!; + } + finally + { + ReleaseSupersededResponse(response, copy); + } } /// @@ -43,23 +52,23 @@ public static Response CopyResponseAndDispose(Response response, DeepCopier service.Copy(value)!); - } - - private static Response CopyResponseAndDispose(Response response, TCopier copier, Func copyResponse) - { ArgumentNullExceptionPolyfill.ThrowIfNull(response); Response? copy = null; try { - return copy = copyResponse(response, copier); + return copy = copier.Copy(response)!; } finally { - if (!ReferenceEquals(response, copy)) response.Dispose(); + ReleaseSupersededResponse(response, copy); } } + private static void ReleaseSupersededResponse(Response response, Response? copy) + { + if (!ReferenceEquals(response, copy)) response.Dispose(); + } + /// /// Creates the default activator for a statically specified reference type. /// diff --git a/src/Orleans.Serialization/Invocation/IInvokable.cs b/src/Orleans.Serialization/Invocation/IInvokable.cs index adf2df2a273..bf8b0e96902 100644 --- a/src/Orleans.Serialization/Invocation/IInvokable.cs +++ b/src/Orleans.Serialization/Invocation/IInvokable.cs @@ -2,9 +2,6 @@ using System.Reflection; using System.Threading; using System.Threading.Tasks; -using Orleans.Serialization.Cloning; -using Orleans.Serialization.GeneratedCodeHelpers; -using Orleans.Serialization.Serializers; namespace Orleans.Serialization.Invocation { @@ -33,35 +30,10 @@ public interface IInvokable : IDisposable /// /// Invokes the method and isolates its successful result before returning to incoming filters. /// - /// The invocation's serialization provider. - /// The invocation's copy-context pool. - /// The selected copier for response implementations. + /// The provider-owned services used to isolate the result. /// An owned response whose successful result is isolated. /// Exception envelopes retain the original exception for filters and are copied at delivery. - async ValueTask InvokeAndCopy( - ICodecProvider codecProvider, - CopyContextPool copyContextPool, - DeepCopier responseCopier) - { - Response? response = await Invoke(); - try - { - if (response.Exception is not null) - { - var result = response; - response = null; - return result; - } - - var original = response; - response = null; - return OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); - } - finally - { - response?.Dispose(); - } - } + ValueTask Invoke(InvocationContext context) => context.Invoke(this); /// /// Gets the number of arguments. diff --git a/src/Orleans.Serialization/Invocation/InvocationContext.cs b/src/Orleans.Serialization/Invocation/InvocationContext.cs new file mode 100644 index 00000000000..a228ac95763 --- /dev/null +++ b/src/Orleans.Serialization/Invocation/InvocationContext.cs @@ -0,0 +1,86 @@ +using System; +using System.Threading.Tasks; +using Orleans.Serialization.Cloning; +using Orleans.Serialization.GeneratedCodeHelpers; +using Orleans.Serialization.Serializers; + +namespace Orleans.Serialization.Invocation; + +/// +/// Provides the provider-owned serialization services used to isolate invocation results. +/// +/// +/// A context can be reused across invocations using the same serialization provider. +/// Successful results are isolated before incoming filters resume. Exceptions retain their original identity until delivery. +/// +public sealed class InvocationContext +{ + /// + /// Initializes an invocation context with its serialization services. + /// + /// The provider used to resolve concrete result services. + /// The pool used to copy mutable result graphs. + /// The selected copier used by compatibility invocations. + public InvocationContext(ICodecProvider codecProvider, CopyContextPool copyContextPool, DeepCopier responseCopier) + { + CodecProvider = codecProvider ?? throw new ArgumentNullException(nameof(codecProvider)); + CopyContextPool = copyContextPool ?? throw new ArgumentNullException(nameof(copyContextPool)); + ResponseCopier = responseCopier ?? throw new ArgumentNullException(nameof(responseCopier)); + } + + /// + /// Gets the provider used to resolve concrete result services. + /// + public ICodecProvider CodecProvider { get; } + + /// + /// Gets the pool used to copy mutable result graphs. + /// + public CopyContextPool CopyContextPool { get; } + + /// + /// Gets the selected copier used by compatibility invocations. + /// + public DeepCopier ResponseCopier { get; } + + /// + /// Invokes a request's parameterless entry point and isolates its successful result using the selected response copier. + /// + /// The request using compatibility response implementations. + /// An owned isolated response, or an exception response representing an invocation or copying failure. + /// Generated invocations use this path when the provider selects custom result or response services. + public async ValueTask InvokeCompatibility(IInvokable request) + { + try + { + return CopyResult(await request.Invoke()); + } + catch (Exception exception) + { + return Response.FromException(exception); + } + } + + internal async ValueTask Invoke(IInvokable request) + => CopyResult(await request.Invoke()); + + private Response CopyResult(Response response) + { + Response? ownedResponse = response; + try + { + if (response.Exception is not null) + { + ownedResponse = null; + return response; + } + + ownedResponse = null; + return OrleansGeneratedCodeHelper.CopyResponseAndDispose(response, ResponseCopier); + } + finally + { + ownedResponse?.Dispose(); + } + } +} diff --git a/src/Orleans.Serialization/Invocation/Pools/ResponsePool.cs b/src/Orleans.Serialization/Invocation/Pools/ResponsePool.cs index e5ab2deea3c..e87f4e43172 100644 --- a/src/Orleans.Serialization/Invocation/Pools/ResponsePool.cs +++ b/src/Orleans.Serialization/Invocation/Pools/ResponsePool.cs @@ -10,37 +10,32 @@ public static class ResponsePool /// /// The underlying response type. /// A value from the pool. - public static Response Get() => TypedPool.Pool.Get(); + public static Response Get() => Pool>.Instance.Get(); /// /// Returns a value to the pool. /// /// The underlying response type. /// The value to return to the pool. - public static void Return(Response obj) => TypedPool.Pool.Return(obj); + public static void Return(Response obj) => Pool>.Instance.Return(obj); /// /// Rents a generated concrete response holder. /// /// The concrete response type. /// A reset response holder. - public static TResponse GetGenerated() where TResponse : Response, new() => GeneratedPool.Pool.Get(); + public static TResponse GetGenerated() where TResponse : Response, new() => Pool.Instance.Get(); /// /// Returns a generated response after its value and provider dependencies have been cleared. /// /// The concrete response type. /// The reset response. - public static void ReturnGenerated(TResponse response) where TResponse : Response, new() => GeneratedPool.Pool.Return(response); + public static void ReturnGenerated(TResponse response) where TResponse : Response, new() => Pool.Instance.Return(response); - private static class GeneratedPool where TResponse : Response, new() + private static class Pool where TResponse : Response, new() { - public static readonly ConcurrentObjectPool Pool = new(); - } - - private static class TypedPool - { - public static readonly ConcurrentObjectPool> Pool = new(); + public static readonly ConcurrentObjectPool Instance = new(); } } } diff --git a/src/api/Orleans.Core/Orleans.Core.cs b/src/api/Orleans.Core/Orleans.Core.cs index f5e45365106..a8367f08536 100644 --- a/src/api/Orleans.Core/Orleans.Core.cs +++ b/src/api/Orleans.Core/Orleans.Core.cs @@ -3124,7 +3124,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { throw null; } public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) { } } @@ -3160,7 +3160,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { throw null; } public override void SetArgument(int index, object value) { } @@ -3203,7 +3203,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { throw null; } public override void SetArgument(int index, object value) { } @@ -3245,7 +3245,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { throw null; } public override void SetArgument(int index, object value) { } @@ -3317,7 +3317,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { throw null; } public override void SetArgument(int index, object value) { } @@ -3531,7 +3531,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { throw null; } public override void SetArgument(int index, object value) { } @@ -3566,7 +3566,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { throw null; } public override void SetArgument(int index, object value) { } @@ -3670,7 +3670,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { throw null; } public override void SetArgument(int index, object value) { } @@ -4297,7 +4297,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.ValueTask InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { throw null; } public override void SetArgument(int index, object value) { } @@ -6018,7 +6018,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { throw null; } public override void SetArgument(int index, object value) { } @@ -6370,7 +6370,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { throw null; } public override void SetArgument(int index, object value) { } @@ -6408,7 +6408,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { throw null; } public override void SetArgument(int index, object value) { } @@ -6543,7 +6543,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { throw null; } public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) { } } diff --git a/src/api/Orleans.Serialization/Orleans.Serialization.cs b/src/api/Orleans.Serialization/Orleans.Serialization.cs index bdf49d45b03..ebb212c4885 100644 --- a/src/api/Orleans.Serialization/Orleans.Serialization.cs +++ b/src/api/Orleans.Serialization/Orleans.Serialization.cs @@ -3609,12 +3609,25 @@ public partial interface IInvokable : System.IDisposable string GetMethodName(); object? GetTarget(); System.Threading.Tasks.ValueTask Invoke(); - System.Threading.Tasks.ValueTask InvokeAndCopy(Serializers.ICodecProvider codecProvider, Cloning.CopyContextPool copyContextPool, DeepCopier responseCopier); + System.Threading.Tasks.ValueTask Invoke(InvocationContext context); void SetArgument(int index, object value); void SetTarget(ITargetHolder holder); bool TryCancel(); } + public sealed partial class InvocationContext + { + public InvocationContext(Serializers.ICodecProvider codecProvider, Cloning.CopyContextPool copyContextPool, DeepCopier responseCopier) { } + + public Serializers.ICodecProvider CodecProvider { get { throw null; } } + + public Cloning.CopyContextPool CopyContextPool { get { throw null; } } + + public DeepCopier ResponseCopier { get { throw null; } } + + public System.Threading.Tasks.ValueTask InvokeCompatibility(IInvokable request) { throw null; } + } + public static partial class InvokablePool { public static T Get() diff --git a/src/api/Orleans.Streaming/Orleans.Streaming.cs b/src/api/Orleans.Streaming/Orleans.Streaming.cs index d273a9f92de..1b3d9683642 100644 --- a/src/api/Orleans.Streaming/Orleans.Streaming.cs +++ b/src/api/Orleans.Streaming/Orleans.Streaming.cs @@ -3436,7 +3436,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.ValueTask InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { throw null; } public override void SetArgument(int index, object value) { } @@ -3476,7 +3476,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.ValueTask InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { throw null; } public override void SetArgument(int index, object value) { } diff --git a/src/api/Orleans.Transactions.TestKit.Base/Orleans.Transactions.TestKit.Base.cs b/src/api/Orleans.Transactions.TestKit.Base/Orleans.Transactions.TestKit.Base.cs index 8eb7baf55f6..409e013599a 100644 --- a/src/api/Orleans.Transactions.TestKit.Base/Orleans.Transactions.TestKit.Base.cs +++ b/src/api/Orleans.Transactions.TestKit.Base/Orleans.Transactions.TestKit.Base.cs @@ -2773,7 +2773,7 @@ public override void Dispose() { } protected override System.Threading.Tasks.Task[]> InvokeInner() { throw null; } - System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) { throw null; } + System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { throw null; } public override void SetArgument(int index, object value) { } diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index 27a32cce351..337787505d4 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -2288,7 +2288,7 @@ public partial class Context : Orleans.Serialization.SerializerContext { } frameworkSymbol.GeneratedSources.OrderBy(static source => source.HintName, StringComparer.Ordinal) .Select(static source => (source.HintName, Source: source.SourceText.ToString()))); var source = ConcatenateGeneratedSources(managed); - Assert.Contains("IInvokable.InvokeAndCopy", source); + Assert.Contains("IInvokable.Invoke(", source); Assert.Contains("IRawResponseWriter", source); Assert.Contains("AddRawResponseReader", source); Assert.DoesNotContain("#if NET5_0_OR_GREATER", source); @@ -3668,16 +3668,27 @@ public interface IWriter : IGrainWithIntegerKey { {{returnType}} Get(); } Assert.Contains("ResponsePool.GetGenerated<", response); Assert.Contains("_factory = null", response); Assert.Contains("options.AddRawResponseReader", response); - Assert.Contains("IInvokable.InvokeAndCopy", proxy); + Assert.Contains("IInvokable.Invoke(", proxy); + Assert.DoesNotContain("InvokeAndCopy", proxy); + Assert.Contains("InvocationContext context", proxy); + Assert.Contains("if (resultTask.IsCompleted)", proxy); + Assert.Contains("resultTask.GetAwaiter().GetResult()", proxy); Assert.Contains("factory.RentCopied(value, contexts)", proxy); - Assert.Contains("var original = await Invoke();", proxy); - Assert.Contains("OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier)", proxy); + Assert.Contains("context.InvokeCompatibility(this)", proxy); + Assert.DoesNotContain("CopyResponseAndDispose", proxy); Assert.DoesNotContain("MakeGenericType", response); var holders = CSharpSyntaxTree.ParseText(response, cancellationToken: TestContext.Current.CancellationToken) .GetCompilationUnitRoot(TestContext.Current.CancellationToken).DescendantNodes() .OfType().Where(static type => type.BaseList?.ToString().Contains("IRawResponseWriter", StringComparison.Ordinal) == true).ToArray(); var holder = Assert.Single(holders); Assert.Null(holder.TypeParameterList); + var invocation = CSharpSyntaxTree.ParseText(proxy, cancellationToken: TestContext.Current.CancellationToken) + .GetCompilationUnitRoot(TestContext.Current.CancellationToken).DescendantNodes() + .OfType().Single(static method => method.ExplicitInterfaceSpecifier is not null + && method.Identifier.ValueText == "Invoke"); + Assert.DoesNotContain(invocation.Modifiers, static modifier => modifier.IsKind(SyntaxKind.AsyncKeyword)); + Assert.Equal(1, invocation.DescendantNodes().OfType().Count( + static expression => expression.Expression is IdentifierNameSyntax { Identifier.ValueText: "InvokeInner" })); var factory = CSharpSyntaxTree.ParseText(response, cancellationToken: TestContext.Current.CancellationToken) .GetCompilationUnitRoot(TestContext.Current.CancellationToken).DescendantNodes() .OfType().Single(static type => type.Identifier.ValueText.EndsWith("Factory", StringComparison.Ordinal)); @@ -3715,7 +3726,7 @@ public interface ICompatibility : IGrainWithIntegerKey var result = RunSourceGenerator(compilation); Assert.Empty(result.Diagnostics); var proxy = Assert.Single(result.GeneratedSources, static item => item.HintName.Contains(".orleans.proxy.", StringComparison.Ordinal)).SourceText.ToString(); - Assert.DoesNotContain("IInvokable.InvokeAndCopy", proxy); + Assert.DoesNotContain("InvocationContext context", proxy); } private static GeneratorRunResult RunSourceGenerator( diff --git a/test/Orleans.CodeGenerator.Tests/RpcResponseHolderNamingTests.cs b/test/Orleans.CodeGenerator.Tests/RpcResponseHolderNamingTests.cs index 2ed7a6d22ff..3a2323a7f8f 100644 --- a/test/Orleans.CodeGenerator.Tests/RpcResponseHolderNamingTests.cs +++ b/test/Orleans.CodeGenerator.Tests/RpcResponseHolderNamingTests.cs @@ -93,8 +93,9 @@ public async Task CollidingResultsCompileAndUseDistinctFactories(bool compatibil using var secondRequest = requests[1]; firstRequest.SetTarget(new TargetHolder(target!)); secondRequest.SetTarget(new TargetHolder(target!)); - using var first = await firstRequest.InvokeAndCopy(provider, contexts, copier); - using var second = await secondRequest.InvokeAndCopy(provider, contexts, copier); + var invocationContext = new InvocationContext(provider, contexts, copier); + using var first = await firstRequest.Invoke(invocationContext); + using var second = await secondRequest.Invoke(invocationContext); Assert.IsAssignableFrom(first); Assert.IsAssignableFrom(second); Assert.NotEqual(first.GetType(), second.GetType()); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs index d65055da134..1ef37d4a95f 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet10_0.verified.cs @@ -57,20 +57,29 @@ public override void SetArgument(int index, object value) } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.SayHello(arg0); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { try { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(context.CodecProvider); if (!factory.IsSupported) - { - var original = await Invoke(); - if (original.Exception is not null) - return original; - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); - } + return context.InvokeCompatibility(this); + var resultTask = InvokeInner(); + if (resultTask.IsCompleted) + return new(factory.RentCopied(resultTask.GetAwaiter().GetResult(), context.CopyContextPool)); + return CompleteInvokeAsync(resultTask, factory, context.CopyContextPool); + } + catch (global::System.Exception exception) + { + return new(global::Orleans.Serialization.Invocation.Response.FromException(exception)); + } + } - string value = await InvokeInner(); + private static async global::System.Threading.Tasks.ValueTask CompleteInvokeAsync(global::System.Threading.Tasks.Task resultTask, global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory factory, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + try + { + string value = await resultTask; return factory.RentCopied(value, contexts); } catch (global::System.Exception exception) diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs index fd1d2dc9ee5..0860495fa94 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.DotNet8_0.verified.cs @@ -57,20 +57,29 @@ public override void SetArgument(int index, object value) } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.SayHello(arg0); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { try { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(context.CodecProvider); if (!factory.IsSupported) - { - var original = await Invoke(); - if (original.Exception is not null) - return original; - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); - } + return context.InvokeCompatibility(this); + var resultTask = InvokeInner(); + if (resultTask.IsCompleted) + return new(factory.RentCopied(resultTask.GetAwaiter().GetResult(), context.CopyContextPool)); + return CompleteInvokeAsync(resultTask, factory, context.CopyContextPool); + } + catch (global::System.Exception exception) + { + return new(global::Orleans.Serialization.Invocation.Response.FromException(exception)); + } + } - string value = await InvokeInner(); + private static async global::System.Threading.Tasks.ValueTask CompleteInvokeAsync(global::System.Threading.Tasks.Task resultTask, global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory factory, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + try + { + string value = await resultTask; return factory.RentCopied(value, contexts); } catch (global::System.Exception exception) diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs index 364bef45f5f..dc2438c7a88 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet10_0.verified.cs @@ -57,20 +57,29 @@ public override void SetArgument(int index, object value) } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.SayHello(arg0); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { try { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(context.CodecProvider); if (!factory.IsSupported) - { - var original = await Invoke(); - if (original.Exception is not null) - return original; - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); - } + return context.InvokeCompatibility(this); + var resultTask = InvokeInner(); + if (resultTask.IsCompleted) + return new(factory.RentCopied(resultTask.GetAwaiter().GetResult(), context.CopyContextPool)); + return CompleteInvokeAsync(resultTask, factory, context.CopyContextPool); + } + catch (global::System.Exception exception) + { + return new(global::Orleans.Serialization.Invocation.Response.FromException(exception)); + } + } - string value = await InvokeInner(); + private static async global::System.Threading.Tasks.ValueTask CompleteInvokeAsync(global::System.Threading.Tasks.Task resultTask, global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory factory, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + try + { + string value = await resultTask; return factory.RentCopied(value, contexts); } catch (global::System.Exception exception) diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs index 30d5ab98303..44ccf2e5faf 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.DotNet8_0.verified.cs @@ -57,20 +57,29 @@ public override void SetArgument(int index, object value) } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.SayHello(arg0); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { try { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(context.CodecProvider); if (!factory.IsSupported) - { - var original = await Invoke(); - if (original.Exception is not null) - return original; - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); - } + return context.InvokeCompatibility(this); + var resultTask = InvokeInner(); + if (resultTask.IsCompleted) + return new(factory.RentCopied(resultTask.GetAwaiter().GetResult(), context.CopyContextPool)); + return CompleteInvokeAsync(resultTask, factory, context.CopyContextPool); + } + catch (global::System.Exception exception) + { + return new(global::Orleans.Serialization.Invocation.Response.FromException(exception)); + } + } - string value = await InvokeInner(); + private static async global::System.Threading.Tasks.ValueTask CompleteInvokeAsync(global::System.Threading.Tasks.Task resultTask, global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory factory, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + try + { + string value = await resultTask; return factory.RentCopied(value, contexts); } catch (global::System.Exception exception) diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs index 17e95187ee4..f4a5c472f30 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet10_0.verified.cs @@ -101,20 +101,29 @@ public override bool TryCancel() public override bool IsCancellable => true; - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { try { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_FC7DD5BDFactory.Resolve(provider); + var factory = global::OrleansCodeGen.TestProject.RpcResponse_FC7DD5BDFactory.Resolve(context.CodecProvider); if (!factory.IsSupported) - { - var original = await Invoke(); - if (original.Exception is not null) - return original; - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); - } + return context.InvokeCompatibility(this); + var resultTask = InvokeInner(); + if (resultTask.IsCompleted) + return new(factory.RentCopied(resultTask.GetAwaiter().GetResult(), context.CopyContextPool)); + return CompleteInvokeAsync(resultTask, factory, context.CopyContextPool); + } + catch (global::System.Exception exception) + { + return new(global::Orleans.Serialization.Invocation.Response.FromException(exception)); + } + } - global::TestProject.ComplexData value = await InvokeInner(); + private static async global::System.Threading.Tasks.ValueTask CompleteInvokeAsync(global::System.Threading.Tasks.Task resultTask, global::OrleansCodeGen.TestProject.RpcResponse_FC7DD5BDFactory factory, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + try + { + global::TestProject.ComplexData value = await resultTask; return factory.RentCopied(value, contexts); } catch (global::System.Exception exception) diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs index 0a7a68f45a9..e51058f281e 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.DotNet8_0.verified.cs @@ -100,20 +100,29 @@ public override bool TryCancel() } public override bool IsCancellable => true; - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { try { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_FC7DD5BDFactory.Resolve(provider); + var factory = global::OrleansCodeGen.TestProject.RpcResponse_FC7DD5BDFactory.Resolve(context.CodecProvider); if (!factory.IsSupported) - { - var original = await Invoke(); - if (original.Exception is not null) - return original; - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); - } + return context.InvokeCompatibility(this); + var resultTask = InvokeInner(); + if (resultTask.IsCompleted) + return new(factory.RentCopied(resultTask.GetAwaiter().GetResult(), context.CopyContextPool)); + return CompleteInvokeAsync(resultTask, factory, context.CopyContextPool); + } + catch (global::System.Exception exception) + { + return new(global::Orleans.Serialization.Invocation.Response.FromException(exception)); + } + } - global::TestProject.ComplexData value = await InvokeInner(); + private static async global::System.Threading.Tasks.ValueTask CompleteInvokeAsync(global::System.Threading.Tasks.Task resultTask, global::OrleansCodeGen.TestProject.RpcResponse_FC7DD5BDFactory factory, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + try + { + global::TestProject.ComplexData value = await resultTask; return factory.RentCopied(value, contexts); } catch (global::System.Exception exception) diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs index a407ca52dcc..e062e2b68c5 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet10_0.verified.cs @@ -62,20 +62,29 @@ public override void SetArgument(int index, object value) } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.SayHello(arg0); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { try { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(context.CodecProvider); if (!factory.IsSupported) - { - var original = await Invoke(); - if (original.Exception is not null) - return original; - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); - } + return context.InvokeCompatibility(this); + var resultTask = InvokeInner(); + if (resultTask.IsCompleted) + return new(factory.RentCopied(resultTask.GetAwaiter().GetResult(), context.CopyContextPool)); + return CompleteInvokeAsync(resultTask, factory, context.CopyContextPool); + } + catch (global::System.Exception exception) + { + return new(global::Orleans.Serialization.Invocation.Response.FromException(exception)); + } + } - string value = await InvokeInner(); + private static async global::System.Threading.Tasks.ValueTask CompleteInvokeAsync(global::System.Threading.Tasks.Task resultTask, global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory factory, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + try + { + string value = await resultTask; return factory.RentCopied(value, contexts); } catch (global::System.Exception exception) diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs index 3b480a34576..0323df96358 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.DotNet8_0.verified.cs @@ -62,20 +62,29 @@ public override void SetArgument(int index, object value) } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.SayHello(arg0); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { try { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(context.CodecProvider); if (!factory.IsSupported) - { - var original = await Invoke(); - if (original.Exception is not null) - return original; - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); - } + return context.InvokeCompatibility(this); + var resultTask = InvokeInner(); + if (resultTask.IsCompleted) + return new(factory.RentCopied(resultTask.GetAwaiter().GetResult(), context.CopyContextPool)); + return CompleteInvokeAsync(resultTask, factory, context.CopyContextPool); + } + catch (global::System.Exception exception) + { + return new(global::Orleans.Serialization.Invocation.Response.FromException(exception)); + } + } - string value = await InvokeInner(); + private static async global::System.Threading.Tasks.ValueTask CompleteInvokeAsync(global::System.Threading.Tasks.Task resultTask, global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory factory, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + try + { + string value = await resultTask; return factory.RentCopied(value, contexts); } catch (global::System.Exception exception) diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs index 9c7077c2876..ecbe8dbc2b2 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet10_0.verified.cs @@ -59,20 +59,29 @@ public override void SetArgument(int index, object value) } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.LongRunningMethod(arg0); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { try { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(context.CodecProvider); if (!factory.IsSupported) - { - var original = await Invoke(); - if (original.Exception is not null) - return original; - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); - } + return context.InvokeCompatibility(this); + var resultTask = InvokeInner(); + if (resultTask.IsCompleted) + return new(factory.RentCopied(resultTask.GetAwaiter().GetResult(), context.CopyContextPool)); + return CompleteInvokeAsync(resultTask, factory, context.CopyContextPool); + } + catch (global::System.Exception exception) + { + return new(global::Orleans.Serialization.Invocation.Response.FromException(exception)); + } + } - string value = await InvokeInner(); + private static async global::System.Threading.Tasks.ValueTask CompleteInvokeAsync(global::System.Threading.Tasks.Task resultTask, global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory factory, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + try + { + string value = await resultTask; return factory.RentCopied(value, contexts); } catch (global::System.Exception exception) diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs index 4c7e7dbc2a5..6400f6e5dbf 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.DotNet8_0.verified.cs @@ -59,20 +59,29 @@ public override void SetArgument(int index, object value) } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.LongRunningMethod(arg0); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { try { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(context.CodecProvider); if (!factory.IsSupported) - { - var original = await Invoke(); - if (original.Exception is not null) - return original; - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); - } + return context.InvokeCompatibility(this); + var resultTask = InvokeInner(); + if (resultTask.IsCompleted) + return new(factory.RentCopied(resultTask.GetAwaiter().GetResult(), context.CopyContextPool)); + return CompleteInvokeAsync(resultTask, factory, context.CopyContextPool); + } + catch (global::System.Exception exception) + { + return new(global::Orleans.Serialization.Invocation.Response.FromException(exception)); + } + } - string value = await InvokeInner(); + private static async global::System.Threading.Tasks.ValueTask CompleteInvokeAsync(global::System.Threading.Tasks.Task resultTask, global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory factory, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + try + { + string value = await resultTask; return factory.RentCopied(value, contexts); } catch (global::System.Exception exception) diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs index 2f120a0df68..7ca26ada2a0 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet10_0.verified.cs @@ -30,20 +30,29 @@ public override void Dispose() } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.GetGuidValue(); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { try { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_5C3A711CFactory.Resolve(provider); + var factory = global::OrleansCodeGen.TestProject.RpcResponse_5C3A711CFactory.Resolve(context.CodecProvider); if (!factory.IsSupported) - { - var original = await Invoke(); - if (original.Exception is not null) - return original; - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); - } + return context.InvokeCompatibility(this); + var resultTask = InvokeInner(); + if (resultTask.IsCompleted) + return new(factory.RentCopied(resultTask.GetAwaiter().GetResult(), context.CopyContextPool)); + return CompleteInvokeAsync(resultTask, factory, context.CopyContextPool); + } + catch (global::System.Exception exception) + { + return new(global::Orleans.Serialization.Invocation.Response.FromException(exception)); + } + } - global::System.Guid value = await InvokeInner(); + private static async global::System.Threading.Tasks.ValueTask CompleteInvokeAsync(global::System.Threading.Tasks.Task resultTask, global::OrleansCodeGen.TestProject.RpcResponse_5C3A711CFactory factory, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + try + { + global::System.Guid value = await resultTask; return factory.RentCopied(value, contexts); } catch (global::System.Exception exception) @@ -86,20 +95,29 @@ public override void Dispose() } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.GetStringKey(); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { try { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(context.CodecProvider); if (!factory.IsSupported) - { - var original = await Invoke(); - if (original.Exception is not null) - return original; - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); - } + return context.InvokeCompatibility(this); + var resultTask = InvokeInner(); + if (resultTask.IsCompleted) + return new(factory.RentCopied(resultTask.GetAwaiter().GetResult(), context.CopyContextPool)); + return CompleteInvokeAsync(resultTask, factory, context.CopyContextPool); + } + catch (global::System.Exception exception) + { + return new(global::Orleans.Serialization.Invocation.Response.FromException(exception)); + } + } - string value = await InvokeInner(); + private static async global::System.Threading.Tasks.ValueTask CompleteInvokeAsync(global::System.Threading.Tasks.Task resultTask, global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory factory, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + try + { + string value = await resultTask; return factory.RentCopied(value, contexts); } catch (global::System.Exception exception) @@ -142,20 +160,29 @@ public override void Dispose() } protected override global::System.Threading.Tasks.Task> InvokeInner() => _target.GetGuidAndStringKey(); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { try { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_6A3EE8F4Factory.Resolve(provider); + var factory = global::OrleansCodeGen.TestProject.RpcResponse_6A3EE8F4Factory.Resolve(context.CodecProvider); if (!factory.IsSupported) - { - var original = await Invoke(); - if (original.Exception is not null) - return original; - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); - } + return context.InvokeCompatibility(this); + var resultTask = InvokeInner(); + if (resultTask.IsCompleted) + return new(factory.RentCopied(resultTask.GetAwaiter().GetResult(), context.CopyContextPool)); + return CompleteInvokeAsync(resultTask, factory, context.CopyContextPool); + } + catch (global::System.Exception exception) + { + return new(global::Orleans.Serialization.Invocation.Response.FromException(exception)); + } + } - global::System.Tuple value = await InvokeInner(); + private static async global::System.Threading.Tasks.ValueTask CompleteInvokeAsync(global::System.Threading.Tasks.Task> resultTask, global::OrleansCodeGen.TestProject.RpcResponse_6A3EE8F4Factory factory, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + try + { + global::System.Tuple value = await resultTask; return factory.RentCopied(value, contexts); } catch (global::System.Exception exception) @@ -198,20 +225,29 @@ public override void Dispose() } protected override global::System.Threading.Tasks.Task> InvokeInner() => _target.GetIntegerAndStringKey(); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { try { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_AFB713E4Factory.Resolve(provider); + var factory = global::OrleansCodeGen.TestProject.RpcResponse_AFB713E4Factory.Resolve(context.CodecProvider); if (!factory.IsSupported) - { - var original = await Invoke(); - if (original.Exception is not null) - return original; - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); - } + return context.InvokeCompatibility(this); + var resultTask = InvokeInner(); + if (resultTask.IsCompleted) + return new(factory.RentCopied(resultTask.GetAwaiter().GetResult(), context.CopyContextPool)); + return CompleteInvokeAsync(resultTask, factory, context.CopyContextPool); + } + catch (global::System.Exception exception) + { + return new(global::Orleans.Serialization.Invocation.Response.FromException(exception)); + } + } - global::System.Tuple value = await InvokeInner(); + private static async global::System.Threading.Tasks.ValueTask CompleteInvokeAsync(global::System.Threading.Tasks.Task> resultTask, global::OrleansCodeGen.TestProject.RpcResponse_AFB713E4Factory factory, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + try + { + global::System.Tuple value = await resultTask; return factory.RentCopied(value, contexts); } catch (global::System.Exception exception) diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs index 8a7f0ec4943..edcc913c949 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.DotNet8_0.verified.cs @@ -30,20 +30,29 @@ public override void Dispose() } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.GetGuidValue(); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { try { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_5C3A711CFactory.Resolve(provider); + var factory = global::OrleansCodeGen.TestProject.RpcResponse_5C3A711CFactory.Resolve(context.CodecProvider); if (!factory.IsSupported) - { - var original = await Invoke(); - if (original.Exception is not null) - return original; - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); - } + return context.InvokeCompatibility(this); + var resultTask = InvokeInner(); + if (resultTask.IsCompleted) + return new(factory.RentCopied(resultTask.GetAwaiter().GetResult(), context.CopyContextPool)); + return CompleteInvokeAsync(resultTask, factory, context.CopyContextPool); + } + catch (global::System.Exception exception) + { + return new(global::Orleans.Serialization.Invocation.Response.FromException(exception)); + } + } - global::System.Guid value = await InvokeInner(); + private static async global::System.Threading.Tasks.ValueTask CompleteInvokeAsync(global::System.Threading.Tasks.Task resultTask, global::OrleansCodeGen.TestProject.RpcResponse_5C3A711CFactory factory, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + try + { + global::System.Guid value = await resultTask; return factory.RentCopied(value, contexts); } catch (global::System.Exception exception) @@ -86,20 +95,29 @@ public override void Dispose() } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.GetStringKey(); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { try { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(context.CodecProvider); if (!factory.IsSupported) - { - var original = await Invoke(); - if (original.Exception is not null) - return original; - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); - } + return context.InvokeCompatibility(this); + var resultTask = InvokeInner(); + if (resultTask.IsCompleted) + return new(factory.RentCopied(resultTask.GetAwaiter().GetResult(), context.CopyContextPool)); + return CompleteInvokeAsync(resultTask, factory, context.CopyContextPool); + } + catch (global::System.Exception exception) + { + return new(global::Orleans.Serialization.Invocation.Response.FromException(exception)); + } + } - string value = await InvokeInner(); + private static async global::System.Threading.Tasks.ValueTask CompleteInvokeAsync(global::System.Threading.Tasks.Task resultTask, global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory factory, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + try + { + string value = await resultTask; return factory.RentCopied(value, contexts); } catch (global::System.Exception exception) @@ -142,20 +160,29 @@ public override void Dispose() } protected override global::System.Threading.Tasks.Task> InvokeInner() => _target.GetGuidAndStringKey(); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { try { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_6A3EE8F4Factory.Resolve(provider); + var factory = global::OrleansCodeGen.TestProject.RpcResponse_6A3EE8F4Factory.Resolve(context.CodecProvider); if (!factory.IsSupported) - { - var original = await Invoke(); - if (original.Exception is not null) - return original; - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); - } + return context.InvokeCompatibility(this); + var resultTask = InvokeInner(); + if (resultTask.IsCompleted) + return new(factory.RentCopied(resultTask.GetAwaiter().GetResult(), context.CopyContextPool)); + return CompleteInvokeAsync(resultTask, factory, context.CopyContextPool); + } + catch (global::System.Exception exception) + { + return new(global::Orleans.Serialization.Invocation.Response.FromException(exception)); + } + } - global::System.Tuple value = await InvokeInner(); + private static async global::System.Threading.Tasks.ValueTask CompleteInvokeAsync(global::System.Threading.Tasks.Task> resultTask, global::OrleansCodeGen.TestProject.RpcResponse_6A3EE8F4Factory factory, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + try + { + global::System.Tuple value = await resultTask; return factory.RentCopied(value, contexts); } catch (global::System.Exception exception) @@ -198,20 +225,29 @@ public override void Dispose() } protected override global::System.Threading.Tasks.Task> InvokeInner() => _target.GetIntegerAndStringKey(); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { try { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_AFB713E4Factory.Resolve(provider); + var factory = global::OrleansCodeGen.TestProject.RpcResponse_AFB713E4Factory.Resolve(context.CodecProvider); if (!factory.IsSupported) - { - var original = await Invoke(); - if (original.Exception is not null) - return original; - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); - } + return context.InvokeCompatibility(this); + var resultTask = InvokeInner(); + if (resultTask.IsCompleted) + return new(factory.RentCopied(resultTask.GetAwaiter().GetResult(), context.CopyContextPool)); + return CompleteInvokeAsync(resultTask, factory, context.CopyContextPool); + } + catch (global::System.Exception exception) + { + return new(global::Orleans.Serialization.Invocation.Response.FromException(exception)); + } + } - global::System.Tuple value = await InvokeInner(); + private static async global::System.Threading.Tasks.ValueTask CompleteInvokeAsync(global::System.Threading.Tasks.Task> resultTask, global::OrleansCodeGen.TestProject.RpcResponse_AFB713E4Factory factory, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + try + { + global::System.Tuple value = await resultTask; return factory.RentCopied(value, contexts); } catch (global::System.Exception exception) diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs index bf846fa59f0..708f349d6eb 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet10_0.verified.cs @@ -57,20 +57,29 @@ public override void SetArgument(int index, object value) } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.MethodA(arg0); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { try { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(context.CodecProvider); if (!factory.IsSupported) - { - var original = await Invoke(); - if (original.Exception is not null) - return original; - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); - } + return context.InvokeCompatibility(this); + var resultTask = InvokeInner(); + if (resultTask.IsCompleted) + return new(factory.RentCopied(resultTask.GetAwaiter().GetResult(), context.CopyContextPool)); + return CompleteInvokeAsync(resultTask, factory, context.CopyContextPool); + } + catch (global::System.Exception exception) + { + return new(global::Orleans.Serialization.Invocation.Response.FromException(exception)); + } + } - string value = await InvokeInner(); + private static async global::System.Threading.Tasks.ValueTask CompleteInvokeAsync(global::System.Threading.Tasks.Task resultTask, global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory factory, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + try + { + string value = await resultTask; return factory.RentCopied(value, contexts); } catch (global::System.Exception exception) @@ -141,20 +150,29 @@ public override void SetArgument(int index, object value) } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.MethodB(arg0); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { try { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(context.CodecProvider); if (!factory.IsSupported) - { - var original = await Invoke(); - if (original.Exception is not null) - return original; - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); - } + return context.InvokeCompatibility(this); + var resultTask = InvokeInner(); + if (resultTask.IsCompleted) + return new(factory.RentCopied(resultTask.GetAwaiter().GetResult(), context.CopyContextPool)); + return CompleteInvokeAsync(resultTask, factory, context.CopyContextPool); + } + catch (global::System.Exception exception) + { + return new(global::Orleans.Serialization.Invocation.Response.FromException(exception)); + } + } - string value = await InvokeInner(); + private static async global::System.Threading.Tasks.ValueTask CompleteInvokeAsync(global::System.Threading.Tasks.Task resultTask, global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory factory, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + try + { + string value = await resultTask; return factory.RentCopied(value, contexts); } catch (global::System.Exception exception) diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs index 3762b49dadb..48a274d2e82 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.DotNet8_0.verified.cs @@ -57,20 +57,29 @@ public override void SetArgument(int index, object value) } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.MethodA(arg0); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { try { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(context.CodecProvider); if (!factory.IsSupported) - { - var original = await Invoke(); - if (original.Exception is not null) - return original; - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); - } + return context.InvokeCompatibility(this); + var resultTask = InvokeInner(); + if (resultTask.IsCompleted) + return new(factory.RentCopied(resultTask.GetAwaiter().GetResult(), context.CopyContextPool)); + return CompleteInvokeAsync(resultTask, factory, context.CopyContextPool); + } + catch (global::System.Exception exception) + { + return new(global::Orleans.Serialization.Invocation.Response.FromException(exception)); + } + } - string value = await InvokeInner(); + private static async global::System.Threading.Tasks.ValueTask CompleteInvokeAsync(global::System.Threading.Tasks.Task resultTask, global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory factory, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + try + { + string value = await resultTask; return factory.RentCopied(value, contexts); } catch (global::System.Exception exception) @@ -141,20 +150,29 @@ public override void SetArgument(int index, object value) } protected override global::System.Threading.Tasks.Task InvokeInner() => _target.MethodB(arg0); - async global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.InvokeAndCopy(global::Orleans.Serialization.Serializers.ICodecProvider provider, global::Orleans.Serialization.Cloning.CopyContextPool contexts, global::Orleans.Serialization.DeepCopier responseCopier) + global::System.Threading.Tasks.ValueTask global::Orleans.Serialization.Invocation.IInvokable.Invoke(global::Orleans.Serialization.Invocation.InvocationContext context) { try { - var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(provider); + var factory = global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory.Resolve(context.CodecProvider); if (!factory.IsSupported) - { - var original = await Invoke(); - if (original.Exception is not null) - return original; - return global::Orleans.Serialization.GeneratedCodeHelpers.OrleansGeneratedCodeHelper.CopyResponseAndDispose(original, responseCopier); - } + return context.InvokeCompatibility(this); + var resultTask = InvokeInner(); + if (resultTask.IsCompleted) + return new(factory.RentCopied(resultTask.GetAwaiter().GetResult(), context.CopyContextPool)); + return CompleteInvokeAsync(resultTask, factory, context.CopyContextPool); + } + catch (global::System.Exception exception) + { + return new(global::Orleans.Serialization.Invocation.Response.FromException(exception)); + } + } - string value = await InvokeInner(); + private static async global::System.Threading.Tasks.ValueTask CompleteInvokeAsync(global::System.Threading.Tasks.Task resultTask, global::OrleansCodeGen.TestProject.RpcResponse_9146C7E3Factory factory, global::Orleans.Serialization.Cloning.CopyContextPool contexts) + { + try + { + string value = await resultTask; return factory.RentCopied(value, contexts); } catch (global::System.Exception exception) diff --git a/test/Orleans.Core.Tests/Serialization/SelfWritingResponseFilterTests.cs b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseFilterTests.cs index c33657e477a..bfb4d170e37 100644 --- a/test/Orleans.Core.Tests/Serialization/SelfWritingResponseFilterTests.cs +++ b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseFilterTests.cs @@ -204,7 +204,7 @@ private static GrainMethodInvoker CreateInvoker( }; return new GrainMethodInvoker( message, grainContext, request, [filter], new InterfaceToImplementationMappingCache(), - responseCopier, codecProvider, copyContexts); + new InvocationContext(codecProvider, copyContexts, responseCopier)); } private sealed class CallbackFilter(Func callback) : IIncomingGrainCallFilter @@ -251,13 +251,12 @@ public override ValueTask Invoke() throw new InvalidOperationException("Direct invocations must not use the legacy Invoke path."); } - public ValueTask InvokeAndCopy( - ICodecProvider codecProvider, CopyContextPool copyContextPool, DeepCopier responseCopier) + public ValueTask Invoke(InvocationContext context) { DirectCalls++; - CodecProvider = codecProvider; - CopyContexts = copyContextPool; - ResponseCopier = responseCopier; + CodecProvider = context.CodecProvider; + CopyContexts = context.CopyContextPool; + ResponseCopier = context.ResponseCopier; if (failure is not null) { ReturnedResponse = Response.FromException(failure); diff --git a/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs index bca6e2efbfd..44daa863eac 100644 --- a/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs +++ b/test/Orleans.Core.Tests/Serialization/SelfWritingResponseOwnershipTests.cs @@ -54,7 +54,7 @@ public async Task DefaultInvokableContractCopiesAndTransfersOneOwner(string beha if (behavior == "Throw") { var exception = await Assert.ThrowsAsync(async () => - await ((IInvokable)request).InvokeAndCopy(provider, contexts, copier)); + await ((IInvokable)request).Invoke(new InvocationContext(provider, contexts, copier))); Assert.Same(counts.CopyFailure, exception); Assert.Equal(1, counts.Rents); Assert.Equal(1, counts.Returns); @@ -62,7 +62,7 @@ public async Task DefaultInvokableContractCopiesAndTransfersOneOwner(string beha } else { - var response = await ((IInvokable)request).InvokeAndCopy(provider, contexts, copier); + var response = await ((IInvokable)request).Invoke(new InvocationContext(provider, contexts, copier)); Assert.Equal(1, counts.ResponseCopies); Assert.Equal(behavior == "Same" ? 0 : 1, counts.PayloadCopies); Assert.Equal(behavior == "Same" ? 0 : 1, counts.Returns); @@ -794,11 +794,11 @@ public virtual ValueTask Invoke() private sealed class DirectRequest(Payload payload, Counts counts) : LegacyRequest(payload, counts), IInvokable { - public override ValueTask Invoke() => throw new InvalidOperationException("The direct request uses InvokeAndCopy."); + public override ValueTask Invoke() => throw new InvalidOperationException("The direct request uses the contextual invocation contract."); - public ValueTask InvokeAndCopy(ICodecProvider provider, CopyContextPool contexts, DeepCopier responseCopier) + public ValueTask Invoke(InvocationContext context) { - ReturnedResponse = CountedResponse.Rent(Counters.Copy(Payload), Counters, provider.GetCodec()); + ReturnedResponse = CountedResponse.Rent(Counters.Copy(Payload), Counters, context.CodecProvider.GetCodec()); AfterInvocation?.Invoke(); return ValueTask.FromResult(ReturnedResponse); } @@ -813,7 +813,7 @@ private class ExceptionRequest(Exception failure, Counts counts) : LegacyRequest private sealed class DirectExceptionRequest(Exception failure, Counts counts) : ExceptionRequest(failure, counts), IInvokable { public override ValueTask Invoke() => throw new InvalidOperationException("Use the isolated invocation contract."); - public ValueTask InvokeAndCopy(ICodecProvider provider, CopyContextPool contexts, DeepCopier copier) + public ValueTask Invoke(InvocationContext context) => ValueTask.FromResult(Response.FromException(Failure)); } diff --git a/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs b/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs index 463c651fb21..9fbabaaca9d 100644 --- a/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs +++ b/test/Orleans.NativeAotSmoke/RpcResponses.Contracts.cs @@ -53,6 +53,8 @@ public static async System.Threading.Tasks.Task GeneratedInvokablesWriteCopiedRe using var services = CreateServices(); var provider = services.GetRequiredService(); var contexts = services.GetRequiredService(); + var invocationContext = new InvocationContext(provider, contexts, + new DeepCopier(provider.GetDeepCopier(), contexts)); var target = new SelfWritingTarget(); IRpcSelfWriting proxy = new global::OrleansCodeGen.Orleans.NativeAotSmoke.Proxy_IRpcSelfWriting(provider, contexts); _ = proxy.Boolean(); @@ -62,8 +64,7 @@ public static async System.Threading.Tasks.Task GeneratedInvokablesWriteCopiedRe _ = proxy.Payload(); using var request = ((RpcTupleProxyBase)proxy).Captured!; request.SetTarget(target); - using var response = await request.InvokeAndCopy(provider, contexts, - new DeepCopier(provider.GetDeepCopier(), contexts)); + using var response = await request.Invoke(invocationContext); Ensure(response is IRawResponseWriter && !response.GetType().IsGenericType, "The actual generated invokable creates a non-generic self-writing holder."); var value = response.GetResult(); @@ -84,12 +85,39 @@ public static async System.Threading.Tasks.Task GeneratedInvokablesWriteCopiedRe var decoded = reconstructed.GetResult(); Ensure(decoded is not null && ReferenceEquals(decoded, decoded.Left), "The static reader reconstructs the self-writing cyclic holder."); + var booleanCompletion = new System.Threading.Tasks.TaskCompletionSource(); + target.BooleanResult = booleanCompletion.Task; + _ = proxy.Boolean(); + using (var pendingRequest = ((RpcTupleProxyBase)proxy).Captured!) + { + pendingRequest.SetTarget(target); + var invocation = pendingRequest.Invoke(invocationContext); + Ensure(!invocation.IsCompleted, "Pending tasks use asynchronous generated completion."); + booleanCompletion.SetResult(true); + using var result = await invocation; + Ensure(result is IRawResponseWriter && result.GetResult(), "Asynchronous task completion produces a concrete holder."); + } + + var integerCompletion = new System.Threading.Tasks.TaskCompletionSource(); + target.IntegerResult = new(integerCompletion.Task); + _ = proxy.Integer(); + using (var pendingRequest = ((RpcTupleProxyBase)proxy).Captured!) + { + pendingRequest.SetTarget(target); + var invocation = pendingRequest.Invoke(invocationContext); + Ensure(!invocation.IsCompleted, "Pending value tasks use asynchronous generated completion."); + integerCompletion.SetResult(42); + using var result = await invocation; + Ensure(result is IRawResponseWriter && result.GetResult() == 42, "Asynchronous value-task completion produces a concrete holder."); + } + async System.Threading.Tasks.Task Check(IInvokable invocation, T expected) { using var request = invocation; request.SetTarget(target); - using var result = await request.InvokeAndCopy(provider, contexts, - new DeepCopier(provider.GetDeepCopier(), contexts)); + var pending = request.Invoke(invocationContext); + Ensure(pending.IsCompletedSuccessfully, "Completed task and value-task results use the generated synchronous path."); + using var result = await pending; Ensure(result is IRawResponseWriter && Equals(expected, result.GetResult()), "Generated primitive responses bind direct writers."); var output = new ArrayBufferWriter(); using (var session = services.GetRequiredService().GetSession()) @@ -115,11 +143,13 @@ async System.Threading.Tasks.Task Check(IInvokable invocation, T expected) private sealed class SelfWritingTarget : IRpcSelfWriting, ITargetHolder { public RpcResponsePayload Result { get; } = new() { Value = 47 }; + public System.Threading.Tasks.Task BooleanResult { get; set; } = System.Threading.Tasks.Task.FromResult(true); + public System.Threading.Tasks.ValueTask IntegerResult { get; set; } = new(42); public SelfWritingTarget() => Result.Left = Result; public object GetTarget() => this; public object? GetComponent(Type type) => type.IsInstanceOfType(this) ? this : null; - public System.Threading.Tasks.Task Boolean() => System.Threading.Tasks.Task.FromResult(true); - public System.Threading.Tasks.ValueTask Integer() => new(42); + public System.Threading.Tasks.Task Boolean() => BooleanResult; + public System.Threading.Tasks.ValueTask Integer() => IntegerResult; public System.Threading.Tasks.Task Payload() => System.Threading.Tasks.Task.FromResult(Result); } #endif diff --git a/test/Orleans.Serialization.UnitTests/InvocationContextTests.cs b/test/Orleans.Serialization.UnitTests/InvocationContextTests.cs new file mode 100644 index 00000000000..8f1aa848a5d --- /dev/null +++ b/test/Orleans.Serialization.UnitTests/InvocationContextTests.cs @@ -0,0 +1,539 @@ +using System; +using System.Linq; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Threading; +using System.Threading.Tasks; +using System.Threading.Tasks.Sources; +using Microsoft.Extensions.DependencyInjection; +using Orleans.Runtime; +using Orleans.Serialization.Cloning; +using Orleans.Serialization.Codecs; +using Orleans.Serialization.Invocation; +using Orleans.Serialization.Serializers; + +namespace Orleans.Serialization.UnitTests; + +[Trait("Category", "BVT")] +[TestSuite("BVT")] +[TestProvider("None")] +[TestArea("Serialization")] +public sealed class InvocationContextTests : IDisposable +{ + private readonly ServiceProvider _services = new ServiceCollection().AddSerializer().BuildServiceProvider(); + private readonly InvocationContext _context; + + public InvocationContextTests() + { + _context = new InvocationContext( + _services.GetRequiredService(), + _services.GetRequiredService(), + _services.GetRequiredService().GetCopier()); + } + + public void Dispose() => _services.Dispose(); + + [Theory] + [InlineData("codecProvider")] + [InlineData("copyContextPool")] + [InlineData("responseCopier")] + public void ConstructorRejectsNullServices(string parameterName) + { + var exception = Assert.Throws(() => new InvocationContext( + parameterName == "codecProvider" ? null! : _context.CodecProvider, + parameterName == "copyContextPool" ? null! : _context.CopyContextPool, + parameterName == "responseCopier" ? null! : _context.ResponseCopier)); + + Assert.Equal(parameterName, exception.ParamName); + } + + [Fact] + public async Task ConstructorRetainsProvidedServicesAfterInvocation() + { + var provider = _services.GetRequiredService(); + var contexts = _services.GetRequiredService(); + var copier = _services.GetRequiredService().GetCopier(); + var context = new InvocationContext(provider, contexts, copier); + var target = new InvocationTarget(); + + Assert.Same(provider, context.CodecProvider); + Assert.Same(contexts, context.CopyContextPool); + Assert.Same(copier, context.ResponseCopier); + foreach (var useValueTask in new[] { false, true }) + { + using var request = CreateInvokable(useValueTask, target); + using var response = await request.Invoke(context); + Assert.Equal(InvocationTarget.CompletedResult, response.GetResult()); + } + + Assert.Same(provider, context.CodecProvider); + Assert.Same(contexts, context.CopyContextPool); + Assert.Same(copier, context.ResponseCopier); + Assert.Equal(1, target.TaskCalls); + Assert.Equal(1, target.ValueTaskCalls); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task GeneratedContextualInvokeReturnsCompletedValueSynchronously(bool useValueTask) + { + var target = new InvocationTarget(); + using var request = CreateInvokable(useValueTask, target); + + var invocation = request.Invoke(_context); + + Assert.True(invocation.IsCompletedSuccessfully); + using var response = await invocation; + AssertGeneratedResult(response, InvocationTarget.CompletedResult); + AssertCalls(target, useValueTask, 1); + Assert.Same(target, request.GetTarget()); + } + + [Fact] + public async Task GeneratedTaskInvokeWaitsForIncompleteCompletion() + { + var source = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var target = new InvocationTarget { TaskCompletion = source.Task }; + using var request = CreateInvokable(false, target); + + var invocation = request.Invoke(_context); + + Assert.False(source.Task.IsCompleted); + Assert.False(invocation.IsCompleted); + AssertCalls(target, false, 1); + source.SetResult(-101); + using var response = await invocation; + AssertGeneratedResult(response, -101); + AssertCalls(target, false, 1); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task GeneratedValueTaskInvokeConsumesSourceExactlyOnce(bool completeBeforeInvoke) + { + var source = new SingleConsumptionSource(); + var target = new InvocationTarget { ValueTaskCompletion = source.CreateValueTask() }; + using var request = CreateInvokable(true, target); + if (completeBeforeInvoke) source.SetResult(-211); + + var invocation = request.Invoke(_context); + + Assert.Equal(completeBeforeInvoke, invocation.IsCompletedSuccessfully); + Assert.Equal(completeBeforeInvoke ? 1 : 0, source.GetResultCalls); + Assert.Equal(completeBeforeInvoke ? 0 : 1, source.OnCompletedCalls); + AssertCalls(target, true, 1); + if (!completeBeforeInvoke) + { + Assert.False(invocation.IsCompleted); + Assert.Equal(ValueTaskSourceStatus.Pending, source.Status); + source.SetResult(-211); + } + + using var response = await invocation; + AssertGeneratedResult(response, -211); + Assert.Equal(1, source.GetResultCalls); + Assert.Equal(completeBeforeInvoke ? 0 : 1, source.OnCompletedCalls); + AssertCalls(target, true, 1); + } + + [Theory] + [InlineData(false, false)] + [InlineData(false, true)] + [InlineData(true, false)] + [InlineData(true, true)] + public async Task GeneratedTaskInvokePreservesFaultAndCancellationIdentity(bool completeBeforeInvoke, bool cancel) + { + var source = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + Exception expected = cancel + ? new OperationCanceledException("controlled Task cancellation", new CancellationToken(canceled: true)) + : new InvalidOperationException("controlled Task failure"); + if (completeBeforeInvoke) source.SetResult(0); + // The async task builder retains the original OCE and marks the task canceled. + // A bare TCS.SetCanceled() instead synthesizes a new exception on each GetResult. + var target = new InvocationTarget { TaskCompletion = FailAfterBarrier(source.Task, expected) }; + using var request = CreateInvokable(false, target); + + var invocation = request.Invoke(_context); + + // The invocation succeeds with an exception envelope, not a faulted ValueTask. + Assert.Equal(completeBeforeInvoke, invocation.IsCompletedSuccessfully); + AssertCalls(target, false, 1); + if (!completeBeforeInvoke) + { + Assert.False(invocation.IsCompleted); + Assert.False(source.Task.IsCompleted); + Assert.False(target.TaskCompletion.IsCompleted); + source.SetResult(0); + } + + using var response = await invocation; + Assert.IsType(response); + Assert.Same(expected, response.Exception); + Assert.Same(expected, Assert.ThrowsAny(() => response.GetResult())); + Assert.Equal(cancel, target.TaskCompletion.IsCanceled); + Assert.Equal(!cancel, target.TaskCompletion.IsFaulted); + AssertCalls(target, false, 1); + } + + [Theory] + [InlineData(false, false)] + [InlineData(false, true)] + [InlineData(true, false)] + [InlineData(true, true)] + public async Task GeneratedValueTaskInvokePreservesFaultAndCancellationIdentity(bool completeBeforeInvoke, bool cancel) + { + var source = new SingleConsumptionSource(); + Exception expected = cancel + ? new OperationCanceledException("controlled ValueTask cancellation", new CancellationToken(canceled: true)) + : new InvalidOperationException("controlled ValueTask failure"); + var target = new InvocationTarget { ValueTaskCompletion = source.CreateValueTask() }; + using var request = CreateInvokable(true, target); + if (completeBeforeInvoke) source.SetException(expected); + + var invocation = request.Invoke(_context); + + Assert.Equal(completeBeforeInvoke, invocation.IsCompletedSuccessfully); + Assert.Equal(completeBeforeInvoke ? 1 : 0, source.GetResultCalls); + Assert.Equal(completeBeforeInvoke ? 0 : 1, source.OnCompletedCalls); + AssertCalls(target, true, 1); + if (!completeBeforeInvoke) + { + Assert.False(invocation.IsCompleted); + Assert.Equal(ValueTaskSourceStatus.Pending, source.Status); + source.SetException(expected); + } + + using var response = await invocation; + Assert.IsType(response); + Assert.Same(expected, response.Exception); + Assert.Same(expected, Assert.ThrowsAny(() => response.GetResult())); + Assert.Equal(cancel ? ValueTaskSourceStatus.Canceled : ValueTaskSourceStatus.Faulted, source.Status); + Assert.Equal(1, source.GetResultCalls); + Assert.Equal(completeBeforeInvoke ? 0 : 1, source.OnCompletedCalls); + AssertCalls(target, true, 1); + } + + [Theory] + [InlineData(false, false, "Distinct")] + [InlineData(false, false, "Same")] + [InlineData(false, false, "Throw")] + [InlineData(false, true, "Distinct")] + [InlineData(false, true, "Same")] + [InlineData(false, true, "Throw")] + [InlineData(true, false, "Distinct")] + [InlineData(true, false, "Same")] + [InlineData(true, false, "Throw")] + [InlineData(true, true, "Distinct")] + [InlineData(true, true, "Same")] + [InlineData(true, true, "Throw")] + public async Task GeneratedCompatibilityInvocationPreservesCopyOwnership(bool useValueTask, bool completeBeforeInvoke, string behavior) + { + using var services = new ServiceCollection().AddSerializer(builder => builder.Configure(options => + options.AddSerializer(static _ => new Int32Codec(), static _ => new CompatibilityIntCopier()))) + .BuildServiceProvider(); + var copier = new TrackingResponseCopier(behavior); + var context = new InvocationContext( + services.GetRequiredService(), + services.GetRequiredService(), + new DeepCopier(copier, services.GetRequiredService())); + var completion = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + if (completeBeforeInvoke) completion.SetResult(InvocationTarget.CompletedResult); + var target = new InvocationTarget + { + TaskCompletion = completion.Task, + ValueTaskCompletion = new(completion.Task) + }; + using var request = CreateInvokable(useValueTask, target); + + var invocation = request.Invoke(context); + + Assert.Equal(completeBeforeInvoke, invocation.IsCompletedSuccessfully); + if (!completeBeforeInvoke) + { + Assert.Equal(0, copier.Calls); + completion.SetResult(InvocationTarget.CompletedResult); + } + using var response = await invocation; + Assert.Equal(1, copier.Calls); + Assert.IsType>(copier.Input); + AssertCalls(target, useValueTask, 1); + if (behavior == "Throw") + { + Assert.IsType(response); + Assert.Same(copier.Failure, response.Exception); + } + else + { + Assert.IsType>(response); + Assert.Equal(InvocationTarget.CompletedResult, response.GetResult()); + Assert.Null(response.Exception); + } + if (behavior == "Same") Assert.Same(copier.Input, response); + else + { + Assert.NotSame(copier.Input, response); + Assert.Equal(0, copier.Input!.GetResult()); + } + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public void GeneratedContextualEntryHasNoAsyncStateMachine(bool useValueTask) + { + using var request = CreateInvokable(useValueTask, new InvocationTarget()); + var contract = typeof(IInvokable).GetMethod(nameof(IInvokable.Invoke), new[] { typeof(InvocationContext) })!; + var map = request.GetType().GetInterfaceMap(typeof(IInvokable)); + var index = Array.IndexOf(map.InterfaceMethods, contract); + + Assert.NotEqual(-1, index); + var entry = map.TargetMethods[index]; + Assert.Equal(request.GetType(), entry.DeclaringType); + Assert.True(entry.IsPrivate); + Assert.Null(entry.GetCustomAttribute()); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public void WarmedSynchronousInvocationAndDisposeAllocateZeroBytes(bool useValueTask) + { + const int warmupCount = 8_192; + const int measuredCount = 1_024; + var target = new InvocationTarget(); + using var request = CreateInvokable(useValueTask, target); + + using (var copyContext = _context.CopyContextPool.GetContext()) + using (var legacy = Response.FromResult(InvocationTarget.CompletedResult)) + using (var copy = _context.ResponseCopier.Copy(legacy)) + { + Assert.Equal(InvocationTarget.CompletedResult, copy.GetResult()); + } + + Response? warmedResponse = null; + for (var i = 0; i < warmupCount; i++) + { + using var response = GetCompletedResponse(request.Invoke(_context)); + warmedResponse = response; + } + + var allSynchronous = true; + var resultSum = 0; + Response? lastResponse = null; + var before = GC.GetAllocatedBytesForCurrentThread(); + for (var i = 0; i < measuredCount; i++) + { + var invocation = request.Invoke(_context); + allSynchronous &= invocation.IsCompletedSuccessfully; + using var response = GetCompletedResponse(invocation); + resultSum += response.GetResult(); + lastResponse = response; + } + var allocated = GC.GetAllocatedBytesForCurrentThread() - before; + + Assert.Equal(0L, allocated); + Assert.True(allSynchronous); + Assert.Equal(measuredCount * InvocationTarget.CompletedResult, resultSum); + AssertCalls(target, useValueTask, warmupCount + measuredCount); + Assert.IsAssignableFrom(lastResponse); + Assert.Same(warmedResponse, lastResponse); + Assert.Equal(0, lastResponse!.GetResult()); + } + + [Fact] + public void LegacyDisposeReturnsEnvelopeToGeneratedPool() + { + var original = ResponsePool.Get(); + original.TypedResult = 73; + + original.Dispose(); + using var generated = ResponsePool.GetGenerated>(); + + Assert.Same(original, generated); + Assert.Equal(0, generated.TypedResult); + Assert.Null(generated.Exception); + Assert.Equal(typeof(int), generated.GetSimpleResultType()); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public void GeneratedReturnSharesLegacyEnvelopePool(bool dispose) + { + var generated = ResponsePool.GetGenerated>(); + generated.TypedResult = -117; + if (dispose) + { + generated.Dispose(); + } + else + { + // Explicit ReturnGenerated requires the caller to clear its envelope first. + generated.TypedResult = default; + ResponsePool.ReturnGenerated(generated); + } + + using var legacy = ResponsePool.Get(); + Assert.Same(generated, legacy); + Assert.Equal(0, legacy.TypedResult); + Assert.Null(legacy.Exception); + Assert.Equal(typeof(int), legacy.GetSimpleResultType()); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task GeneratedParameterlessInvokeRetainsLegacyResponse(bool useValueTask) + { + var target = new InvocationTarget(); + using var request = CreateInvokable(useValueTask, target); + + var invocation = request.Invoke(); + + Assert.True(invocation.IsCompletedSuccessfully); + using var response = await invocation; + Assert.IsType>(response); + Assert.Equal(InvocationTarget.CompletedResult, response.GetResult()); + Assert.Null(response.Exception); + AssertCalls(target, useValueTask, 1); + } + + private static void AssertGeneratedResult(Response response, int expected) + { + Assert.IsAssignableFrom(response); + Assert.Equal(typeof(int), response.GetSimpleResultType()); + Assert.Equal(expected, response.GetResult()); + Assert.Null(response.Exception); + } + + private static void AssertCalls(InvocationTarget target, bool useValueTask, int expected) + { + Assert.Equal(useValueTask ? 0 : expected, target.TaskCalls); + Assert.Equal(useValueTask ? expected : 0, target.ValueTaskCalls); + } + + private static async Task FailAfterBarrier(Task barrier, Exception exception) + { + await barrier; + throw exception; + } + + private static Response GetCompletedResponse(ValueTask invocation) + { + // Allocation sampling must stay on this thread. Never block on an incomplete + // operation: that is a failure of the synchronous path being measured. + if (!invocation.IsCompletedSuccessfully) + throw new InvalidOperationException("Expected a synchronously completed invocation."); + return invocation.GetAwaiter().GetResult(); + } + + private static IInvokable CreateInvokable(bool useValueTask, InvocationTarget target) + { + var methodName = useValueTask ? nameof(IInvocationContextTestGrain.ValueTaskResult) : nameof(IInvocationContextTestGrain.TaskResult); + var types = typeof(IInvocationContextTestGrain).Assembly.GetTypes() + .Where(static type => !type.IsAbstract && typeof(IInvokable).IsAssignableFrom(type) + && type.Name.StartsWith("Invokable_IInvocationContextTestGrain_", StringComparison.Ordinal)); + foreach (var type in types) + { + var request = (IInvokable)Activator.CreateInstance(type)!; + if (request.GetMethodName() != methodName) + { + request.Dispose(); + continue; + } + + Assert.Equal(typeof(IInvocationContextTestGrain), request.GetInterfaceType()); + if (useValueTask) Assert.IsAssignableFrom>(request); + else Assert.IsAssignableFrom>(request); + request.SetTarget(target); + return request; + } + + throw new InvalidOperationException($"No generated request was found for {methodName}."); + } + + private sealed class InvocationTarget : IInvocationContextTestGrain, ITargetHolder + { + public const int CompletedResult = 913; + public Task TaskCompletion { get; init; } = Task.FromResult(CompletedResult); + public ValueTask ValueTaskCompletion { get; init; } = new(CompletedResult); + public int TaskCalls { get; private set; } + public int ValueTaskCalls { get; private set; } + + public Task TaskResult() + { + TaskCalls++; + return TaskCompletion; + } + + public ValueTask ValueTaskResult() + { + ValueTaskCalls++; + return ValueTaskCompletion; + } + + public object GetTarget() => this; + public object? GetComponent(Type componentType) => componentType.IsInstanceOfType(this) ? this : null; + } + + private sealed class SingleConsumptionSource : IValueTaskSource + { + private ManualResetValueTaskSourceCore _core = new() { RunContinuationsAsynchronously = true }; + private int _getResultCalls; + private int _onCompletedCalls; + + public int GetResultCalls => Volatile.Read(ref _getResultCalls); + public int OnCompletedCalls => Volatile.Read(ref _onCompletedCalls); + public ValueTaskSourceStatus Status => _core.GetStatus(_core.Version); + public ValueTask CreateValueTask() => new(this, _core.Version); + public void SetResult(int result) => _core.SetResult(result); + public void SetException(Exception exception) => _core.SetException(exception); + public ValueTaskSourceStatus GetStatus(short token) => _core.GetStatus(token); + + public int GetResult(short token) + { + if (Interlocked.Increment(ref _getResultCalls) != 1) + throw new InvalidOperationException("ValueTask source was consumed more than once."); + return _core.GetResult(token); + } + + public void OnCompleted(Action continuation, object? state, short token, ValueTaskSourceOnCompletedFlags flags) + { + Interlocked.Increment(ref _onCompletedCalls); + _core.OnCompleted(continuation, state, token, flags); + } + } + + private sealed class CompatibilityIntCopier : IDeepCopier + { + public int DeepCopy(int input, CopyContext context) => input; + } + + private sealed class TrackingResponseCopier(string behavior) : IDeepCopier + { + public int Calls { get; private set; } + public Response? Input { get; private set; } + public Exception Failure { get; } = new InvalidOperationException("response copying failed"); + + [return: System.Diagnostics.CodeAnalysis.NotNullIfNotNull(nameof(input))] + public Response? DeepCopy(Response? input, CopyContext context) + { + if (input is null) return null; + Calls++; + Input = input; + if (behavior == "Throw") throw Failure; + return behavior == "Same" ? input : Response.FromResult(input.GetResult()); + } + } +} + +public interface IInvocationContextTestGrain : IGrainWithIntegerKey +{ + [Id(0)] + Task TaskResult(); + + [Id(1)] + ValueTask ValueTaskResult(); +} diff --git a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs index 79728cb5721..0b60ae4798f 100644 --- a/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs +++ b/test/Orleans.Serialization.UnitTests/RpcResponseTests.cs @@ -637,7 +637,7 @@ public async Task GeneratedResponseFactoryResolvesDependenciesOnlyDuringConstruc if (readerFirst) Assert.True(provider.TryGetRawResponseReader(typeof(int), out _)); using var invokable = CreateInvokable("Integer"); invokable.SetTarget(new TargetHolder(new RpcResponseTarget())); - using var response = await invokable.InvokeAndCopy(provider, contexts, copier); + using var response = await invokable.Invoke(new InvocationContext(provider, contexts, copier)); Assert.IsAssignableFrom(response); Assert.Equal(42, response.GetResult()); Assert.True(provider.TryGetRawResponseReader(typeof(int), out var reader)); @@ -745,9 +745,9 @@ public async Task GeneratedResponseFactoryKeepsProviderSpecificOverridesWhenInvo { var selected = i % 2 == 0 ? _services : overridden; var selectedProvider = selected.GetRequiredService(); - using var response = await invokable.InvokeAndCopy( + using var response = await invokable.Invoke(new InvocationContext( selectedProvider, selected.GetRequiredService(), - selected.GetRequiredService().GetCopier()); + selected.GetRequiredService().GetCopier())); Assert.Null(response.Exception); Assert.Equal(i % 2 == 0 ? 42 : 43, response.GetResult()); Assert.Equal(i % 2 == 0, response is IRawResponseWriter); @@ -784,7 +784,7 @@ public async Task GeneratedResponseHoldersCopyAndWriteDirectly(string methodName var provider = _services.GetRequiredService(); var contexts = _services.GetRequiredService(); var compatibility = new CountingResponseCopier(); - using var response = await direct.InvokeAndCopy(provider, contexts, new DeepCopier(compatibility, contexts)); + using var response = await direct.Invoke(new InvocationContext(provider, contexts, new DeepCopier(compatibility, contexts))); var writer = Assert.IsAssignableFrom(response); Assert.False(response.GetType().IsGenericType); Assert.Equal(0, compatibility.Copies); @@ -857,8 +857,8 @@ public async Task GeneratedResponseHoldersUseContextInJit(string methodName, Typ var compatibility = new CountingResponseCopier(); using var invokable = CreateInvokable(methodName); invokable.SetTarget(new TargetHolder(target)); - using var response = await invokable.InvokeAndCopy( - provider, contexts, new DeepCopier(compatibility, contexts)); + using var response = await invokable.Invoke(new InvocationContext( + provider, contexts, new DeepCopier(compatibility, contexts))); Assert.IsAssignableFrom(response); Assert.Equal(0, compatibility.Copies); @@ -898,7 +898,7 @@ public async Task GeneratedResponseHolderPreservesRawWireBytesAndPoolReset() var provider = _services.GetRequiredService(); var contexts = _services.GetRequiredService(); var direct = invokable; - var response = await direct.InvokeAndCopy(provider, contexts, _services.GetRequiredService().GetCopier()); + var response = await direct.Invoke(new InvocationContext(provider, contexts, _services.GetRequiredService().GetCopier())); var body = new ArrayBufferWriter(); var legacy = new ArrayBufferWriter(); var sessions = _services.GetRequiredService(); @@ -921,7 +921,7 @@ public async Task GeneratedResponseHolderPreservesRawWireBytesAndPoolReset() var factory = response.GetType().GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic) .Single(static field => field.Name == "_factory"); Assert.Null(factory.GetValue(response)); - using var reused = await direct.InvokeAndCopy(provider, contexts, _services.GetRequiredService().GetCopier()); + using var reused = await direct.Invoke(new InvocationContext(provider, contexts, _services.GetRequiredService().GetCopier())); Assert.Same(response, reused); Assert.Equal(42, reused.GetResult()); } @@ -933,8 +933,8 @@ public async Task GeneratedResponseHolderKeepsExceptionBehavior() invokable.SetTarget(new TargetHolder(new RpcResponseTarget { Fail = true })); var contexts = _services.GetRequiredService(); var compatibility = new CountingResponseCopier(); - using var response = await invokable.InvokeAndCopy( - _services.GetRequiredService(), contexts, new DeepCopier(compatibility, contexts)); + using var response = await invokable.Invoke(new InvocationContext( + _services.GetRequiredService(), contexts, new DeepCopier(compatibility, contexts))); Assert.IsType(response); Assert.Equal("response failure", response.Exception!.Message); Assert.Equal(0, compatibility.Copies); @@ -950,8 +950,8 @@ public async Task GeneratedResponseHolderPreservesCyclesAndNullPayloads() invokable.SetTarget(new TargetHolder(target)); var provider = _services.GetRequiredService(); var contexts = _services.GetRequiredService(); - using var response = await invokable.InvokeAndCopy( - provider, contexts, _services.GetRequiredService().GetCopier()); + using var response = await invokable.Invoke(new InvocationContext( + provider, contexts, _services.GetRequiredService().GetCopier())); var value = response.GetResult(); Assert.NotNull(value); Assert.NotSame(target.Result, value); @@ -975,7 +975,7 @@ public async Task GeneratedResponseHolderPreservesCyclesAndNullPayloads() Assert.Same(copied.Left, copied.Right); invokable.SetTarget(new TargetHolder(new NullPayloadTarget())); - using var empty = await invokable.InvokeAndCopy(provider, contexts, _services.GetRequiredService().GetCopier()); + using var empty = await invokable.Invoke(new InvocationContext(provider, contexts, _services.GetRequiredService().GetCopier())); Assert.IsAssignableFrom(empty); Assert.Null(empty.GetResult()); } @@ -990,8 +990,8 @@ public async Task GeneratedResponseHolderHonorsCustomPayloadCopier() var target = new RpcResponseTarget(); using var invokable = CreateInvokable("Payload"); invokable.SetTarget(new TargetHolder(target)); - using var result = await invokable.InvokeAndCopy( - provider, contexts, services.GetRequiredService().GetCopier()); + using var result = await invokable.Invoke(new InvocationContext( + provider, contexts, services.GetRequiredService().GetCopier())); Assert.IsType>(result); Assert.Same(target.Result, result.GetResult()); Assert.False(provider.TryGetRawResponseReader(typeof(NativeAotSmoke.RpcResponsePayload), out _)); @@ -1023,8 +1023,8 @@ public async Task GeneratedResponseHolderHonorsCustomResultAndResponseServices(s var contexts = services.GetRequiredService(); using var invokable = CreateInvokable("Integer"); invokable.SetTarget(new TargetHolder(new RpcResponseTarget())); - using var result = await invokable.InvokeAndCopy( - provider, contexts, services.GetRequiredService().GetCopier()); + using var result = await invokable.Invoke(new InvocationContext( + provider, contexts, services.GetRequiredService().GetCopier())); Assert.Null(result.Exception); Assert.IsType>(result); @@ -1046,7 +1046,7 @@ public async Task GeneratedResponseReaderReturnsHolderAfterMalformedPayload() var contexts = _services.GetRequiredService(); var direct = invokable; var copier = _services.GetRequiredService().GetCopier(); - var original = await direct.InvokeAndCopy(provider, contexts, copier); + var original = await direct.Invoke(new InvocationContext(provider, contexts, copier)); original.Dispose(); Assert.True(provider.TryGetRawResponseReader(typeof(int), out var registered)); var sessions = _services.GetRequiredService(); @@ -1071,7 +1071,7 @@ public async Task GeneratedResponseReaderReturnsHolderAfterMalformedPayload() Assert.Equal("wireType", error.ParamName); Assert.Equal(0, original.GetResult()); Assert.Null(original.GetType().GetField("_factory", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!.GetValue(original)); - using var reused = await direct.InvokeAndCopy(provider, contexts, copier); + using var reused = await direct.Invoke(new InvocationContext(provider, contexts, copier)); Assert.Same(original, reused); Assert.Equal(42, reused.GetResult()); } @@ -1100,7 +1100,7 @@ public async Task GeneratedResponseHolderHonorsCanonicalResponseSubclasses(bool using var invokable = CreateInvokable("Integer"); invokable.SetTarget(new TargetHolder(new RpcResponseTarget())); - using var response = await invokable.InvokeAndCopy(provider, contexts, services.GetRequiredService().GetCopier()); + using var response = await invokable.Invoke(new InvocationContext(provider, contexts, services.GetRequiredService().GetCopier())); Assert.IsType>(response); Assert.Equal(customCodec ? 42 : 43, response.GetResult()); From 0d39ed9d859c1972d1de0e1957704338410d68d1 Mon Sep 17 00:00:00 2001 From: Reuben Bond Date: Wed, 7 Oct 2026 22:57:40 -0700 Subject: [PATCH 54/54] fix(serialization): reject abstract constructor constraints on every target Apply new()-constraint abstract-type rejection before generic closure on all supported frameworks. Cover metadata-free and captured selection, fallback identity and pending construction without attempting the rejected closure. --- .../docs/implementation/serialization.md | 2 +- .../Serializers/GenericConstraintValidator.cs | 2 - .../ManifestContractTests.cs | 41 +++++++++++++++---- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/docs/site/src/content/docs/implementation/serialization.md b/docs/site/src/content/docs/implementation/serialization.md index ff90e28729f..bb7bd6119dd 100644 --- a/docs/site/src/content/docs/implementation/serialization.md +++ b/docs/site/src/content/docs/implementation/serialization.md @@ -155,7 +155,7 @@ Completed response transport uses the existing generated codec and its canonical The finite response graph supplies successful typed results and completed-response transport, plus immutable exception-envelope copying. Exception transport uses the selected codec and the exception and `Data` value dependencies. Closed factories provide statically compiled implementations; registered metadata and the existing exception codecs provide the remaining supported serialization contracts. -The generator prepares one response plan for holder naming, graph admission, and factory emission. Complete, partial, and referenced graphs share constructor-service descriptions and a registration emitter, so each dependency edge identifies the service consumed by its factory. Generated graphs register closed generic-argument metadata through . Candidate selection validates bound generic constraints before choosing an implementation, using the same validation for inferred defaults and ordinary lookup. Managed lookup retains runtime constraint validation for application-selected types whose metadata is supplied at runtime. +The generator prepares one response plan for holder naming, graph admission, and factory emission. Complete, partial, and referenced graphs share constructor-service descriptions and a registration emitter, so each dependency edge identifies the service consumed by its factory. Generated graphs register closed generic-argument metadata through . Candidate selection validates bound generic constraints before choosing an implementation, using the same validation for inferred defaults and ordinary lookup. Constructor-constrained reference arguments must be concrete types with public parameterless constructors on every target framework; invalid candidates yield to the next applicable registration before generic closure. Managed lookup retains runtime constraint validation for application-selected types whose metadata is supplied at runtime. Generated invocation fallbacks and runtime delivery boundaries share non-generic envelope copy-and-dispose ownership logic. The selected copier retains its typed or runtime-type dispatch behavior, including immutable exception envelopes and custom copiers that return their input. Raw response transport resolves one reader per result type; adapts compatibility codecs to , and supported generated readers retain precedence. diff --git a/src/Orleans.Serialization/Serializers/GenericConstraintValidator.cs b/src/Orleans.Serialization/Serializers/GenericConstraintValidator.cs index e76730bd13f..b4b3ada3484 100644 --- a/src/Orleans.Serialization/Serializers/GenericConstraintValidator.cs +++ b/src/Orleans.Serialization/Serializers/GenericConstraintValidator.cs @@ -49,9 +49,7 @@ internal static GenericConstraintValidationResult Validate( return GenericConstraintValidationResult.Invalid; if ((attributes & GenericParameterAttributes.DefaultConstructorConstraint) != 0 && !argument.IsValueType) { -#if NET10_0_OR_GREATER if (argument.IsAbstract) return GenericConstraintValidationResult.Invalid; -#endif if (metadata.TryGetValue(argument, out var argumentMetadata)) { if (!argumentMetadata.HasPublicParameterlessConstructor) return GenericConstraintValidationResult.Invalid; diff --git a/test/Orleans.Serialization.UnitTests/ManifestContractTests.cs b/test/Orleans.Serialization.UnitTests/ManifestContractTests.cs index 1a6b678828a..16e70f6a34c 100644 --- a/test/Orleans.Serialization.UnitTests/ManifestContractTests.cs +++ b/test/Orleans.Serialization.UnitTests/ManifestContractTests.cs @@ -1137,12 +1137,7 @@ public void StructConstrainedCopiersSelectTheLatestApplicableRegistration() [InlineData(typeof(ReferenceConstrainedCopier<>), typeof(int), false)] [InlineData(typeof(ConstructorConstrainedCopier<>), typeof(PublicConstructorTarget), true)] [InlineData(typeof(ConstructorConstrainedCopier<>), typeof(PrivateConstructorTarget), false)] - // MakeGenericType permits an abstract new()-constrained argument on .NET 8 and rejects it on .NET 10. -#if NET10_0_OR_GREATER [InlineData(typeof(ConstructorConstrainedCopier<>), typeof(AbstractConstructorTarget), false)] -#else - [InlineData(typeof(ConstructorConstrainedCopier<>), typeof(AbstractConstructorTarget), true)] -#endif [InlineData(typeof(ConstructorConstrainedCopier<>), typeof(int), true)] [InlineData(typeof(ConstructorConstrainedCopier<>), typeof(int?), true)] [InlineData(typeof(ComparableConstrainedCopier<>), typeof(string), true)] @@ -1188,6 +1183,37 @@ public void ConstraintRejectionsDoNotFaultPendingClosedFactoryConstruction() Assert.Equal(17, root.ValueCopier.DeepCopy(17, null!)); } + [Theory] + [InlineData(false)] + [InlineData(true)] + public void AbstractConstructorConstraintRejectionPreservesPendingConstruction(bool captureMetadata) + { + var attempts = 0; + var implementation = new CountingGenericImplementation(typeof(ConstructorConstrainedCopier<>)); + using var services = new ServiceCollection().AddSerializer(builder => builder.Configure(options => + { + if (captureMetadata) options.AddGenericArgumentMetadata(typeof(AbstractConstructorTarget)); + options.AddSerializationContract(typeof(ParameterCopier<>), typeof(IDeepCopier<>), SerializationType.Parameter(0)); + options.AddSerializationContract(implementation, typeof(IDeepCopier<>), SerializationType.Parameter(0)); + options.AddSerializerService>(provider => + { + attempts++; + Assert.True(((CodecProvider)provider).IsConstructionPending); + return provider.GetDeepCopier(); + }); + })).BuildServiceProvider(); + var provider = services.GetRequiredService(); + + var copier = GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null!, provider); + + Assert.IsType>(copier); + Assert.Same(copier, provider.GetDeepCopier()); + Assert.Same(copier, GeneratedCodeHelpers.OrleansGeneratedCodeHelper.GetService>(null!, provider)); + Assert.Equal(0, implementation.ClosureAttempts); + Assert.Equal(1, attempts); + Assert.False(provider.IsConstructionPending); + } + private sealed class ConstraintSelection(IDeepCopier referenceCopier, IDeepCopier valueCopier) { public IDeepCopier ReferenceCopier { get; } = referenceCopier; @@ -1382,6 +1408,7 @@ public void GenericArgumentMetadataCapturesAnnotatedClosedTypesAndIsIdempotent() [InlineData(typeof(ReferenceConstrainedCopier<>), typeof(string), true)] [InlineData(typeof(ReferenceConstrainedCopier<>), typeof(int), false)] [InlineData(typeof(ConstructorConstrainedCopier<>), typeof(int), true)] + [InlineData(typeof(ConstructorConstrainedCopier<>), typeof(AbstractConstructorTarget), false)] [InlineData(typeof(BaseConstrainedCopier<>), typeof(ConstraintDerived), true)] [InlineData(typeof(BaseConstrainedCopier<>), typeof(string), false)] [InlineData(typeof(DisposableConstrainedCopier<>), typeof(System.IO.MemoryStream), true)] @@ -1406,11 +1433,7 @@ public void SpecialAndClosedConstraintsAreDecidableWithoutArgumentMetadata(Type [Theory] [InlineData(typeof(ConstructorConstrainedCopier<>), typeof(PublicConstructorTarget), true)] [InlineData(typeof(ConstructorConstrainedCopier<>), typeof(PrivateConstructorTarget), false)] -#if NET10_0_OR_GREATER [InlineData(typeof(ConstructorConstrainedCopier<>), typeof(AbstractConstructorTarget), false)] -#else - [InlineData(typeof(ConstructorConstrainedCopier<>), typeof(AbstractConstructorTarget), true)] -#endif [InlineData(typeof(ConstructorConstrainedCopier<>), typeof(string), false)] [InlineData(typeof(ComparableConstrainedCopier<>), typeof(string), true)] [InlineData(typeof(ComparableConstrainedCopier<>), typeof(int), true)]