[http-client-csharp] Emit short type names from CodeWriter to slash Roslyn post-processing cost#10427
Conversation
…dant annotation Adds per-call Stopwatch tracing for Simplifier.ReduceAsync in GeneratedCodeWorkspace.ProcessDocument so the team can measure the dominant Roslyn post-processing cost without re-instrumenting. Drops the redundant Simplifier.Annotation re-application in PostProcessor.MarkInternal: changing an accessibility keyword does not introduce anything reducible, so the second-pass walk over the document is wasted work. No measurable wall-clock change on the four sampled projects (within run-to-run noise) but removes structurally unnecessary work that scales with the number of internalized types. See microsoft#10424 for the full perf analysis and remaining optimization backlog. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
commit: |
|
No changes needing a change description found. |
CodeWriter now tracks each (namespace, headName) pair it has written via global::-qualified form. In ToString(), it shortens those occurrences to either bare `HeadName` (when only one namespace owns the head name) or `Namespace.HeadName` (when multiple emitted namespaces share the head name). This removes most of the work Roslyn's NameReducer was doing on every name node via SemanticModel lookups. On Azure.AI.Projects (884 generated files): - Simplifier.ReduceAsync CPU: ~70 minutes -> 32 seconds (~130x) - Roslyn post-processing wall-clock: 37s -> 25s - Total emit wall-clock: 45s -> 28s (~38% faster) The emitted output is substantively identical; the only differences are minor cref normalizations that previously relied on Roslyn's signature-aware cref resolution. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The global:: chain reduction concern is now handled by CodeWriter emitting short names directly, so the rationale in the TODO no longer applies. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adds a global!doc:: sentinel for type references emitted inside XML documentation comments. The sentinel is left in place by the body shortening pass and swapped back to global:: at the end so Roslyn's cref-aware Simplifier can normalize the cref signature itself, preserving ? nullability annotations on parameter types that the plain string shortening would drop. Also: only run the short-name rewrite when ToString is invoked with header == true. The header-less path (used by CSharpType.ToString and MethodBodyStatement.ToString for in-process expression composition) now keeps fully-qualified names so callers cannot end up with short names without the matching using directives. Includes the bulk regeneration of test goldens and the Sample-TypeSpec generated output to reflect short-name emission, plus the helper script (eng/scripts/Update-Goldens.py) that performs the golden-file transformation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Uses the known total length from UnsafeBufferSequence.Reader.Length to allocate the final body string in one shot via string.Create, copying each segment directly into the destination span. Skips the StringBuilder chunk allocations and the extra .ToString() materialization that was introduced when the short-name rewrite was added. Adds Reader.CopyTo(Span<char>) for the new code path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…pilation Tests in NamedTypeSymbolProviderTests reference BinaryData (e.g. ValidateParameters, ValidatePropertyTypes(System.BinaryData)). The Roslyn compilation built by LoadCompilation needs an explicit metadata reference to System.Memory.Data so the BinaryData type resolves; otherwise tests fail with 'Expected: True But was: False' when comparing parameter/property types. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ShortenQualifiedNames now treats type names as collisions when: - A sub-namespace of the current namespace shares the type's simple name (e.g. Sample.ServiceA namespace shadows the System.ClientModel.ContinuationToken type when the file is in Payload.Pageable._ServerDrivenPagination). - A property/field/method/nested-type member of the primary type (or its sibling partial parts such as serialization providers) shares the type's simple name (e.g. Element.Extension property shadows the Extension type). Adds OutputLibrary.AreTypeProvidersBuilt guard to avoid re-entrant access to TypeProviders during attribute-provider writes. Updates two MultiService client goldens that previously emitted ambiguous unqualified ServiceA/KeyVault/Storage/Compute names which would not have compiled. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
When a simple type reference would be shadowed by a sub-namespace or by an inherited member of the primary type, ShortenQualifiedNames now computes the shortest qualifier that disambiguates rather than always using the full namespace. - Strip the longest common prefix shared with the current namespace. - If the result is still a bare name that collides with a primary-type member (own or inherited), prepend the last segment of the type's namespace (which resolves up the namespace chain). - Walk base types when collecting primary-type member names so inherited properties/fields/nested types also count as shadowing. - Exclude methods (and constructors) from member shadowing - methods live in a different lookup category and don't shadow type names. - Don't treat the primary type's own name as shadowing itself. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jorgerangel-msft
left a comment
There was a problem hiding this comment.
should we run a regen preview ?
| public virtual CodeFile Write() | ||
| { | ||
| using var writer = new CodeWriter(); | ||
| writer.SetPrimaryType(_provider); |
There was a problem hiding this comment.
should we set this in the ctor instead?
There was a problem hiding this comment.
Good idea — done in 9268e5e: added a CodeWriter(TypeProvider? primaryType) constructor and pass it from TypeProviderWriter.Write. Kept the parameterless ctor in place for the many existing test call sites.
| // Tracks every (namespace, headName) pair we've written as a global::-qualified name. | ||
| // headName is the outermost named type (DeclaringType.Name for nested, otherwise Name). | ||
| // Used in ToString() to drop redundant namespace prefixes (replaces the work NameReducer did). | ||
| private readonly HashSet<(string Namespace, string HeadName)> _emittedTypeRefs = new(); |
There was a problem hiding this comment.
have we considered measuring the memory usage with these changes?
There was a problem hiding this comment.
Not formally measured yet. The new state per CodeWriter is small: one extra HashSet<(string,string)> (typically <50 entries — only types we wrote global::-qualified) plus one TypeProvider? field. The big perf win comes from skipping Roslyn's Simplifier rewrite over the entire SyntaxTree, which allocates much more than this hashset, so the net effect should be a memory reduction. Happy to grab a dotMemory snapshot if you want a hard number.
| } | ||
| else | ||
| { | ||
| _emittedTypeRefs.Add((type.Namespace, type.DeclaringType?.Name ?? type.Name)); |
There was a problem hiding this comment.
does the hashset need the fully qualified namespace? Are there any issues with collisions between types?
There was a problem hiding this comment.
Yes, the namespace is needed. Two different namespaces can declare types with the same head name (e.g. Foo.Models.Result vs Bar.Models.Result). Keying by (Namespace, HeadName) lets us know which fully-qualified strings to rewrite, and during the rewrite (around line 1106) we only drop the prefix when a head name maps to a single namespace — otherwise we keep global:: for disambiguation.
| // crefs normally during post-processing. | ||
| if (bodyText.Contains(_globalDocSentinel)) | ||
| { | ||
| bodyText = bodyText.Replace(_globalDocSentinel, "global::"); |
There was a problem hiding this comment.
nit: should we just make global:: a const?
There was a problem hiding this comment.
Done in 9268e5e — extracted private const string GlobalPrefix = "global::"; and replaced the literals.
| { | ||
| if (prefixDot.Length == 0) | ||
| { | ||
| // Top-level: any first segment of any namespace shadows. |
There was a problem hiding this comment.
nit: can we just simplify this condition to avoid having an empty body?
There was a problem hiding this comment.
Done in 9268e5e — collapsed to if (prefixDot.Length > 0 && !ns.StartsWith(prefixDot, StringComparison.Ordinal)) continue; and moved the top-level explanation into the comment above the loop.
…pler conditional - Pass primary TypeProvider through CodeWriter ctor instead of a separate SetPrimaryType call. - Extract 'global::' literal into a GlobalPrefix constant. - Simplify the shadowing-namespace prefix check to avoid an empty if branch. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR optimizes the C# emitter’s Roslyn post-processing by emitting shorter, unqualified (or minimally-qualified) type names directly from CodeWriter, reducing the work done by Simplifier.ReduceAsync.
Changes:
- Update
CodeWriterto track emittedglobal::Namespace.HeadNamereferences and post-rewrite them to short/disambiguated forms (with special handling for XML-doc crefs). - Reduce unnecessary Roslyn simplifier work in post-processing and add timing instrumentation for
Simplifier.ReduceAsync. - Update generated outputs and test goldens to match short-name emission.
Reviewed changes
Copilot reviewed 242 out of 244 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Writers/CodeWriter.cs | Implement short type-name rewrite and XML-doc cref sentinel handling in ToString(true). |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Writers/UnsafeBufferSequence.Reader.cs | Add CopyTo(Span<char>) to support string.Create materialization. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Primitives/TypeProviderWriter.cs | Set primary TypeProvider on CodeWriter to detect member-name collisions during shortening. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/PostProcessing/PostProcessor.cs | Avoid re-applying Simplifier.Annotation when changing accessibility to internal. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/PostProcessing/GeneratedCodeWorkspace.cs | Add ReduceAsync timing accumulation/logging. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/OutputLibrary.cs | Add AreTypeProvidersBuilt to avoid re-entrant initialization during collision checks. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/NamedTypeSymbolProviders/CompilationHelper.cs | Add BinaryData assembly reference for compilations after short-name emission. |
| packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/Internal/ModelSerializationExtensions.cs | Update sample generated output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Writers/TestData/TypeProviderWriterTests/TypeProviderWriter_WriteModelAsStruct.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Writers/TestData/TypeProviderWriterTests/TypeProviderWriter_WriteModel.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Writers/TestData/TypeProviderWriterTests/TypeProviderWriter_WriteEnumWithFieldAttributes.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/TestData/ProviderWithAttributesTests/ValidateAttributes.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/TestData/ModelProviderTests/XmlDocsAreWritten.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/TestData/ModelProviderTests/ModelWithOptionalDiscriminatorProperty.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/TestData/ModelCustomizationTests/CanCustomizePropertyIntoReadOnlyMemory.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/TestData/ModelCustomizationTests/CanCustomizeDiscriminatorModel.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/TestData/ClientSettingsProviderTests/TestGeneratedSettings_WithUrlEndpoint.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/TestData/ClientSettingsProviderTests/TestGeneratedSettings_WithStringEndpoint.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/TestData/ClientSettingsProviderTests/TestGeneratedSettings_WithNamedStringEndpoint.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/TestData/ClientOptionsProviderTests/MultiServiceCombinedClient_GeneratesExpectedClientOptions.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/TestData/ClientOptionsProviderTests/MultiServiceClient_UniqueNamespaces_ProducesUniqueVersionEnums.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/TestData/ClientOptionsProviderTests/MultiServiceClient_SameLastSegment_ProducesUniqueVersionEnums.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/TestData/ClientOptionsProviderTests/MultiServiceClient_GeneratesExpectedClientOptions.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ScmModelProvider/TestData/ScmModelProviderTests/TestStructDynamicModel.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ScmModelProvider/TestData/ScmModelProviderTests/TestSingleDiscriminatorDynamicModel(True).cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ScmModelProvider/TestData/ScmModelProviderTests/TestSingleDiscriminatorDynamicModel(False).cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ScmModelProvider/TestData/ScmModelProviderTests/TestSimpleDynamicModel.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ScmModelProvider/TestData/ScmModelProviderTests/TestNestedDiscriminatorDynamicModel(True).cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ScmModelProvider/TestData/ScmModelProviderTests/TestNestedDiscriminatorDynamicModel(False).cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ScmModelProvider/TestData/ScmModelProviderTests/TestDynamicModelWithPropagators.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ScmModelProvider/TestData/ScmModelProviderTests/TestDynamicModelWithCustomFullConstructor/Cat.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ScmModelProvider/TestData/ScmModelProviderTests/TestDynamicModelWithBinaryDataAdditionalPropsBackCompat/DynamicModel.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ScmModelProvider/TestData/ScmModelProviderTests/TestDynamicModelWithBinaryDataAdditionalPropsBackCompat.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ScmModelProvider/TestData/ScmModelProviderTests/TestDynamicModelWithBinaryDataAdditionalProps.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ScmModelProvider/TestData/ScmModelProviderTests/TestDynamicModelInheritsFromNonDiscriminatedBase.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ScmModelProvider/TestData/ScmModelProviderTests/TestDynamicDerivedModel.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ScmModelProvider/TestData/ScmModelProviderTests/TestDiscriminatedDynamicDerivedModel.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ScmModelProvider/TestData/ScmModelProviderTests/TestDiscriminatedDynamicBaseModel.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ScmModelProvider/TestData/ScmModelProviderTests/TestCustomStructDynamicModel.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/RestClientProviders/TestData/RestClientProviderTests/ValidateClientWithSpecialHeaders.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/RestClientProviders/TestData/RestClientProviderTests/ValidateClientWithAcceptHeader_ValuesDefinedInResponse.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/RestClientProviders/TestData/RestClientProviderTests/ValidateClientWithAcceptHeader_ValuesDefinedAsEnum.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/RestClientProviders/TestData/RestClientProviderTests/ValidateClientWithAcceptHeader_ValueDefinedAsConstant.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/RestClientProviders/TestData/RestClientProviderTests/ValidateClientWithAcceptHeader_NoValuesDefined.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/RestClientProviders/TestData/RestClientProviderTests/TestNextLinkReinjectedParametersInCreateRequestMethod.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/RestClientProviders/TestData/RestClientProviderTests/TestCollectionHeaderPrefix_UsesAddWithPrefixCall(True).cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/RestClientProviders/TestData/RestClientProviderTests/TestCollectionHeaderPrefix_UsesAddWithPrefixCall(False).cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/RestClientProviders/TestData/RestClientProviderTests/TestBuildCreateRequestMethodWithSlashQueryInPath.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/RestClientProviders/TestData/RestClientProviderTests/TestBuildCreateRequestMethodWithQueryInPath.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/RestClientProviders/TestData/RestClientProviderTests/TestBuildCreateRequestMethodWithPathParameters.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/RestClientProviders/TestData/RestClientProviderTests/TestBuildCreateRequestMethodWithMixedPathAndQueryInPath.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/RestClientProviders/TestData/RestClientProviderTests/MultiServiceCombinedClient_GeneratesExpectedRestClient.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/RestClientProviders/TestData/RestClientProviderTests/ContentTypeHeaderWrappedInNullCheckWhenContentTypeIsOptional.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/RestClientProviders/TestData/RestClientProviderTests/ContentTypeHeaderWrappedInNullCheckWhenContentIsOptional.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/RestClientProviders/TestData/RestClientProviderTests/ContentTypeHeaderNotWrappedInNullCheckWhenContentIsRequired.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/XmlSerializationTests/XmlSerializationHandlesElementWithNamespace.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/XmlSerializationTests/XmlSerializationHandlesAttributeWithNamespace.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/XmlSerializationTests/XmlSerializationHandlesAttributeProperties.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/XmlSerializationTests/XmlSerializationForDiscriminatedSubtype.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/XmlSerializationTests/XmlSerializationForDiscriminatedBaseType.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/XmlSerializationTests/XmlOnlyModelGeneratesIPersistableModelMethods.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/XmlSerializationTests/SerializeXmlValueOverride_CustomTypeSerialization.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/XmlSerializationTests/PersistableModelWriteCoreHandlesXmlFormat.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/XmlSerializationTests/PersistableModelWriteCoreHandlesJsonAndXmlFormats.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/XmlSerializationCustomizationTests/CanSerializeCustomizedNullableDateTimeOffset.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/XmlSerializationCustomizationTests/CanCustomizeSerializationMethod.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/XmlSerializationCustomizationTests/CanCustomizeDeserializationMethodWithOptions.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/XmlSerializationCustomizationTests/CanCustomizeDeserializationMethod.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/XmlSerializationCustomizationTests/CanCustomizeAttributeSerializationMethod.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/XmlSerializationCustomizationTests/CanCustomizeAttributeDeserializationMethod.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/XmlSerializationCustomizationTests/CanChangePropertyName.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/XmlDeserializationTests/XmlDeserializationMethodHandlesOptionalUnwrappedListProperty.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/XmlDeserializationTests/XmlDeserializationHandlesElementWithNamespace.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/XmlDeserializationTests/XmlDeserializationHandlesAttributeWithNamespace.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/XmlDeserializationTests/XmlDeserializationHandlesAttributeProperties.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/XmlDeserializationTests/XmlDeserializationForDiscriminatedSubtype.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/XmlDeserializationTests/XmlDeserializationForDiscriminatedBaseType.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/XmlDeserializationTests/ExplicitOperatorForXmlOnlyModel.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/XmlDeserializationTests/ExplicitOperatorForJsonAndXmlModel.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/XmlDeserializationTests/DeserializeXmlValueOverride_CustomTypeDeserialization.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/SerializationCustomizationTests/CanCustomizeDeserializationMethodWithoutOptions.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/SerializationCustomizationTests/CanCustomizeDeserializationMethodWithOptions.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/ModelCustomizationTests/CanCustomizePropertyUsingField.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/ModelCustomizationTests/CanChangePropertyName.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/JsonModelCoreTests/SnakeCaseSerializedName.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/JsonModelCoreTests/PascalCaseSerializedName.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/JsonModelCoreTests/NonBodyPropertyKindsInModel.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/JsonModelCoreTests/MultipleAdditionalProperties.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/JsonModelCoreTests/KebabCaseSerializedName.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/JsonModelCoreTests/CamelCaseSerializedName.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/JsonModelCoreTests/BinaryDataAdditionalProperties.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/DynamicModelSerializationTests/WriteMultiplePrimitiveProperties.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/DynamicModelSerializationTests/WriteModelWithBinaryDataAdditionalPropsBackCompat/DynamicModel.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/DynamicModelSerializationTests/WriteModelWithAdditionalProperties.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/DynamicModelSerializationTests/WriteDynamicDerivedModelWithNonDiscriminatedBase.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/DynamicModelSerializationTests/WriteDiscriminatedDerivedModel.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/DynamicModelSerializationTests/WriteDiscriminatedBaseModel.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/DynamicModelSerializationTests/WriteDerivedModel.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/DynamicModelSerializationTests/WriteBaseModel.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/DynamicModelSerializationTests/PropagateModelProperty.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/DynamicModelSerializationTests/PropagateModelListProperty.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/DynamicModelSerializationTests/PropagateModelDictionaryProperty.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/DynamicModelSerializationTests/PropagateIncludesBaseDynamicProperties.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/DynamicModelSerializationTests/PropagateDerivedDynamicPropertiesWithNonDynamicBase.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/DynamicModelSerializationTests/PropagateCustomizedDynamicPropertyMixed.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/DynamicModelSerializationTests/PropagateCustomizedDynamicProperty.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/DynamicModelSerializationTests/PropagateCustomizedDynamicListPropertyMixed.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/DynamicModelSerializationTests/PropagateCustomizedDynamicListProperty.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/DynamicModelSerializationTests/ExplicitClientResultOperator(True).cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/DynamicModelSerializationTests/ExplicitClientResultOperator(False).cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/DynamicModelSerializationTests/DeserializeMultiplePrimitiveProperties.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/DynamicModelSerializationTests/DeserializeModelWithBinaryDataAdditionalPropsBackCompat/DynamicModel.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/DynamicModelSerializationTests/DeserializeModelWithBinaryDataAdditionalPropsBackCompat.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/DynamicModelSerializationTests/DeserializeModelWithAP.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/DynamicModelSerializationTests/DeserializeModelPropertyType.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/DynamicModelSerializationTests/DeserializeDynamicDerivedModelWithNonDiscriminatedBase.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/DeserializationTests/DeserializeStruct.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/EnumProvider/TestData/SerializationCustomizationTests/CanChangeEnumMemberName.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/Definitions/TestData/PipelineRequestHeadersExtensionsDefinitionTests/ValidateAddMethodIsGenerated.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/Definitions/TestData/ModelSerializationExtensionsDefinitionTests/ValidateTryGetIndex.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/Definitions/TestData/ModelSerializationExtensionsDefinitionTests/ValidateSliceToStartOfPropertyName.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/Definitions/TestData/ModelSerializationExtensionsDefinitionTests/ValidateGetUtf8Bytes.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/Definitions/TestData/ModelSerializationExtensionsDefinitionTests/ValidateGetRemainder.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/Definitions/TestData/ModelSerializationExtensionsDefinitionTests/ValidateGetFirstPropertyName.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/Definitions/TestData/ModelReaderWriterContextDefinitionTests/ValidateObsoleteGeneratedTypeHasAttributeSuppression.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/Definitions/TestData/ModelReaderWriterContextDefinitionTests/ValidateObsoleteFrameworkTypeHasAttributeSuppression.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/Definitions/TestData/ModelReaderWriterContextDefinitionTests/ValidateCustomObsoleteTypeHasAttributeSuppression.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/Definitions/TestData/ModelReaderWriterContextDefinitionTests/NullableValueTypesAreHandledCorrectly.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/Definitions/TestData/ModelReaderWriterContextDefinitionTests/ExperimentalModelsHaveAttributeSuppression.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/Definitions/TestData/ModelReaderWriterContextDefinitionTests/ExperimentalDependencyModelHaveAttributeSuppressions.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/Definitions/TestData/ModelReaderWriterContextDefinitionTests/CustomizedExperimentalModelsHaveAttributeSuppressions.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NextLinkInHeaderAsync.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NextLinkInHeader.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NextLinkInBody.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/NestedNextLinkInBody.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/NextLinkTests/InheritedNextLinkInBody.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/ListPageableTests/NoNextLinkOrContinuationTokenOfTAsync.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/ListPageableTests/NoNextLinkOrContinuationTokenOfT.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/ListPageableTests/NoNextLinkOrContinuationTokenAsync.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/ListPageableTests/NoNextLinkOrContinuationToken.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/NestedContinuationTokenInBody.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/ContinuationTokenInHeaderAsync.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/ContinuationTokenInHeader.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/ContinuationTokenInBodyAsync.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/CollectionResultDefinitions/TestData/ContinuationTokenTests/ContinuationTokenInBody.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ClientProviders/TestData/ClientProviderTests/ValidateQueryParamWriterDiff(True).cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ClientProviders/TestData/ClientProviderTests/ValidateQueryParamWriterDiff(False).cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ClientProviders/TestData/ClientProviderTests/ValidateConstructorsWhenUnsupportedAuth.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ClientProviders/TestData/ClientProviderTests/TestNonBodyRequestParametersInBodyWriterDiff(WithQueryInRequestBody).cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ClientProviders/TestData/ClientProviderTests/TestNonBodyRequestParametersInBodyWriterDiff(WithPathInRequestBody).cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ClientProviders/TestData/ClientProviderTests/TestNonBodyRequestParametersInBodyWriterDiff(WithMixedParametersInRequestBody).cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ClientProviders/TestData/ClientProviderTests/TestNonBodyRequestParametersInBodyWriterDiff(WithHeaderInRequestBody).cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ClientProviders/TestData/ClientProviderSubClientTests/SubClientWithSingleSubClient.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ClientProviders/TestData/ClientProviderSubClientTests/SubClientWithMultipleSubClients.cs | Update golden output to reflect short type names. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ClientProviders/TestData/ClientProviderSubClientTests/ServiceClientWithSubClient.cs | Update golden output to reflect short type names. |
| cspell.yaml | Add “crefs” to dictionary to avoid spellcheck noise from new terminology. |
| @@ -950,7 +980,23 @@ public string ToString(bool header) | |||
| if (totalLength == 0) | |||
| return string.Empty; | |||
|
|
|||
| var builder = new StringBuilder((int)totalLength); | |||
| // Materialize body into a single contiguous string so we can rewrite global::Namespace.HeadName | |||
| // references to short forms. Allocates the final string in one shot via string.Create instead | |||
| // of going through a StringBuilder middleman. | |||
| // Only shorten when emitting a full file (header == true) - otherwise we'd return short | |||
| // names without the matching using directives, which is invalid C# and breaks in-process | |||
| // expression composition (e.g. CSharpType.ToString, MethodBodyStatement.ToString). | |||
| string bodyText = string.Create((int)totalLength, reader, static (span, r) => r.CopyTo(span)); | |||
| if (header) | |||
There was a problem hiding this comment.
_builder.ExtractReader() transfers ownership of pooled buffers to the returned Reader, but ToString(bool header) never disposes that reader. This will prevent ArrayPool<char> buffers from being returned (potentially a major memory/pool leak during generation). Dispose the reader (e.g., via a using scope) after materializing the string.
There was a problem hiding this comment.
Good catch — fixed in b3f508e. Wrapped the reader in using so its pooled buffers get returned.
| if (totalLength == 0) | ||
| return string.Empty; | ||
|
|
||
| var builder = new StringBuilder((int)totalLength); | ||
| // Materialize body into a single contiguous string so we can rewrite global::Namespace.HeadName | ||
| // references to short forms. Allocates the final string in one shot via string.Create instead | ||
| // of going through a StringBuilder middleman. | ||
| // Only shorten when emitting a full file (header == true) - otherwise we'd return short | ||
| // names without the matching using directives, which is invalid C# and breaks in-process | ||
| // expression composition (e.g. CSharpType.ToString, MethodBodyStatement.ToString). | ||
| string bodyText = string.Create((int)totalLength, reader, static (span, r) => r.CopyTo(span)); | ||
| if (header) | ||
| { |
There was a problem hiding this comment.
reader.Length is a long, but string.Create((int)totalLength, ...) truncates/can overflow for very large generated outputs. Consider guarding with an explicit totalLength > int.MaxValue check and throwing a clear exception (similar to Reader.ToBinaryData) before casting.
There was a problem hiding this comment.
Fixed in b3f508e — added an explicit totalLength > int.MaxValue check that throws InvalidOperationException (matching the pattern in Reader.ToBinaryData) before the cast.
| // Tracing for Simplifier.ReduceAsync cost. See https://github.com/microsoft/typespec/issues/10424. | ||
| private static long _reduceTicks; | ||
| private static int _reduceCount; |
There was a problem hiding this comment.
_reduceTicks/_reduceCount are static and never reset, so successive generator runs (or multiple workspaces in the same process, e.g. unit tests) will accumulate counts and report misleading per-run timings. Reset these counters at the start of a post-processing run (or make them instance fields) so the log reflects the current execution.
There was a problem hiding this comment.
Fixed in b3f508e — reset both counters with Interlocked.Exchange at the start of GetGeneratedFilesAsync so each post-processing run reports its own timings. Kept them static since they're aggregated across parallel ProcessDocument tasks.
| // ShortenQualifiedNames rewrite intentionally leaves these alone so Roslyn's Simplifier can | ||
| // handle the cref reduction natively (and preserve cref-specific annotations like `?`); we | ||
| // swap them back to "global::" right before returning the body. | ||
| private const string _globalDocSentinel = "global!doc::"; |
There was a problem hiding this comment.
This isn't using the correct naming convention for a const.
There was a problem hiding this comment.
Fixed in b3f508e — renamed to GlobalDocSentinel.
…rename const - Dispose UnsafeBufferSequence.Reader in CodeWriter.ToString so pooled ArrayPool<char> buffers are returned to the pool. - Throw a clear InvalidOperationException when the generated file would overflow int.MaxValue characters before casting to (int) for string.Create. - Reset _reduceTicks/_reduceCount at the start of each post-processing run so logged timings reflect only the current execution. - Rename _globalDocSentinel to GlobalDocSentinel (PascalCase const). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The PR's CodeWriter pre-shortening rewrote global::Other.Ns.X to bare X across the board. When a project also referenced an external assembly contributing the same namespace (e.g. the OpenAI NuGet package matching generated OpenAI.* types in Azure.AI.Projects.Agents), SymbolFinder.FindReferencesAsync in PostProcessor.RemoveAsync could miss references to the local symbol and incorrectly prune the type. Restrict textual shortening in CodeWriter.ShortenQualifiedNames to references that are always safe: - Same namespace or an ancestor of the current namespace (C# scoping rules make these visible by the unqualified name). - System.* references (well-known, with intra-System collision handling). All other cross-namespace references are left as \global::Ns.X\ for Roslyn's Simplifier to handle during post-processing - it has access to the full SemanticModel including external assemblies and correctly accounts for collisions and visibility. Update test goldens for non-System cross-namespace references to expect the fully-qualified form; Simplifier reduces these in real output so the generated code is unchanged. Add CodeWriterTests.ShortenQualifiedNames_DoesNotShortenNonSystemCrossNamespaceReferences regression test. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
When a type's head name matches a segment of the current namespace, the simple name binds to the namespace rather than the type. For example, inside namespace Payload.Pageable._ServerDrivenPagination.ContinuationToken, a bare ContinuationToken resolves to the enclosing namespace, producing CS0118 ('namespace used like a type').
Leave such references as global::Ns.X so Roslyn's Simplifier can disambiguate them with the full SemanticModel.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The previous fix only checked segments of the current namespace, but a bare type name can also bind to a sibling namespace through ancestor scopes. For example, inside Payload.Pageable._ServerDrivenPagination.Link, a bare 'ContinuationToken' resolves to the sibling Payload.Pageable._ServerDrivenPagination.ContinuationToken namespace and produces CS0118. Expand the collision set to include every distinct namespace segment across the project's TypeProviders. This is a safe over-approximation: keeping more refs as global::Ns.X just means Roslyn's Simplifier resolves them with the full SemanticModel. Cached per OutputLibrary instance so the cost is paid once per generation run. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
| // expression composition (e.g. CSharpType.ToString, MethodBodyStatement.ToString). | ||
| if (totalLength > int.MaxValue) | ||
| { | ||
| throw new InvalidOperationException( |
There was a problem hiding this comment.
should we just log an error and skip the file vs throwing ?
There was a problem hiding this comment.
I think this is enough of an exceptional case that we can throw
| // since SymbolFinder.FindReferencesAsync can miss references when the text resolves | ||
| // ambiguously (e.g. a generated `OpenAI.X` type referenced by simple name in a | ||
| // project that also imports the OpenAI NuGet namespace). | ||
| string[]? currentParts = _currentNamespace?.Split('.'); |
There was a problem hiding this comment.
copilot really goes crazy with these comments 😄
The CodeWriter pre-shortening approach (emitting short type names from CodeWriter to reduce Roslyn Simplifier.ReduceAsync work) introduced significant complexity and edge cases (namespace-segment shadowing, member shadowing, partial-type collisions) that were not worth the modest perf gain. It also broke Azure ETag/AzureLocation serialization patches because reading SerializationProviders during the writer phase forced lazy-build before patches were applied. This reverts all CodeWriter, OutputLibrary, TypeProviderWriter, PostProcessor, UnsafeBufferSequence.Reader changes and the associated test golden updates back to upstream/main, restoring the simpler model where Roslyn Simplifier handles all reference simplification. Kept the per-call Stopwatch tracing for Simplifier.ReduceAsync in GeneratedCodeWorkspace.cs as a useful diagnostic. See microsoft#10424. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This reverts commit 02f44bc.
… Simplifier" This reverts commit f77975d.
- Remove cross-namespace shortening skip in CodeWriter.ShortenQualifiedNames. All cross-namespace references (not just System.*) are now shortened to bare names given a using directive, with head-collision and namespace-segment collision detection applied across all namespaces. - Add supplemental syntax-tree scan in ReferenceMapBuilder that walks each document once and attributes identifier references to target symbols via Symbol and CandidateSymbols. This backs up SymbolFinder.FindReferencesAsync, which can miss references when an external assembly contributes the same namespace as a generated type (the compiler may expose our symbol only via SymbolInfo.CandidateSymbols), previously causing PostProcessor.RemoveAsync to prune types incorrectly. - Update test goldens to reflect the re-enabled cross-namespace shortening (bare names instead of global::Ns.Type forms); leave cref attributes fully qualified since CodeWriter intentionally does not shorten crefs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
| // produce CS0118; we use this to keep such references fully qualified so Simplifier | ||
| // can resolve them with the full SemanticModel. | ||
| private static IReadOnlyCollection<string>? _projectNamespaceSegments; | ||
| private static object? _projectNamespaceSegmentsKey; |
There was a problem hiding this comment.
Do we need this key? Are unit tests failing without it?
| private static IReadOnlyCollection<string>? ComputeProjectNamespaceSegments() | ||
| { | ||
| var generator = CodeModelGenerator.Instance; | ||
| if (generator?.OutputLibrary is not { AreTypeProvidersBuilt: true } outputLibrary) |
There was a problem hiding this comment.
Do we need AreTypeProvidersBuilt? If this is just for unit tests we should not do this.
Massively reduces C# emitter post-processing cost by emitting short type names directly from CodeWriter, so Roslyn's Simplifier.ReduceAsync (which used to dominate emit time via per-name SemanticModel lookups under the compilation lock) does almost no work.
Changes
(namespace, headName)pair emitted asglobal::Namespace.Typein _emittedTypeRefs. In ToString(true), rewrite the body so:global::Namespace.Typefor Roslyn's Simplifier to handle. Simplifier has access to the full SemanticModel including external assemblies (e.g. NuGet packages) and can correctly account for collisions and visibility that a purely textual rewriter cannot. This also keeps PostProcessor.RemoveAsync's reference search reliable — SymbolFinder.FindReferencesAsync can miss references when a textually-short name resolves ambiguously between a generated type and an external assembly contributing the same namespace (e.g. a generated OpenAI.X type in a project that also imports the OpenAI NuGet namespace).ContinuationTokeninside namespaceFoo._Pagination.ContinuationTokenwould bind to the enclosing namespace rather than the type (CS0118).global!doc::sentinel during emission and is swapped back toglobal::at the end so Roslyn's cref-aware reducer can normalize the cref signature itself (preserves?nullability annotations on parameter types).global::Ns.X; Simplifier reduces these in real output so the generated code is unchanged.Perf impact
Measured on Azure.AI.Projects (884 generated files), wall-clock for
px tsp-client generate (each run preceded by sp-client sync; includes a ~17 s
pm ci overhead common to both):
1.0.0-alpha.20260417.10)Subtracting the ~17 s
npm cioverhead, emit-only goes from ~48 s →32 s (1.5×). The post-processing cost (RoslynNameReducerwalking everyNameSyntaxwith aSemanticModellookup per name under the compilation lock) collapses to a near-noop because the names are already short.Speedup is smaller than originally measured (~1.7×) because the final shortening rules are deliberately conservative — restricted to same/ancestor namespace and
System.*refs, and skipped when a head name collides with a current-namespace segment — to avoid a class of correctness issues:PostProcessor.RemoveAsyncpruning local types that share a namespace name with an external NuGet assembly (uncovered while regeneratingAzure.AI.Projects.Agents).payload/pageable).See #10424 for the broader perf analysis.