Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid more large string constant fields #74307

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Compilers/Test/Core/InstrumentationChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private static string GetTermination(int index, int length)
return (index == length - 1) ? ";" : "";
}

public const string InstrumentationHelperSource = @"
public static readonly string InstrumentationHelperSource = @"
namespace Microsoft.CodeAnalysis.Runtime
{
public static class Instrumentation
Expand Down Expand Up @@ -216,8 +216,7 @@ private static string GetTermination(int index, int length)
return (index == length - 1) ? "" : ".";
}

public static readonly XElement InstrumentationHelperSource = new XElement("file", new XAttribute("name", "c.vb"), InstrumentationHelperSourceStr);
public const string InstrumentationHelperSourceStr = @"
public static readonly string InstrumentationHelperSourceStr = @"
Namespace Microsoft.CodeAnalysis.Runtime

Public Class Instrumentation
Expand Down Expand Up @@ -271,6 +270,7 @@ End Function
End Class
End Namespace
";
public static readonly XElement InstrumentationHelperSource = new XElement("file", new XAttribute("name", "c.vb"), InstrumentationHelperSourceStr);
}

public abstract class BaseInstrumentationChecker
Expand Down
64 changes: 32 additions & 32 deletions src/Compilers/Test/Utilities/CSharp/CSharpTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace Microsoft.CodeAnalysis.CSharp.Test.Utilities
{
public abstract class CSharpTestBase : CommonTestBase
{
protected const string NullableAttributeDefinition = @"
protected static readonly string NullableAttributeDefinition = @"
namespace System.Runtime.CompilerServices
{
[System.AttributeUsage(AttributeTargets.Event | // The type of the event is nullable, or has a nullable reference type as one of its constituents
Expand All @@ -60,7 +60,7 @@ public NullableAttribute(byte[] transformFlags)
}
";

protected const string NullableContextAttributeDefinition = @"
protected static readonly string NullableContextAttributeDefinition = @"
namespace System.Runtime.CompilerServices
{
[System.AttributeUsage(
Expand All @@ -81,7 +81,7 @@ public NullableContextAttribute(byte flag)
}
}";

protected const string NullablePublicOnlyAttributeDefinition = @"
protected static readonly string NullablePublicOnlyAttributeDefinition = @"
namespace System.Runtime.CompilerServices
{
[System.AttributeUsage(AttributeTargets.Module, AllowMultiple = false)]
Expand All @@ -97,7 +97,7 @@ public NullablePublicOnlyAttribute(bool includesInternals)

// Nullable flow analysis attributes are defined at
// https://github.com/dotnet/coreclr/blob/4a1275434fff99206f2a28f5f0e87f124069eb7f/src/System.Private.CoreLib/shared/System/Diagnostics/CodeAnalysis/NullableAttributes.cs
protected const string AllowNullAttributeDefinition = @"
protected static readonly string AllowNullAttributeDefinition = @"
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property)]
Expand All @@ -106,7 +106,7 @@ public sealed class AllowNullAttribute : Attribute
}
}";

protected const string DisallowNullAttributeDefinition = @"
protected static readonly string DisallowNullAttributeDefinition = @"
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property)]
Expand All @@ -115,7 +115,7 @@ public sealed class DisallowNullAttribute : Attribute
}
}";

protected const string MaybeNullAttributeDefinition = @"
protected static readonly string MaybeNullAttributeDefinition = @"
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue)]
Expand All @@ -125,7 +125,7 @@ public sealed class MaybeNullAttribute : Attribute
}
";

protected const string MaybeNullWhenAttributeDefinition = @"
protected static readonly string MaybeNullWhenAttributeDefinition = @"
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)]
Expand All @@ -136,7 +136,7 @@ public MaybeNullWhenAttribute(bool when) { }
}
";

protected const string NotNullAttributeDefinition = @"
protected static readonly string NotNullAttributeDefinition = @"
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue)]
Expand All @@ -146,7 +146,7 @@ public sealed class NotNullAttribute : Attribute
}
";

protected const string NotNullWhenAttributeDefinition = @"
protected static readonly string NotNullWhenAttributeDefinition = @"
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)]
Expand All @@ -157,7 +157,7 @@ public NotNullWhenAttribute(bool when) { }
}
";

protected const string MemberNotNullAttributeDefinition = @"
protected static readonly string MemberNotNullAttributeDefinition = @"
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = true)]
Expand All @@ -169,7 +169,7 @@ public MemberNotNullAttribute(string member) { }
}
";

protected const string MemberNotNullWhenAttributeDefinition = @"
protected static readonly string MemberNotNullWhenAttributeDefinition = @"
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = true)]
Expand All @@ -181,7 +181,7 @@ public MemberNotNullWhenAttribute(bool when, string member) { }
}
";

protected const string DoesNotReturnIfAttributeDefinition = @"
protected static readonly string DoesNotReturnIfAttributeDefinition = @"
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)]
Expand All @@ -192,7 +192,7 @@ public DoesNotReturnIfAttribute(bool condition) { }
}
";

protected const string DoesNotReturnAttributeDefinition = @"
protected static readonly string DoesNotReturnAttributeDefinition = @"
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
Expand All @@ -203,7 +203,7 @@ public DoesNotReturnAttribute() { }
}
";

protected const string NotNullIfNotNullAttributeDefinition = @"
protected static readonly string NotNullIfNotNullAttributeDefinition = @"
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)]
Expand All @@ -214,7 +214,7 @@ public NotNullIfNotNullAttribute(string parameterName) { }
}
";

protected const string IsExternalInitTypeDefinition = @"
protected static readonly string IsExternalInitTypeDefinition = @"
namespace System.Runtime.CompilerServices
{
public static class IsExternalInit
Expand All @@ -223,7 +223,7 @@ public static class IsExternalInit
}
";

protected const string IAsyncDisposableDefinition = @"
protected static readonly string IAsyncDisposableDefinition = @"
namespace System
{
public interface IAsyncDisposable
Expand All @@ -233,7 +233,7 @@ public interface IAsyncDisposable
}
";

protected const string NonDisposableAsyncEnumeratorDefinition = @"
protected static readonly string NonDisposableAsyncEnumeratorDefinition = @"
#nullable disable

namespace System.Collections.Generic
Expand All @@ -246,7 +246,7 @@ public interface IAsyncEnumerator<out T>
}
";

protected const string DisposableAsyncEnumeratorDefinition = @"
protected static readonly string DisposableAsyncEnumeratorDefinition = @"
#nullable disable

namespace System.Collections.Generic
Expand All @@ -259,9 +259,7 @@ public interface IAsyncEnumerator<out T> : System.IAsyncDisposable
}
" + IAsyncDisposableDefinition;

protected const string AsyncStreamsTypes = DisposableAsyncEnumeratorDefinition + CommonAsyncStreamsTypes;

protected const string CommonAsyncStreamsTypes = @"
protected static readonly string CommonAsyncStreamsTypes = @"
#nullable disable

namespace System.Collections.Generic
Expand Down Expand Up @@ -590,7 +588,9 @@ public void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter
}
";

protected const string EnumeratorCancellationAttributeType = @"
protected static readonly string AsyncStreamsTypes = DisposableAsyncEnumeratorDefinition + CommonAsyncStreamsTypes;

protected static readonly string EnumeratorCancellationAttributeType = @"
namespace System.Runtime.CompilerServices
{
[System.AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)]
Expand All @@ -601,7 +601,7 @@ public EnumeratorCancellationAttribute() { }
}
";

protected const string NativeIntegerAttributeDefinition =
protected static readonly string NativeIntegerAttributeDefinition =
@"using System.Collections.Generic;
namespace System.Runtime.CompilerServices
{
Expand Down Expand Up @@ -629,7 +629,7 @@ public NativeIntegerAttribute(bool[] flags)
}
}";

protected const string UnmanagedCallersOnlyAttributeDefinition =
protected static readonly string UnmanagedCallersOnlyAttributeDefinition =
@"namespace System.Runtime.InteropServices
{
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
Expand All @@ -641,7 +641,7 @@ public UnmanagedCallersOnlyAttribute() { }
}
}";

protected const string UnscopedRefAttributeDefinition =
protected static readonly string UnscopedRefAttributeDefinition =
@"namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = false)]
Expand All @@ -650,7 +650,7 @@ public sealed class UnscopedRefAttribute : Attribute
}
}";

protected const string RefSafetyRulesAttributeDefinition =
protected static readonly string RefSafetyRulesAttributeDefinition =
@"namespace System.Runtime.CompilerServices
{
public sealed class RefSafetyRulesAttribute : Attribute
Expand All @@ -663,7 +663,7 @@ public sealed class RefSafetyRulesAttribute : Attribute
protected static MetadataReference RefSafetyRulesAttributeLib =>
CreateCompilation(RefSafetyRulesAttributeDefinition).EmitToImageReference();

protected const string RequiredMemberAttribute = @"
protected static readonly string RequiredMemberAttribute = @"
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Field | AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
Expand All @@ -676,7 +676,7 @@ public RequiredMemberAttribute()
}
";

protected const string SetsRequiredMembersAttribute = @"
protected static readonly string SetsRequiredMembersAttribute = @"
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Constructor, Inherited = false, AllowMultiple = false)]
Expand All @@ -689,7 +689,7 @@ public SetsRequiredMembersAttribute()
}
";

internal const string CompilerFeatureRequiredAttribute = """
internal static readonly string CompilerFeatureRequiredAttribute = """
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
Expand All @@ -705,7 +705,7 @@ public CompilerFeatureRequiredAttribute(string featureName)
}
""";

internal const string CollectionBuilderAttributeDefinition = """
internal static readonly string CollectionBuilderAttributeDefinition = """
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = false)]
Expand Down Expand Up @@ -2445,7 +2445,7 @@ void appendNonDefaultVariantsWithGenericAndType(string type, string generic, boo
}
}

internal const string InterpolatedStringHandlerAttribute = @"
internal static readonly string InterpolatedStringHandlerAttribute = @"
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false, Inherited = false)]
Expand Down Expand Up @@ -2503,7 +2503,7 @@ public static void Normalize()
" + (includeOneTimeHelpers ? InterpolatedStringHandlerAttribute + cultureInfoHandler : "");
}

internal const string InterpolatedStringHandlerArgumentAttribute = @"
internal static readonly string InterpolatedStringHandlerArgumentAttribute = @"
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/Test/Utilities/CSharp/CompilingTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ internal static BoundBlock ParseAndBindMethodBody(string program, string typeNam
return block;
}

public const string LINQ =
public static readonly string LINQ =
#region the string LINQ defines a complete LINQ API called List1<T> (for instance method) and List2<T> (for extension methods)
@"using System;
using System.Text;
Expand Down