From 5841b3b30d7c9cd3b882d4a636c4bde6454a6b5e Mon Sep 17 00:00:00 2001 From: VSadov Date: Tue, 24 Mar 2015 15:31:07 -0700 Subject: [PATCH 1/2] Changed generation of PrivateImplementationDetails to append module name only when dealing with netmudules. The goal of module name apending is to avoid clashes when combining multiple netmodules into multifile assembly. When building a regular assembly, appending module name is not serving any purpose and just causes unnecessary metadata differences. Also in this change - when we do apend the module name, replace '.' with '_' when that happens. For example when we build a netmodule and its name is Foo.Bar.dll More complicated name mangling schemes were discussed, but at this point we will do a simple '.' --> '_' as the least destabilizing change which is still sufficient in the most common case of having dots in the module name. Fixes #1430 --- .../AnonymousTypeManager.Templates.cs | 2 +- .../Test/Emit/CodeGen/CodeGenForEachTests.cs | 2 +- .../CSharp/Test/Emit/CodeGen/CodeGenTests.cs | 38 +++++++++---------- .../CSharp/Test/Emit/CodeGen/IndexerTests.cs | 16 ++++---- .../CSharp/Test/Emit/CodeGen/SwitchTests.cs | 2 +- .../EditAndContinue/EditAndContinueTests.cs | 6 +-- .../CSharp/Test/Emit/PDB/PDBTests.cs | 2 +- .../WinRT/CodeGen/WinRTCollectionTests.cs | 2 +- .../CodeGen/PrivateImplementationDetails.cs | 19 ++++++++-- .../InternalUtilities/StringExtensions.cs | 14 +++++++ .../Test/Emit/CodeGen/CodeGenForeach.vb | 6 +-- .../CodeGen/CodeGenMultiDimensionalArray.vb | 4 +- .../Test/Emit/CodeGen/CodeGenTests.vb | 16 ++++---- .../Test/Emit/CodeGen/WinRTCollectionTests.vb | 2 +- .../EditAndContinue/EditAndContinueTests.vb | 6 +-- .../ExpressionCompilerTests.cs | 2 +- .../ExpressionCompilerTests.vb | 2 +- 17 files changed, 83 insertions(+), 58 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/AnonymousTypes/AnonymousTypeManager.Templates.cs b/src/Compilers/CSharp/Portable/Symbols/AnonymousTypes/AnonymousTypeManager.Templates.cs index 08c181356e15c..2865e6738e420 100644 --- a/src/Compilers/CSharp/Portable/Symbols/AnonymousTypes/AnonymousTypeManager.Templates.cs +++ b/src/Compilers/CSharp/Portable/Symbols/AnonymousTypes/AnonymousTypeManager.Templates.cs @@ -293,7 +293,7 @@ public void AssignTemplatesNamesAndCompile(MethodCompiler compiler, PEModuleBuil moduleId = moduleId.Substring(0, moduleId.Length - extension.Length); } - moduleId = moduleId.Replace('.', '_'); + moduleId = moduleId.MangleForTypeNameIfNeeded(); } else { diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenForEachTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenForEachTests.cs index bbb723932afb3..b4b7b46f30ed3 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenForEachTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenForEachTests.cs @@ -121,7 +121,7 @@ .locals init (double[,] V_0, IL_0001: ldc.i4.4 IL_0002: newobj ""double[*,*]..ctor"" IL_0007: dup - IL_0008: ldtoken "".__StaticArrayInitTypeSize=64 .E19C080DB8DAB85AF7CA3EF40FFB01B0778F9D25"" + IL_0008: ldtoken "".__StaticArrayInitTypeSize=64 .E19C080DB8DAB85AF7CA3EF40FFB01B0778F9D25"" IL_000d: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_0012: stloc.0 IL_0013: ldloc.0 diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs index edab06bd0e764..248f531a74a7d 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs @@ -3241,7 +3241,7 @@ .locals init (int[] V_0) //arr IL_0000: ldc.i4.4 IL_0001: newarr ""int"" IL_0006: dup - IL_0007: ldtoken ""<MODULE>.__StaticArrayInitTypeSize=16 <MODULE>.42F1B77334EDFA917032CCF8353020C73F8C62E1"" + IL_0007: ldtoken "".__StaticArrayInitTypeSize=16 .42F1B77334EDFA917032CCF8353020C73F8C62E1"" IL_000c: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_0011: stloc.0 IL_0012: ldloc.0 @@ -3560,7 +3560,7 @@ static void Main() "); #region IL - // Can NOT compare IL because the Guid is different every time - {a6c2d596-042b-4294-99ab-d34a2758ec15} + // Can NOT compare IL because the Guid is different every time - {a6c2d596-042b-4294-99ab-d34a2758ec15} #if false compilation.VerifyIL("MyArray.Main", @"{ @@ -3594,7 +3594,7 @@ .locals init (sbyte[] V_0, //a1 IL_0028: ldc.i4.3 IL_0029: newarr ""byte"" IL_002e: dup - IL_002f: ldtoken ""{a6c2d596-042b-4294-99ab-d34a2758ec15}.__StaticArrayInitTypeSize=3 {a6c2d596-042b-4294-99ab-d34a2758ec15}.0"" + IL_002f: ldtoken ""{a6c2d596-042b-4294-99ab-d34a2758ec15}.__StaticArrayInitTypeSize=3 {a6c2d596-042b-4294-99ab-d34a2758ec15}.0"" IL_0034: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_0039: ldc.i4.0 IL_003a: ldelem.u1 @@ -3620,7 +3620,7 @@ .locals init (sbyte[] V_0, //a1 IL_005f: ldc.i4.3 IL_0060: newarr ""short"" IL_0065: dup - IL_0066: ldtoken ""{a6c2d596-042b-4294-99ab-d34a2758ec15}.__StaticArrayInitTypeSize=6 {a6c2d596-042b-4294-99ab-d34a2758ec15}.1"" + IL_0066: ldtoken ""{a6c2d596-042b-4294-99ab-d34a2758ec15}.__StaticArrayInitTypeSize=6 {a6c2d596-042b-4294-99ab-d34a2758ec15}.1"" IL_006b: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_0070: stelem.ref IL_0071: ldc.i4.1 @@ -6406,7 +6406,7 @@ .maxstack 3 IL_0000: ldc.i4.5 IL_0001: newarr ""int"" IL_0006: dup - IL_0007: ldtoken "".__StaticArrayInitTypeSize=20 .56C14CB445C628421AC674599E302B0879FB496F"" + IL_0007: ldtoken "".__StaticArrayInitTypeSize=20 .56C14CB445C628421AC674599E302B0879FB496F"" IL_000c: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_0011: dup IL_0012: ldc.i4.2 @@ -6418,7 +6418,7 @@ .maxstack 3 IL_0020: ldc.i4.5 IL_0021: newarr ""bool"" IL_0026: dup - IL_0027: ldtoken "".__StaticArrayInitTypeSize=5 .4E724558F6B816715597A51663AD8F05247E2C4A"" + IL_0027: ldtoken "".__StaticArrayInitTypeSize=5 .4E724558F6B816715597A51663AD8F05247E2C4A"" IL_002c: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_0031: dup IL_0032: ldc.i4.2 @@ -6430,7 +6430,7 @@ .maxstack 3 IL_0040: ldc.i4.5 IL_0041: newarr ""byte"" IL_0046: dup - IL_0047: ldtoken "".__StaticArrayInitTypeSize=5 .9755240DD0C4C1AD226DEBD40C6D2EBD408250CB"" + IL_0047: ldtoken "".__StaticArrayInitTypeSize=5 .9755240DD0C4C1AD226DEBD40C6D2EBD408250CB"" IL_004c: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_0051: dup IL_0052: ldc.i4.2 @@ -6442,7 +6442,7 @@ .maxstack 3 IL_0060: ldc.i4.5 IL_0061: newarr ""char"" IL_0066: dup - IL_0067: ldtoken "".__StaticArrayInitTypeSize=10 .E313A2813013780396D58750DC5D62221C86F42F"" + IL_0067: ldtoken "".__StaticArrayInitTypeSize=10 .E313A2813013780396D58750DC5D62221C86F42F"" IL_006c: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_0071: dup IL_0072: ldc.i4.2 @@ -6454,7 +6454,7 @@ .maxstack 3 IL_0080: ldc.i4.5 IL_0081: newarr ""float"" IL_0086: dup - IL_0087: ldtoken "".__StaticArrayInitTypeSize=20 .2F3DD953DBFB23217E7CE0E76630EBD31267E237"" + IL_0087: ldtoken "".__StaticArrayInitTypeSize=20 .2F3DD953DBFB23217E7CE0E76630EBD31267E237"" IL_008c: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_0091: dup IL_0092: ldc.i4.2 @@ -6466,7 +6466,7 @@ .maxstack 3 IL_00a0: ldc.i4.5 IL_00a1: newarr ""double"" IL_00a6: dup - IL_00a7: ldtoken "".__StaticArrayInitTypeSize=40 .11F3436B917FFBA0FAB0FAD5563AF18FA24AC16A"" + IL_00a7: ldtoken "".__StaticArrayInitTypeSize=40 .11F3436B917FFBA0FAB0FAD5563AF18FA24AC16A"" IL_00ac: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_00b1: dup IL_00b2: ldc.i4.2 @@ -6500,7 +6500,7 @@ public static void Main() } "; var compilation = CompileAndVerify(source, options: TestOptions.ReleaseExe.WithModuleName("MODULE"), expectedOutput: @"3-5"); - //string pid = "" + compilation.Compilation.SourceModule.Pers + //string pid = "" + compilation.Compilation.SourceModule.Pers compilation.VerifyIL("D.Main", @"{ // Code size 73 (0x49) @@ -6509,7 +6509,7 @@ .locals init (int[] V_0) //x IL_0000: ldc.i4.5 IL_0001: newarr ""int"" IL_0006: dup - IL_0007: ldtoken "".__StaticArrayInitTypeSize=20 .FF942E5F620FC460CF9424D564C73AD8A99C74EE"" + IL_0007: ldtoken "".__StaticArrayInitTypeSize=20 .FF942E5F620FC460CF9424D564C73AD8A99C74EE"" IL_000c: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_0011: dup IL_0012: ldc.i4.2 @@ -6524,7 +6524,7 @@ .locals init (int[] V_0) //x IL_0027: ldc.i4.5 IL_0028: newarr ""int"" IL_002d: dup - IL_002e: ldtoken "".__StaticArrayInitTypeSize=20 .89E37886EEEDC70AEF61138E037CC60EFC35535F"" + IL_002e: ldtoken "".__StaticArrayInitTypeSize=20 .89E37886EEEDC70AEF61138E037CC60EFC35535F"" IL_0033: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_0038: dup IL_0039: ldc.i4.4 @@ -6562,7 +6562,7 @@ public static void Main() } "; var compilation = CompileAndVerify(source, options: TestOptions.ReleaseExe.WithModuleName("MODULE"), expectedOutput: @"30"); - //string pid = "" + compilation.Compilation.SourceModule.Pers + //string pid = "" + compilation.Compilation.SourceModule.Pers compilation.VerifyIL("D.Main", @"{ // Code size 82 (0x52) @@ -6592,7 +6592,7 @@ .locals init (int[] V_0) //x IL_002e: ldc.i4.s 15 IL_0030: newarr ""int"" IL_0035: dup - IL_0036: ldtoken "".__StaticArrayInitTypeSize=60 .49608711F905702F9F227AA782F8B408777D5DF9"" + IL_0036: ldtoken "".__StaticArrayInitTypeSize=60 .49608711F905702F9F227AA782F8B408777D5DF9"" IL_003b: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_0040: dup IL_0041: ldc.i4.s 12 @@ -6728,7 +6728,7 @@ .maxstack 3 IL_0000: ldc.i4.5 IL_0001: newarr ""System.TypeCode"" IL_0006: dup - IL_0007: ldtoken "".__StaticArrayInitTypeSize=20 .3191FF614021ADF3122AC274EA5B6097C21BEB81"" + IL_0007: ldtoken "".__StaticArrayInitTypeSize=20 .3191FF614021ADF3122AC274EA5B6097C21BEB81"" IL_000c: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_0011: dup IL_0012: ldc.i4.1 @@ -7301,7 +7301,7 @@ .locals init (Program.C V_0, //obj IL_0085: ldc.i4.4 IL_0086: newarr ""ushort"" IL_008b: dup - IL_008c: ldtoken ""long .E9E8A66A117598333ABACF5B65971C2366E19B6C"" + IL_008c: ldtoken ""long .E9E8A66A117598333ABACF5B65971C2366E19B6C"" IL_0091: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_0096: callvirt ""uint Program.C.Foo(out short, params ushort[])"" IL_009b: call ""void System.Console.WriteLine(uint)"" @@ -7534,7 +7534,7 @@ .locals init (int[] V_0) //arr IL_0001: ldc.i4.5 IL_0002: newarr ""int"" IL_0007: dup - IL_0008: ldtoken "".__StaticArrayInitTypeSize=20 .1036C5F8EF306104BD582D73E555F4DAE8EECB24"" + IL_0008: ldtoken "".__StaticArrayInitTypeSize=20 .1036C5F8EF306104BD582D73E555F4DAE8EECB24"" IL_000d: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_0012: stloc.0 IL_0013: ret @@ -13047,7 +13047,7 @@ .maxstack 4 IL_0040: ldc.i4.4 IL_0041: newarr ""bool"" IL_0046: dup - IL_0047: ldtoken ""int .35CCB1599F52363510686EF38B7DB5E7998DB108"" + IL_0047: ldtoken ""int .35CCB1599F52363510686EF38B7DB5E7998DB108"" IL_004c: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_0051: ldc.i4.2 IL_0052: ldelem.u1 diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/IndexerTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/IndexerTests.cs index b4fdd4ba49411..3a275fed4a86b 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/IndexerTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/IndexerTests.cs @@ -458,7 +458,7 @@ .locals init (C V_0) //c IL_003f: ldc.i4.3 IL_0040: newarr ""int"" IL_0045: dup - IL_0046: ldtoken "".__StaticArrayInitTypeSize=12 .E429CCA3F703A39CC5954A6572FEC9086135B34E"" + IL_0046: ldtoken "".__StaticArrayInitTypeSize=12 .E429CCA3F703A39CC5954A6572FEC9086135B34E"" IL_004b: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_0050: callvirt ""int C.this[params int[]].get"" IL_0055: pop @@ -466,7 +466,7 @@ .locals init (C V_0) //c IL_0057: ldc.i4.3 IL_0058: newarr ""int"" IL_005d: dup - IL_005e: ldtoken "".__StaticArrayInitTypeSize=12 .E429CCA3F703A39CC5954A6572FEC9086135B34E"" + IL_005e: ldtoken "".__StaticArrayInitTypeSize=12 .E429CCA3F703A39CC5954A6572FEC9086135B34E"" IL_0063: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_0068: callvirt ""int C.this[params int[]].get"" IL_006d: pop @@ -606,7 +606,7 @@ .locals init (C V_0) //c IL_003f: ldc.i4.3 IL_0040: newarr ""int"" IL_0045: dup - IL_0046: ldtoken "".__StaticArrayInitTypeSize=12 .E429CCA3F703A39CC5954A6572FEC9086135B34E"" + IL_0046: ldtoken "".__StaticArrayInitTypeSize=12 .E429CCA3F703A39CC5954A6572FEC9086135B34E"" IL_004b: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_0050: ldc.i4.4 IL_0051: callvirt ""void C.this[params int[]].set"" @@ -614,7 +614,7 @@ .locals init (C V_0) //c IL_0057: ldc.i4.3 IL_0058: newarr ""int"" IL_005d: dup - IL_005e: ldtoken "".__StaticArrayInitTypeSize=12 .E429CCA3F703A39CC5954A6572FEC9086135B34E"" + IL_005e: ldtoken "".__StaticArrayInitTypeSize=12 .E429CCA3F703A39CC5954A6572FEC9086135B34E"" IL_0063: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_0068: ldc.i4.4 IL_0069: callvirt ""void C.this[params int[]].set"" @@ -800,7 +800,7 @@ .locals init (C V_0, //c IL_0084: ldc.i4.3 IL_0085: newarr ""int"" IL_008a: dup - IL_008b: ldtoken "".__StaticArrayInitTypeSize=12 .E429CCA3F703A39CC5954A6572FEC9086135B34E"" + IL_008b: ldtoken "".__StaticArrayInitTypeSize=12 .E429CCA3F703A39CC5954A6572FEC9086135B34E"" IL_0090: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_0095: stloc.3 IL_0096: ldloc.2 @@ -818,7 +818,7 @@ .locals init (C V_0, //c IL_00aa: ldc.i4.3 IL_00ab: newarr ""int"" IL_00b0: dup - IL_00b1: ldtoken "".__StaticArrayInitTypeSize=12 .E429CCA3F703A39CC5954A6572FEC9086135B34E"" + IL_00b1: ldtoken "".__StaticArrayInitTypeSize=12 .E429CCA3F703A39CC5954A6572FEC9086135B34E"" IL_00b6: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_00bb: stloc.3 IL_00bc: ldloc.2 @@ -1030,7 +1030,7 @@ .locals init (C V_0, //c IL_00a2: ldc.i4.3 IL_00a3: newarr ""int"" IL_00a8: dup - IL_00a9: ldtoken "".__StaticArrayInitTypeSize=12 .E429CCA3F703A39CC5954A6572FEC9086135B34E"" + IL_00a9: ldtoken "".__StaticArrayInitTypeSize=12 .E429CCA3F703A39CC5954A6572FEC9086135B34E"" IL_00ae: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_00b3: stloc.2 IL_00b4: ldloc.1 @@ -1047,7 +1047,7 @@ .locals init (C V_0, //c IL_00cb: ldc.i4.3 IL_00cc: newarr ""int"" IL_00d1: dup - IL_00d2: ldtoken "".__StaticArrayInitTypeSize=12 .E429CCA3F703A39CC5954A6572FEC9086135B34E"" + IL_00d2: ldtoken "".__StaticArrayInitTypeSize=12 .E429CCA3F703A39CC5954A6572FEC9086135B34E"" IL_00d7: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_00dc: stloc.2 IL_00dd: ldloc.1 diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/SwitchTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/SwitchTests.cs index b7ce4fc5c5988..3d74a07cd7e44 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/SwitchTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/SwitchTests.cs @@ -2283,7 +2283,7 @@ .locals init (string V_0, //value var reference = compVerifier.Compilation.EmitToImageReference(); var comp = CSharpCompilation.Create("Name", references: new[] { reference }, options: TestOptions.ReleaseDll.WithMetadataImportOptions(MetadataImportOptions.Internal)); - var pid = ((NamedTypeSymbol)comp.GlobalNamespace.GetMembers().Single(s => s.Name.StartsWith("", StringComparison.Ordinal))); + var pid = ((NamedTypeSymbol)comp.GlobalNamespace.GetMembers().Single(s => s.Name.StartsWith("", StringComparison.Ordinal))); var member = pid.GetMembers(PrivateImplementationDetails.SynthesizedStringHashFunctionName).Single(); Assert.Equal(Accessibility.Internal, member.DeclaredAccessibility); } diff --git a/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/EditAndContinueTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/EditAndContinueTests.cs index e031684aa1b8f..98a8e1d815ad0 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/EditAndContinueTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/EditAndContinueTests.cs @@ -2519,7 +2519,7 @@ .locals init (int[] V_0) //a IL_0001: ldc.i4.3 IL_0002: newarr ""int"" IL_0007: dup - IL_0008: ldtoken "".__StaticArrayInitTypeSize=12 .E429CCA3F703A39CC5954A6572FEC9086135B34E"" + IL_0008: ldtoken "".__StaticArrayInitTypeSize=12 .E429CCA3F703A39CC5954A6572FEC9086135B34E"" IL_000d: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_0012: stloc.0 IL_0013: ldloc.0 @@ -2828,7 +2828,7 @@ static int F(string s) var generation0 = EmitBaseline.CreateInitialBaseline(ModuleMetadata.CreateFromImage(bytes0), methodData0.EncDebugInfoProvider()); // Should have generated call to ComputeStringHash and - // added the method to . + // added the method to . var actualIL0 = methodData0.GetMethodIL(); Assert.True(actualIL0.Contains(ComputeStringHashName)); @@ -2843,7 +2843,7 @@ static int F(string s) ImmutableArray.Create(new SemanticEdit(SemanticEditKind.Update, method0, method1, GetEquivalentNodesMap(method1, method0), preserveLocalVariables: true))); // Should not have generated call to ComputeStringHash nor - // added the method to . + // added the method to . var actualIL1 = diff1.GetMethodIL("C.F"); Assert.False(actualIL1.Contains(ComputeStringHashName)); diff --git a/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs b/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs index 4d2b2eb70ef1c..b95830e909f05 100644 --- a/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs +++ b/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs @@ -1135,7 +1135,7 @@ .locals init (int[,,] V_0, //array IL_0003: ldc.i4.2 IL_0004: newobj ""int[*,*,*]..ctor"" IL_0009: dup - IL_000a: ldtoken "".__StaticArrayInitTypeSize=32 .EB196F988F4F427D318CA25B68671CF3A4510012"" + IL_000a: ldtoken "".__StaticArrayInitTypeSize=32 .EB196F988F4F427D318CA25B68671CF3A4510012"" IL_000f: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_0014: stloc.0 -IL_0015: nop diff --git a/src/Compilers/CSharp/Test/WinRT/CodeGen/WinRTCollectionTests.cs b/src/Compilers/CSharp/Test/WinRT/CodeGen/WinRTCollectionTests.cs index 81d8de6637206..6555c54821537 100644 --- a/src/Compilers/CSharp/Test/WinRT/CodeGen/WinRTCollectionTests.cs +++ b/src/Compilers/CSharp/Test/WinRT/CodeGen/WinRTCollectionTests.cs @@ -5242,7 +5242,7 @@ .locals init (AllMembers.<>c__DisplayClass3_0 V_0) //CS$<>8__locals0 IL_005b: ldc.i4.5 IL_005c: newarr ""int"" IL_0061: dup - IL_0062: ldtoken "".__StaticArrayInitTypeSize=20 .864782BF337E3DBC1A27023D5C0C065C80F17087"" + IL_0062: ldtoken "".__StaticArrayInitTypeSize=20 .864782BF337E3DBC1A27023D5C0C065C80F17087"" IL_0067: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_006c: ldloc.0 IL_006d: ldftn ""bool AllMembers.<>c__DisplayClass3_0.b__0(int)"" diff --git a/src/Compilers/Core/Portable/CodeGen/PrivateImplementationDetails.cs b/src/Compilers/Core/Portable/CodeGen/PrivateImplementationDetails.cs index db530e7abce20..ba48cf93e8a9f 100644 --- a/src/Compilers/Core/Portable/CodeGen/PrivateImplementationDetails.cs +++ b/src/Compilers/Core/Portable/CodeGen/PrivateImplementationDetails.cs @@ -80,14 +80,25 @@ internal PrivateImplementationDetails( _systemInt64Type = systemInt64Type; _compilerGeneratedAttribute = compilerGeneratedAttribute; - _name = GetClassName(moduleName, submissionSlotIndex); + + var isNetModule = moduleBuilder.AsAssembly == null; + _name = GetClassName(moduleName, submissionSlotIndex, isNetModule); } - internal static string GetClassName(string moduleName, int submissionSlotIndex) + private static string GetClassName(string moduleName, int submissionSlotIndex, bool isNetModule) { // we include the module name in the name of the PrivateImplementationDetails class so that more than - // one of them can be included in an assembly as part of netmodules. - return $"<{(submissionSlotIndex >= 0 ? submissionSlotIndex.ToString() : moduleName)}>"; + // one of them can be included in an assembly as part of netmodules. + var name = isNetModule ? + $"<{moduleName.MangleForTypeNameIfNeeded()}>" : + $""; + + if (submissionSlotIndex >= 0) + { + name += submissionSlotIndex.ToString(); + } + + return name; } internal void Freeze() diff --git a/src/Compilers/Core/Portable/InternalUtilities/StringExtensions.cs b/src/Compilers/Core/Portable/InternalUtilities/StringExtensions.cs index b0c1469a12176..12e2d59207e49 100644 --- a/src/Compilers/Core/Portable/InternalUtilities/StringExtensions.cs +++ b/src/Compilers/Core/Portable/InternalUtilities/StringExtensions.cs @@ -49,6 +49,20 @@ public static bool LooksLikeTypeParameterName(this string name) return name.Length >= 3 && name[0] == 'T' && char.IsUpper(name[1]) && char.IsLower(name[2]); } + /// + /// Given an input string changes it to be acceptable as a part of a type name. + /// For now we will simply replace '.' with '_'as the most common case. + /// + internal static string MangleForTypeNameIfNeeded(this string original) + { + // TODO: it may make sense to strenthen this algorithm + // to result in 1-1 mapping to reduce chances of + // producing matching results for distinct original strings + var result = original.Replace('.', '_'); + + return result; + } + private static readonly Func s_toLower = char.ToLower; private static readonly Func s_toUpper = char.ToUpper; diff --git a/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenForeach.vb b/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenForeach.vb index e40cc87183478..c395a65d454f8 100644 --- a/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenForeach.vb +++ b/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenForeach.vb @@ -91,7 +91,7 @@ End Class IL_0000: ldc.i4.3 IL_0001: newarr "Integer" IL_0006: dup - IL_0007: ldtoken ".__StaticArrayInitTypeSize=12 .E429CCA3F703A39CC5954A6572FEC9086135B34E" + IL_0007: ldtoken ".__StaticArrayInitTypeSize=12 .E429CCA3F703A39CC5954A6572FEC9086135B34E" IL_000c: call "Sub System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)" IL_0011: stloc.0 IL_0012: ldc.i4.0 @@ -927,7 +927,7 @@ End Class IL_0000: ldc.i4.3 IL_0001: newarr "Integer" IL_0006: dup - IL_0007: ldtoken ".__StaticArrayInitTypeSize=12 .E429CCA3F703A39CC5954A6572FEC9086135B34E" + IL_0007: ldtoken ".__StaticArrayInitTypeSize=12 .E429CCA3F703A39CC5954A6572FEC9086135B34E" IL_000c: call "Sub System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)" IL_0011: ldsfld "C._Closure$__.$I1-0 As System.Func(Of Integer, String)" IL_0016: brfalse.s IL_001f @@ -3041,7 +3041,7 @@ End Class IL_0000: ldc.i4.3 IL_0001: newarr "Integer" IL_0006: dup - IL_0007: ldtoken ".__StaticArrayInitTypeSize=12 .E429CCA3F703A39CC5954A6572FEC9086135B34E" + IL_0007: ldtoken ".__StaticArrayInitTypeSize=12 .E429CCA3F703A39CC5954A6572FEC9086135B34E" IL_000c: call "Sub System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)" IL_0011: stloc.0 .try diff --git a/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenMultiDimensionalArray.vb b/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenMultiDimensionalArray.vb index b8b9593e24155..7b81b4da35e63 100644 --- a/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenMultiDimensionalArray.vb +++ b/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenMultiDimensionalArray.vb @@ -30,7 +30,7 @@ End Module IL_0001: ldc.i4.3 IL_0002: newobj "Integer(*,*)..ctor" IL_0007: dup - IL_0008: ldtoken ".__StaticArrayInitTypeSize=24 .D64E555B758C5B66DFAC42F18587BB1B3C9BCFA8" + IL_0008: ldtoken ".__StaticArrayInitTypeSize=24 .D64E555B758C5B66DFAC42F18587BB1B3C9BCFA8" IL_000d: call "Sub System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)" IL_0012: ldc.i4.1 IL_0013: ldc.i4.1 @@ -64,7 +64,7 @@ End Module IL_0001: ldc.i4.3 IL_0002: newobj "Integer(*,*)..ctor" IL_0007: dup - IL_0008: ldtoken ".__StaticArrayInitTypeSize=24 .A4B74E064E285570B3499538C5B205C3D0972FDF" + IL_0008: ldtoken ".__StaticArrayInitTypeSize=24 .A4B74E064E285570B3499538C5B205C3D0972FDF" IL_000d: call "Sub System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)" IL_0012: dup IL_0013: ldc.i4.1 diff --git a/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTests.vb b/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTests.vb index 13ce0ae7e5395..18497da4a92ec 100644 --- a/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTests.vb +++ b/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTests.vb @@ -4845,7 +4845,7 @@ expectedOutput:="3b").VerifyIL("M1.Main", IL_0000: ldc.i4.3 IL_0001: newarr "Integer" IL_0006: dup - IL_0007: ldtoken ".__StaticArrayInitTypeSize=12 .E429CCA3F703A39CC5954A6572FEC9086135B34E" + IL_0007: ldtoken ".__StaticArrayInitTypeSize=12 .E429CCA3F703A39CC5954A6572FEC9086135B34E" IL_000c: call "Sub System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)" IL_0011: stloc.0 IL_0012: ldc.i4.2 @@ -6796,25 +6796,25 @@ End Module IL_0000: ldc.i4.5 IL_0001: newarr "Byte" IL_0006: dup - IL_0007: ldtoken ".__StaticArrayInitTypeSize=5 .9755240DD0C4C1AD226DEBD40C6D2EBD408250CB" + IL_0007: ldtoken ".__StaticArrayInitTypeSize=5 .9755240DD0C4C1AD226DEBD40C6D2EBD408250CB" IL_000c: call "Sub System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)" IL_0011: pop IL_0012: ldc.i4.5 IL_0013: newarr "Double" IL_0018: dup - IL_0019: ldtoken ".__StaticArrayInitTypeSize=40 .11F3436B917FFBA0FAB0FAD5563AF18FA24AC16A" + IL_0019: ldtoken ".__StaticArrayInitTypeSize=40 .11F3436B917FFBA0FAB0FAD5563AF18FA24AC16A" IL_001e: call "Sub System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)" IL_0023: pop IL_0024: ldc.i4.5 IL_0025: newarr "Boolean" IL_002a: dup - IL_002b: ldtoken ".__StaticArrayInitTypeSize=5 .4E724558F6B816715597A51663AD8F05247E2C4A" + IL_002b: ldtoken ".__StaticArrayInitTypeSize=5 .4E724558F6B816715597A51663AD8F05247E2C4A" IL_0030: call "Sub System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)" IL_0035: pop IL_0036: ldc.i4.5 IL_0037: newarr "Char" IL_003c: dup - IL_003d: ldtoken ".__StaticArrayInitTypeSize=10 .E313A2813013780396D58750DC5D62221C86F42F" + IL_003d: ldtoken ".__StaticArrayInitTypeSize=10 .E313A2813013780396D58750DC5D62221C86F42F" IL_0042: call "Sub System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)" IL_0047: pop IL_0048: ret @@ -6897,7 +6897,7 @@ End Module IL_0000: ldc.i4.5 IL_0001: newarr "System.TypeCode" IL_0006: dup - IL_0007: ldtoken ".__StaticArrayInitTypeSize=20 .3191FF614021ADF3122AC274EA5B6097C21BEB81" + IL_0007: ldtoken ".__StaticArrayInitTypeSize=20 .3191FF614021ADF3122AC274EA5B6097C21BEB81" IL_000c: call "Sub System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)" IL_0011: pop IL_0012: ret @@ -10615,7 +10615,7 @@ True IL_0040: ldc.i4.4 IL_0041: newarr "Boolean" IL_0046: dup - IL_0047: ldtoken "Integer .35CCB1599F52363510686EF38B7DB5E7998DB108" + IL_0047: ldtoken "Integer .35CCB1599F52363510686EF38B7DB5E7998DB108" IL_004c: call "Sub System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)" IL_0051: ldc.i4.2 IL_0052: ldelem.u1 @@ -11474,7 +11474,7 @@ End Module IL_0000: ldc.i4.4 IL_0001: newarr "Integer" IL_0006: dup - IL_0007: ldtoken ".__StaticArrayInitTypeSize=16 .1456763F890A84558F99AFA687C36B9037697848" + IL_0007: ldtoken ".__StaticArrayInitTypeSize=16 .1456763F890A84558F99AFA687C36B9037697848" IL_000c: call "Sub System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)" IL_0011: stloc.0 IL_0012: ldloc.0 diff --git a/src/Compilers/VisualBasic/Test/Emit/CodeGen/WinRTCollectionTests.vb b/src/Compilers/VisualBasic/Test/Emit/CodeGen/WinRTCollectionTests.vb index 9c5e309e728e5..2165218d71940 100644 --- a/src/Compilers/VisualBasic/Test/Emit/CodeGen/WinRTCollectionTests.vb +++ b/src/Compilers/VisualBasic/Test/Emit/CodeGen/WinRTCollectionTests.vb @@ -4431,7 +4431,7 @@ End Class IL_005b: ldc.i4.5 IL_005c: newarr "Integer" IL_0061: dup - IL_0062: ldtoken ".__StaticArrayInitTypeSize=20 .864782BF337E3DBC1A27023D5C0C065C80F17087" + IL_0062: ldtoken ".__StaticArrayInitTypeSize=20 .864782BF337E3DBC1A27023D5C0C065C80F17087" IL_0067: call "Sub System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)" IL_006c: ldloc.0 IL_006d: ldftn "Function AllMembers._Closure$__5-0._Lambda$__0(Integer) As Boolean" diff --git a/src/Compilers/VisualBasic/Test/Emit/Emit/EditAndContinue/EditAndContinueTests.vb b/src/Compilers/VisualBasic/Test/Emit/Emit/EditAndContinue/EditAndContinueTests.vb index c02958fd8eaa9..3640f46b881b1 100644 --- a/src/Compilers/VisualBasic/Test/Emit/Emit/EditAndContinue/EditAndContinueTests.vb +++ b/src/Compilers/VisualBasic/Test/Emit/Emit/EditAndContinue/EditAndContinueTests.vb @@ -459,7 +459,7 @@ End Class IL_0001: ldc.i4.3 IL_0002: newarr ""Integer"" IL_0007: dup - IL_0008: ldtoken "".__StaticArrayInitTypeSize=12 .E429CCA3F703A39CC5954A6572FEC9086135B34E"" + IL_0008: ldtoken "".__StaticArrayInitTypeSize=12 .E429CCA3F703A39CC5954A6572FEC9086135B34E"" IL_000d: call ""Sub System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_0012: stloc.0 IL_0013: ldloc.0 @@ -554,7 +554,7 @@ End Class Dim generation0 = EmitBaseline.CreateInitialBaseline(ModuleMetadata.CreateFromImage(bytes0), methodData0.EncDebugInfoProvider) ' Should have generated call to ComputeStringHash and - ' added the method to . + ' added the method to . Dim actualIL0 = methodData0.GetMethodIL() Assert.True(actualIL0.Contains(ComputeStringHashName)) @@ -570,7 +570,7 @@ End Class ImmutableArray.Create(edit)) ' Should not have generated call to ComputeStringHash nor - ' added the method to . + ' added the method to . Dim actualIL1 = diff1.GetMethodIL("C.F") Assert.False(actualIL1.Contains(ComputeStringHashName)) diff --git a/src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/ExpressionCompilerTests.cs b/src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/ExpressionCompilerTests.cs index eab704b8bdb31..ac0630037cc80 100644 --- a/src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/ExpressionCompilerTests.cs +++ b/src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/ExpressionCompilerTests.cs @@ -3373,7 +3373,7 @@ .maxstack 3 IL_0000: ldc.i4.5 IL_0001: newarr ""int"" IL_0006: dup - IL_0007: ldtoken ""<{#Module#}.dll>.__StaticArrayInitTypeSize=20 <{#Module#}.dll>.1036C5F8EF306104BD582D73E555F4DAE8EECB24"" + IL_0007: ldtoken "".__StaticArrayInitTypeSize=20 .1036C5F8EF306104BD582D73E555F4DAE8EECB24"" IL_000c: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_0011: ret }"); diff --git a/src/ExpressionEvaluator/VisualBasic/Test/ExpressionCompiler/ExpressionCompilerTests.vb b/src/ExpressionEvaluator/VisualBasic/Test/ExpressionCompiler/ExpressionCompilerTests.vb index f682369ea3771..c6a662076dd2e 100644 --- a/src/ExpressionEvaluator/VisualBasic/Test/ExpressionCompiler/ExpressionCompilerTests.vb +++ b/src/ExpressionEvaluator/VisualBasic/Test/ExpressionCompiler/ExpressionCompilerTests.vb @@ -2117,7 +2117,7 @@ End Class" IL_0000: ldc.i4.5 IL_0001: newarr ""Integer"" IL_0006: dup - IL_0007: ldtoken ""<{#Module#}.dll>.__StaticArrayInitTypeSize=20 <{#Module#}.dll>.1036C5F8EF306104BD582D73E555F4DAE8EECB24"" + IL_0007: ldtoken "".__StaticArrayInitTypeSize=20 .1036C5F8EF306104BD582D73E555F4DAE8EECB24"" IL_000c: call ""Sub System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)"" IL_0011: ret }") From 0d09712c91cebb8ddf78ba30dc9538e10b7f653f Mon Sep 17 00:00:00 2001 From: VSadov Date: Tue, 24 Mar 2015 21:07:33 -0700 Subject: [PATCH 2/2] Moved MangleForTypeNameIfNeeded to MetadataHelpers --- .../AnonymousTypeManager.Templates.cs | 2 +- .../CodeGen/PrivateImplementationDetails.cs | 2 +- .../Portable/InternalUtilities/StringExtensions.cs | 14 -------------- .../Portable/MetadataReader/MetadataHelpers.cs | 14 ++++++++++++++ 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/AnonymousTypes/AnonymousTypeManager.Templates.cs b/src/Compilers/CSharp/Portable/Symbols/AnonymousTypes/AnonymousTypeManager.Templates.cs index 2865e6738e420..89db39da1386a 100644 --- a/src/Compilers/CSharp/Portable/Symbols/AnonymousTypes/AnonymousTypeManager.Templates.cs +++ b/src/Compilers/CSharp/Portable/Symbols/AnonymousTypes/AnonymousTypeManager.Templates.cs @@ -293,7 +293,7 @@ public void AssignTemplatesNamesAndCompile(MethodCompiler compiler, PEModuleBuil moduleId = moduleId.Substring(0, moduleId.Length - extension.Length); } - moduleId = moduleId.MangleForTypeNameIfNeeded(); + moduleId = MetadataHelpers.MangleForTypeNameIfNeeded(moduleId); } else { diff --git a/src/Compilers/Core/Portable/CodeGen/PrivateImplementationDetails.cs b/src/Compilers/Core/Portable/CodeGen/PrivateImplementationDetails.cs index ba48cf93e8a9f..cf1716dc103ae 100644 --- a/src/Compilers/Core/Portable/CodeGen/PrivateImplementationDetails.cs +++ b/src/Compilers/Core/Portable/CodeGen/PrivateImplementationDetails.cs @@ -90,7 +90,7 @@ private static string GetClassName(string moduleName, int submissionSlotIndex, b // we include the module name in the name of the PrivateImplementationDetails class so that more than // one of them can be included in an assembly as part of netmodules. var name = isNetModule ? - $"<{moduleName.MangleForTypeNameIfNeeded()}>" : + $"<{MetadataHelpers.MangleForTypeNameIfNeeded(moduleName)}>" : $""; if (submissionSlotIndex >= 0) diff --git a/src/Compilers/Core/Portable/InternalUtilities/StringExtensions.cs b/src/Compilers/Core/Portable/InternalUtilities/StringExtensions.cs index 12e2d59207e49..b0c1469a12176 100644 --- a/src/Compilers/Core/Portable/InternalUtilities/StringExtensions.cs +++ b/src/Compilers/Core/Portable/InternalUtilities/StringExtensions.cs @@ -49,20 +49,6 @@ public static bool LooksLikeTypeParameterName(this string name) return name.Length >= 3 && name[0] == 'T' && char.IsUpper(name[1]) && char.IsLower(name[2]); } - /// - /// Given an input string changes it to be acceptable as a part of a type name. - /// For now we will simply replace '.' with '_'as the most common case. - /// - internal static string MangleForTypeNameIfNeeded(this string original) - { - // TODO: it may make sense to strenthen this algorithm - // to result in 1-1 mapping to reduce chances of - // producing matching results for distinct original strings - var result = original.Replace('.', '_'); - - return result; - } - private static readonly Func s_toLower = char.ToLower; private static readonly Func s_toUpper = char.ToUpper; diff --git a/src/Compilers/Core/Portable/MetadataReader/MetadataHelpers.cs b/src/Compilers/Core/Portable/MetadataReader/MetadataHelpers.cs index 63fc43d230e7b..385a4dd0d5339 100644 --- a/src/Compilers/Core/Portable/MetadataReader/MetadataHelpers.cs +++ b/src/Compilers/Core/Portable/MetadataReader/MetadataHelpers.cs @@ -1047,5 +1047,19 @@ public static bool TryDecode(ImmutableArray bytes) return true; } } + + /// + /// Given an input string changes it to be acceptable as a part of a type name. + /// For now we will simply replace '.' with '_'as the most common case. + /// + internal static string MangleForTypeNameIfNeeded(string moduleName) + { + // TODO: it may make sense to strenthen this algorithm + // to result in 1-1 mapping to reduce chances of + // producing matching results for distinct original strings + var result = moduleName.Replace('.', '_'); + + return result; + } } }