Skip to content

Commit

Permalink
Add the module name to generated PrivateImplementationDetails class
Browse files Browse the repository at this point in the history
so that there will be no conflict if they are used as netmodules
Fixes #1228
  • Loading branch information
gafter committed Mar 13, 2015
1 parent 71d351e commit 38aa68d
Show file tree
Hide file tree
Showing 19 changed files with 162 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace Microsoft.CodeAnalysis.CSharp.Emit
{
internal abstract class PEModuleBuilder : PEModuleBuilder<CSharpCompilation, Symbol, SourceModuleSymbol, ModuleSymbol, AssemblySymbol, NamespaceSymbol, TypeSymbol, NamedTypeSymbol, MethodSymbol, CSharpSyntaxNode, NoPia.EmbeddedTypesManager, ModuleCompilationState>
internal abstract class PEModuleBuilder : PEModuleBuilder<CSharpCompilation, SourceModuleSymbol, AssemblySymbol, TypeSymbol, NamedTypeSymbol, MethodSymbol, CSharpSyntaxNode, NoPia.EmbeddedTypesManager, ModuleCompilationState>
{
// TODO: Need to estimate amount of elements for this map and pass that value to the constructor.
protected readonly ConcurrentDictionary<Symbol, Cci.IModuleReference> AssemblyOrModuleSymbolToModuleRefMap = new ConcurrentDictionary<Symbol, Cci.IModuleReference>();
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenForEachTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static void Main()
}
}
}";
var compilation = CompileAndVerify(source, expectedOutput: @"
var compilation = CompileAndVerify(source, options: TestOptions.ReleaseExe.WithModuleName("MODULE"), expectedOutput: @"
1.2
2.3
3.4
Expand All @@ -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 ""<PrivateImplementationDetails>.__StaticArrayInitTypeSize=64 <PrivateImplementationDetails>.$$method0x6000001-E19C080DB8DAB85AF7CA3EF40FFB01B0778F9D25""
IL_0008: ldtoken ""<PrivateImplementationDetails><MODULE>.__StaticArrayInitTypeSize=64 <PrivateImplementationDetails><MODULE>.E19C080DB8DAB85AF7CA3EF40FFB01B0778F9D25""
IL_000d: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)""
IL_0012: stloc.0
IL_0013: ldloc.0
Expand Down
54 changes: 27 additions & 27 deletions src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3231,7 +3231,7 @@ public static void Main()
}
}
";
var compilation = CompileAndVerify(source, expectedOutput: "222333");
var compilation = CompileAndVerify(source, options: TestOptions.ReleaseExe.WithModuleName("MODULE"), expectedOutput: "222333");

compilation.VerifyIL("D.Main",
@"{
Expand All @@ -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 ""<PrivateImplementationDetails>.__StaticArrayInitTypeSize=16 <PrivateImplementationDetails>.$$method0x6000001-42F1B77334EDFA917032CCF8353020C73F8C62E1""
IL_0007: ldtoken ""<PrivateImplementationDetails><MODULE>.__StaticArrayInitTypeSize=16 <PrivateImplementationDetails><MODULE>.42F1B77334EDFA917032CCF8353020C73F8C62E1""
IL_000c: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)""
IL_0011: stloc.0
IL_0012: ldloc.0
Expand Down Expand Up @@ -3560,7 +3560,7 @@ static void Main()
");

#region IL
// Can NOT compare IL because the Guid is different every time - <PrivateImplementationDetails>{a6c2d596-042b-4294-99ab-d34a2758ec15}
// Can NOT compare IL because the Guid is different every time - <PrivateImplementationDetails><MODULE>{a6c2d596-042b-4294-99ab-d34a2758ec15}
#if false
compilation.VerifyIL("MyArray.Main",
@"{
Expand Down Expand Up @@ -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 ""<PrivateImplementationDetails>{a6c2d596-042b-4294-99ab-d34a2758ec15}.__StaticArrayInitTypeSize=3 <PrivateImplementationDetails>{a6c2d596-042b-4294-99ab-d34a2758ec15}.$$method0x6000001-0""
IL_002f: ldtoken ""<PrivateImplementationDetails><MODULE>{a6c2d596-042b-4294-99ab-d34a2758ec15}.__StaticArrayInitTypeSize=3 <PrivateImplementationDetails><MODULE>{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
Expand All @@ -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 ""<PrivateImplementationDetails>{a6c2d596-042b-4294-99ab-d34a2758ec15}.__StaticArrayInitTypeSize=6 <PrivateImplementationDetails>{a6c2d596-042b-4294-99ab-d34a2758ec15}.$$method0x6000001-1""
IL_0066: ldtoken ""<PrivateImplementationDetails><MODULE>{a6c2d596-042b-4294-99ab-d34a2758ec15}.__StaticArrayInitTypeSize=6 <PrivateImplementationDetails><MODULE>{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
Expand Down Expand Up @@ -6383,7 +6383,7 @@ public static void Main()
System.Console.WriteLine(d[4]);
}
}";
var compilation = CompileAndVerify(source, expectedOutput: @"
var compilation = CompileAndVerify(source, options: TestOptions.ReleaseExe.WithModuleName("MODULE"), expectedOutput: @"
3
-5
True
Expand All @@ -6406,7 +6406,7 @@ .maxstack 3
IL_0000: ldc.i4.5
IL_0001: newarr ""int""
IL_0006: dup
IL_0007: ldtoken ""<PrivateImplementationDetails>.__StaticArrayInitTypeSize=20 <PrivateImplementationDetails>.$$method0x6000001-56C14CB445C628421AC674599E302B0879FB496F""
IL_0007: ldtoken ""<PrivateImplementationDetails><MODULE>.__StaticArrayInitTypeSize=20 <PrivateImplementationDetails><MODULE>.56C14CB445C628421AC674599E302B0879FB496F""
IL_000c: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)""
IL_0011: dup
IL_0012: ldc.i4.2
Expand All @@ -6418,7 +6418,7 @@ .maxstack 3
IL_0020: ldc.i4.5
IL_0021: newarr ""bool""
IL_0026: dup
IL_0027: ldtoken ""<PrivateImplementationDetails>.__StaticArrayInitTypeSize=5 <PrivateImplementationDetails>.$$method0x6000001-4E724558F6B816715597A51663AD8F05247E2C4A""
IL_0027: ldtoken ""<PrivateImplementationDetails><MODULE>.__StaticArrayInitTypeSize=5 <PrivateImplementationDetails><MODULE>.4E724558F6B816715597A51663AD8F05247E2C4A""
IL_002c: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)""
IL_0031: dup
IL_0032: ldc.i4.2
Expand All @@ -6430,7 +6430,7 @@ .maxstack 3
IL_0040: ldc.i4.5
IL_0041: newarr ""byte""
IL_0046: dup
IL_0047: ldtoken ""<PrivateImplementationDetails>.__StaticArrayInitTypeSize=5 <PrivateImplementationDetails>.$$method0x6000001-9755240DD0C4C1AD226DEBD40C6D2EBD408250CB""
IL_0047: ldtoken ""<PrivateImplementationDetails><MODULE>.__StaticArrayInitTypeSize=5 <PrivateImplementationDetails><MODULE>.9755240DD0C4C1AD226DEBD40C6D2EBD408250CB""
IL_004c: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)""
IL_0051: dup
IL_0052: ldc.i4.2
Expand All @@ -6442,7 +6442,7 @@ .maxstack 3
IL_0060: ldc.i4.5
IL_0061: newarr ""char""
IL_0066: dup
IL_0067: ldtoken ""<PrivateImplementationDetails>.__StaticArrayInitTypeSize=10 <PrivateImplementationDetails>.$$method0x6000001-E313A2813013780396D58750DC5D62221C86F42F""
IL_0067: ldtoken ""<PrivateImplementationDetails><MODULE>.__StaticArrayInitTypeSize=10 <PrivateImplementationDetails><MODULE>.E313A2813013780396D58750DC5D62221C86F42F""
IL_006c: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)""
IL_0071: dup
IL_0072: ldc.i4.2
Expand All @@ -6454,7 +6454,7 @@ .maxstack 3
IL_0080: ldc.i4.5
IL_0081: newarr ""float""
IL_0086: dup
IL_0087: ldtoken ""<PrivateImplementationDetails>.__StaticArrayInitTypeSize=20 <PrivateImplementationDetails>.$$method0x6000001-2F3DD953DBFB23217E7CE0E76630EBD31267E237""
IL_0087: ldtoken ""<PrivateImplementationDetails><MODULE>.__StaticArrayInitTypeSize=20 <PrivateImplementationDetails><MODULE>.2F3DD953DBFB23217E7CE0E76630EBD31267E237""
IL_008c: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)""
IL_0091: dup
IL_0092: ldc.i4.2
Expand All @@ -6466,7 +6466,7 @@ .maxstack 3
IL_00a0: ldc.i4.5
IL_00a1: newarr ""double""
IL_00a6: dup
IL_00a7: ldtoken ""<PrivateImplementationDetails>.__StaticArrayInitTypeSize=40 <PrivateImplementationDetails>.$$method0x6000001-11F3436B917FFBA0FAB0FAD5563AF18FA24AC16A""
IL_00a7: ldtoken ""<PrivateImplementationDetails><MODULE>.__StaticArrayInitTypeSize=40 <PrivateImplementationDetails><MODULE>.11F3436B917FFBA0FAB0FAD5563AF18FA24AC16A""
IL_00ac: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)""
IL_00b1: dup
IL_00b2: ldc.i4.2
Expand Down Expand Up @@ -6499,8 +6499,8 @@ public static void Main()
}
}
";
var compilation = CompileAndVerify(source, expectedOutput: @"3-5");
//string pid = "<PrivateImplementationDetails>" + compilation.Compilation.SourceModule.Pers
var compilation = CompileAndVerify(source, options: TestOptions.ReleaseExe.WithModuleName("MODULE"), expectedOutput: @"3-5");
//string pid = "<PrivateImplementationDetails><MODULE>" + compilation.Compilation.SourceModule.Pers
compilation.VerifyIL("D.Main",
@"{
// Code size 73 (0x49)
Expand All @@ -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 ""<PrivateImplementationDetails>.__StaticArrayInitTypeSize=20 <PrivateImplementationDetails>.$$method0x6000001-FF942E5F620FC460CF9424D564C73AD8A99C74EE""
IL_0007: ldtoken ""<PrivateImplementationDetails><MODULE>.__StaticArrayInitTypeSize=20 <PrivateImplementationDetails><MODULE>.FF942E5F620FC460CF9424D564C73AD8A99C74EE""
IL_000c: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)""
IL_0011: dup
IL_0012: ldc.i4.2
Expand All @@ -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 ""<PrivateImplementationDetails>.__StaticArrayInitTypeSize=20 <PrivateImplementationDetails>.$$method0x6000001-89E37886EEEDC70AEF61138E037CC60EFC35535F""
IL_002e: ldtoken ""<PrivateImplementationDetails><MODULE>.__StaticArrayInitTypeSize=20 <PrivateImplementationDetails><MODULE>.89E37886EEEDC70AEF61138E037CC60EFC35535F""
IL_0033: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)""
IL_0038: dup
IL_0039: ldc.i4.4
Expand Down Expand Up @@ -6561,8 +6561,8 @@ public static void Main()
}
}
";
var compilation = CompileAndVerify(source, expectedOutput: @"30");
//string pid = "<PrivateImplementationDetails>" + compilation.Compilation.SourceModule.Pers
var compilation = CompileAndVerify(source, options: TestOptions.ReleaseExe.WithModuleName("MODULE"), expectedOutput: @"30");
//string pid = "<PrivateImplementationDetails><MODULE>" + compilation.Compilation.SourceModule.Pers
compilation.VerifyIL("D.Main",
@"{
// Code size 82 (0x52)
Expand Down Expand Up @@ -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 ""<PrivateImplementationDetails>.__StaticArrayInitTypeSize=60 <PrivateImplementationDetails>.$$method0x6000001-49608711F905702F9F227AA782F8B408777D5DF9""
IL_0036: ldtoken ""<PrivateImplementationDetails><MODULE>.__StaticArrayInitTypeSize=60 <PrivateImplementationDetails><MODULE>.49608711F905702F9F227AA782F8B408777D5DF9""
IL_003b: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)""
IL_0040: dup
IL_0041: ldc.i4.s 12
Expand Down Expand Up @@ -6716,7 +6716,7 @@ public static void Main()
DBNull
";

var compilation = CreateCompilationWithMscorlib45(source: source, options: TestOptions.ReleaseExe);
var compilation = CreateCompilationWithMscorlib45(source: source, options: TestOptions.ReleaseExe.WithModuleName("MODULE"));
var verifier = CompileAndVerify(compilation, expectedOutput: expectedOutput);

//NOTE:
Expand All @@ -6728,7 +6728,7 @@ .maxstack 3
IL_0000: ldc.i4.5
IL_0001: newarr ""System.TypeCode""
IL_0006: dup
IL_0007: ldtoken ""<PrivateImplementationDetails>.__StaticArrayInitTypeSize=20 <PrivateImplementationDetails>.$$method0x6000001-3191FF614021ADF3122AC274EA5B6097C21BEB81""
IL_0007: ldtoken ""<PrivateImplementationDetails><MODULE>.__StaticArrayInitTypeSize=20 <PrivateImplementationDetails><MODULE>.3191FF614021ADF3122AC274EA5B6097C21BEB81""
IL_000c: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)""
IL_0011: dup
IL_0012: ldc.i4.1
Expand Down Expand Up @@ -7240,7 +7240,7 @@ static void Main()
}
}
";
var compilation = CompileAndVerify(source, expectedOutput: @"
var compilation = CompileAndVerify(source, options: TestOptions.ReleaseExe.WithModuleName("MODULE"), expectedOutput: @"
F1=3, F2=33
444
127
Expand Down Expand Up @@ -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 <PrivateImplementationDetails>.$$method0x6000001-E9E8A66A117598333ABACF5B65971C2366E19B6C""
IL_008c: ldtoken ""long <PrivateImplementationDetails><MODULE>.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)""
Expand Down Expand Up @@ -7523,7 +7523,7 @@ public static void Main()
}
";
var compilation = CompileAndVerify(source, options: TestOptions.DebugExe);
var compilation = CompileAndVerify(source, options: TestOptions.DebugExe.WithModuleName("MODULE"));

compilation.VerifyIL("A.Main",
@"{
Expand All @@ -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 ""<PrivateImplementationDetails>.__StaticArrayInitTypeSize=20 <PrivateImplementationDetails>.$$method0x6000001-1036C5F8EF306104BD582D73E555F4DAE8EECB24""
IL_0008: ldtoken ""<PrivateImplementationDetails><MODULE>.__StaticArrayInitTypeSize=20 <PrivateImplementationDetails><MODULE>.1036C5F8EF306104BD582D73E555F4DAE8EECB24""
IL_000d: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)""
IL_0012: stloc.0
IL_0013: ret
Expand Down Expand Up @@ -13006,7 +13006,7 @@ static void Run()
}
}
";
var compilation = CompileAndVerify(source, expectedOutput: @"False
var compilation = CompileAndVerify(source, options: TestOptions.ReleaseExe.WithModuleName("MODULE"), expectedOutput: @"False
True
System.Exception: Exception of type 'System.Exception' was thrown.
Expand Down Expand Up @@ -13047,7 +13047,7 @@ .maxstack 4
IL_0040: ldc.i4.4
IL_0041: newarr ""bool""
IL_0046: dup
IL_0047: ldtoken ""int <PrivateImplementationDetails>.$$method0x6000001-35CCB1599F52363510686EF38B7DB5E7998DB108""
IL_0047: ldtoken ""int <PrivateImplementationDetails><MODULE>.35CCB1599F52363510686EF38B7DB5E7998DB108""
IL_004c: call ""void System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray(System.Array, System.RuntimeFieldHandle)""
IL_0051: ldc.i4.2
IL_0052: ldelem.u1
Expand Down
Loading

0 comments on commit 38aa68d

Please sign in to comment.