Skip to content

Commit 742ea07

Browse files
authored
Remove Reflection.Emit APIs (#56153)
* Remove Reflection.Emit APIs Removes all unused leftover APIs Fix #49452 * Fix the api-compat baseline * Remove the baseline altogether * Remove fIsTransient refs from .cpp (as well as .h) * Remove nIsTransientInternal * Remove DefineDynamicModule & DefineDocument * Revert "Remove the baseline altogether" This reverts commit ddb0303. * API compat baseline for GetModuleHandleImpl * Fix Mono * Match changes in Mono runtime
1 parent d86299e commit 742ea07

File tree

15 files changed

+8
-128
lines changed

15 files changed

+8
-128
lines changed

src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,6 @@ internal static AssemblyBuilder InternalDefineDynamicAssembly(
305305
public ModuleBuilder DefineDynamicModule(string name) =>
306306
DefineDynamicModuleInternal(name, emitSymbolInfo: false);
307307

308-
[DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod.
309-
public ModuleBuilder DefineDynamicModule(string name, bool emitSymbolInfo) =>
310-
DefineDynamicModuleInternal(name, emitSymbolInfo);
311-
312308
private ModuleBuilder DefineDynamicModuleInternal(string name, bool emitSymbolInfo)
313309
{
314310
lock (SyncRoot)

src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,11 @@ public override CallingConventions CallingConvention
160160
}
161161
}
162162

163-
public Module GetModule()
164-
{
165-
return m_methodBuilder.GetModule();
166-
}
167-
168163
internal override Type GetReturnType()
169164
{
170165
return m_methodBuilder.ReturnType;
171166
}
172167

173-
public string Signature => m_methodBuilder.Signature;
174-
175168
public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
176169
{
177170
m_methodBuilder.SetCustomAttribute(con, binaryAttribute);

src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -758,13 +758,11 @@ public bool InitLocals
758758
set { ThrowIfGeneric(); m_fInitLocals = value; }
759759
}
760760

761-
public Module GetModule()
761+
internal Module GetModule()
762762
{
763763
return GetModuleBuilder();
764764
}
765765

766-
public string Signature => GetMethodSignature().ToString();
767-
768766
public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
769767
{
770768
if (con is null)

src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,20 +1598,6 @@ public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
15981598
// Regardless, this is a reliability bug.
15991599
internal ISymbolWriter? GetSymWriter() => _iSymWriter;
16001600

1601-
public ISymbolDocumentWriter? DefineDocument(string url, Guid language, Guid languageVendor, Guid documentType)
1602-
{
1603-
// url cannot be null but can be an empty string
1604-
if (url == null)
1605-
{
1606-
throw new ArgumentNullException(nameof(url));
1607-
}
1608-
1609-
lock (SyncRoot)
1610-
{
1611-
return DefineDocumentNoLock(url, language, languageVendor, documentType);
1612-
}
1613-
}
1614-
16151601
private ISymbolDocumentWriter? DefineDocumentNoLock(string url, Guid language, Guid languageVendor, Guid documentType)
16161602
{
16171603
if (_iSymWriter == null)
@@ -1623,8 +1609,6 @@ public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
16231609
return _iSymWriter.DefineDocument(url, language, languageVendor, documentType);
16241610
}
16251611

1626-
public bool IsTransient() => InternalModule.IsTransientInternal();
1627-
16281612
#endregion
16291613

16301614
#endregion

src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ internal class RuntimeModule : Module
1717
[DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)]
1818
private static extern void GetType(QCallModule module, string className, bool throwOnError, bool ignoreCase, ObjectHandleOnStack type, ObjectHandleOnStack keepAlive);
1919

20-
[DllImport(RuntimeHelpers.QCall)]
21-
private static extern bool nIsTransientInternal(QCallModule module);
22-
2320
[DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)]
2421
private static extern void GetScopeName(QCallModule module, StringHandleOnStack retString);
2522

@@ -382,12 +379,6 @@ public override void GetPEKind(out PortableExecutableKinds peKind, out ImageFile
382379
#region Internal Members
383380
internal RuntimeType RuntimeType => m_runtimeType ??= ModuleHandle.GetModuleType(this);
384381

385-
internal bool IsTransientInternal()
386-
{
387-
RuntimeModule thisAsLocal = this;
388-
return RuntimeModule.nIsTransientInternal(new QCallModule(ref thisAsLocal));
389-
}
390-
391382
internal MetadataImport MetadataImport => ModuleHandle.GetMetadataImport(this);
392383
#endregion
393384

src/coreclr/vm/assembly.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void Assembly::Init(AllocMemTracker *pamTracker, LoaderAllocator *pLoaderAllocat
176176
#ifndef CROSSGEN_COMPILE
177177
if (GetManifestFile()->IsDynamic())
178178
// manifest modules of dynamic assemblies are always transient
179-
m_pManifest = ReflectionModule::Create(this, GetManifestFile(), pamTracker, REFEMIT_MANIFEST_MODULE_NAME, TRUE);
179+
m_pManifest = ReflectionModule::Create(this, GetManifestFile(), pamTracker, REFEMIT_MANIFEST_MODULE_NAME);
180180
else
181181
#endif
182182
m_pManifest = Module::Create(this, mdFileNil, GetManifestFile(), pamTracker);

src/coreclr/vm/ceeload.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12442,7 +12442,7 @@ idMethodSpec Module::LogInstantiatedMethod(const MethodDesc * md, ULONG flagNum)
1244212442
// ===========================================================================
1244312443

1244412444
/* static */
12445-
ReflectionModule *ReflectionModule::Create(Assembly *pAssembly, PEFile *pFile, AllocMemTracker *pamTracker, LPCWSTR szName, BOOL fIsTransient)
12445+
ReflectionModule *ReflectionModule::Create(Assembly *pAssembly, PEFile *pFile, AllocMemTracker *pamTracker, LPCWSTR szName)
1244612446
{
1244712447
CONTRACT(ReflectionModule *)
1244812448
{
@@ -12468,9 +12468,6 @@ ReflectionModule *ReflectionModule::Create(Assembly *pAssembly, PEFile *pFile, A
1246812468

1246912469
pModule->DoInit(pamTracker, szName);
1247012470

12471-
// Set this at module creation time. The m_fIsTransient field should never change during the lifetime of this ReflectionModule.
12472-
pModule->SetIsTransient(fIsTransient ? true : false);
12473-
1247412471
RETURN pModule.Extract();
1247512472
}
1247612473

@@ -12498,7 +12495,6 @@ ReflectionModule::ReflectionModule(Assembly *pAssembly, mdFile token, PEFile *pF
1249812495
m_pCeeFileGen = NULL;
1249912496
m_pDynamicMetadata = NULL;
1250012497
m_fSuppressMetadataCapture = false;
12501-
m_fIsTransient = false;
1250212498
}
1250312499

1250412500
HRESULT STDMETHODCALLTYPE CreateICeeGen(REFIID riid, void **pCeeGen);

src/coreclr/vm/ceeload.h

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3210,9 +3210,6 @@ class ReflectionModule : public Module
32103210
// This is used to allow bulk emitting types without re-emitting the metadata between each type.
32113211
bool m_fSuppressMetadataCapture;
32123212

3213-
// If true, then only other transient modules can depend on this module.
3214-
bool m_fIsTransient;
3215-
32163213
#if !defined DACCESS_COMPILE && !defined CROSSGEN_COMPILE
32173214
// Returns true iff metadata capturing is suppressed
32183215
bool IsMetadataCaptureSuppressed();
@@ -3244,7 +3241,7 @@ class ReflectionModule : public Module
32443241
#endif
32453242

32463243
#if !defined DACCESS_COMPILE && !defined CROSSGEN_COMPILE
3247-
static ReflectionModule *Create(Assembly *pAssembly, PEFile *pFile, AllocMemTracker *pamTracker, LPCWSTR szName, BOOL fIsTransient);
3244+
static ReflectionModule *Create(Assembly *pAssembly, PEFile *pFile, AllocMemTracker *pamTracker, LPCWSTR szName);
32483245
void Initialize(AllocMemTracker *pamTracker, LPCWSTR szName);
32493246
void Destruct();
32503247
#endif // !DACCESS_COMPILE && !CROSSGEN_COMPILE
@@ -3296,20 +3293,6 @@ class ReflectionModule : public Module
32963293
return &m_pISymUnmanagedWriter;
32973294
}
32983295

3299-
bool IsTransient()
3300-
{
3301-
LIMITED_METHOD_CONTRACT;
3302-
3303-
return m_fIsTransient;
3304-
}
3305-
3306-
void SetIsTransient(bool fIsTransient)
3307-
{
3308-
LIMITED_METHOD_CONTRACT;
3309-
3310-
m_fIsTransient = fIsTransient;
3311-
}
3312-
33133296
#ifndef DACCESS_COMPILE
33143297
#ifndef CROSSGEN_COMPILE
33153298

src/coreclr/vm/commodule.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -704,28 +704,6 @@ void QCALLTYPE COMModule::SetModuleName(QCall::ModuleHandle pModule, LPCWSTR wsz
704704
END_QCALL;
705705
}
706706

707-
//******************************************************************************
708-
//
709-
// Return a type spec token given a byte array
710-
//
711-
//******************************************************************************
712-
BOOL QCALLTYPE COMModule::IsTransient(QCall::ModuleHandle pModule)
713-
{
714-
QCALL_CONTRACT;
715-
716-
BOOL fIsTransient = FALSE;
717-
718-
BEGIN_QCALL;
719-
720-
/* Only reflection modules can be transient */
721-
if (pModule->IsReflection())
722-
fIsTransient = pModule->GetReflectionModule()->IsTransient();
723-
724-
END_QCALL;
725-
726-
return fIsTransient;
727-
}
728-
729707
//******************************************************************************
730708
//
731709
// Return a type spec token given a byte array

src/coreclr/vm/ecalllist.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ FCFuncStart(gCOMModuleFuncs)
324324
QCFuncElement("GetScopeName", COMModule::GetScopeName)
325325
FCFuncElement("GetTypes", COMModule::GetTypes)
326326
QCFuncElement("GetFullyQualifiedName", COMModule::GetFullyQualifiedName)
327-
QCFuncElement("nIsTransientInternal", COMModule::IsTransient)
328327
FCFuncElement("IsResource", COMModule::IsResource)
329328
FCFuncEnd()
330329

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
11
Compat issues with assembly System.Reflection.Emit:
2-
MembersMustExist : Member 'public System.Reflection.Emit.ModuleBuilder System.Reflection.Emit.AssemblyBuilder.DefineDynamicModule(System.String, System.Boolean)' does not exist in the reference but it does exist in the implementation.
3-
MembersMustExist : Member 'public System.Reflection.Module System.Reflection.Emit.ConstructorBuilder.GetModule()' does not exist in the reference but it does exist in the implementation.
4-
MembersMustExist : Member 'public System.String System.Reflection.Emit.ConstructorBuilder.Signature.get()' does not exist in the reference but it does exist in the implementation.
5-
MembersMustExist : Member 'public System.Reflection.Module System.Reflection.Emit.MethodBuilder.GetModule()' does not exist in the reference but it does exist in the implementation.
6-
MembersMustExist : Member 'public System.String System.Reflection.Emit.MethodBuilder.Signature.get()' does not exist in the reference but it does exist in the implementation.
7-
MembersMustExist : Member 'public System.Diagnostics.SymbolStore.ISymbolDocumentWriter System.Reflection.Emit.ModuleBuilder.DefineDocument(System.String, System.Guid, System.Guid, System.Guid)' does not exist in the reference but it does exist in the implementation.
82
MembersMustExist : Member 'protected System.ModuleHandle System.Reflection.Emit.ModuleBuilder.GetModuleHandleImpl()' does not exist in the reference but it does exist in the implementation.
9-
MembersMustExist : Member 'public System.Boolean System.Reflection.Emit.ModuleBuilder.IsTransient()' does not exist in the reference but it does exist in the implementation.
10-
Total Issues: 8
3+
Total Issues: 1

src/mono/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.Mono.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,7 @@ public static AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyB
254254
return ab;
255255
}
256256

257-
public ModuleBuilder DefineDynamicModule(string name) => DefineDynamicModule(name, false);
258-
259-
public ModuleBuilder DefineDynamicModule(string name, bool emitSymbolInfo)
257+
public ModuleBuilder DefineDynamicModule(string name)
260258
{
261259
if (name == null)
262260
throw new ArgumentNullException(nameof(name));

src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.Mono.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,6 @@ public override string Name
209209
}
210210
}
211211

212-
public string Signature
213-
{
214-
get
215-
{
216-
return "constructor signature";
217-
}
218-
}
219-
220212
public ParameterBuilder DefineParameter(int iSequence, ParameterAttributes attributes, string? strParamName)
221213
{
222214
// The 0th ParameterBuilder does not correspond to an
@@ -313,16 +305,11 @@ public void SetImplementationFlags(MethodImplAttributes attributes)
313305
iattrs = attributes;
314306
}
315307

316-
public Module GetModule()
317-
{
318-
return type.Module;
319-
}
320-
321308
public override Module Module
322309
{
323310
get
324311
{
325-
return GetModule();
312+
return type.Module;
326313
}
327314
}
328315

src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,6 @@ public override CallingConventions CallingConvention
184184
get { return call_conv; }
185185
}
186186

187-
// FIXME: "Not implemented"
188-
public string Signature
189-
{
190-
get
191-
{
192-
throw new NotImplementedException();
193-
}
194-
}
195-
196187
/* Used by mcs */
197188
internal bool BestFitMapping
198189
{
@@ -278,7 +269,7 @@ internal MethodBase RuntimeResolve()
278269
return type.RuntimeResolve().GetMethod(this);
279270
}
280271

281-
public Module GetModule()
272+
internal Module GetModule()
282273
{
283274
return type.Module;
284275
}

src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,6 @@ public override string FullyQualifiedName
118118
}
119119
}
120120

121-
public bool IsTransient()
122-
{
123-
return true;
124-
}
125-
126121
public void CreateGlobalFunctions()
127122
{
128123
if (global_type_created != null)
@@ -596,8 +591,6 @@ internal int GetTypeToken(Type type)
596591
throw new ArgumentNullException(nameof(type));
597592
if (type.IsByRef)
598593
throw new ArgumentException("type can't be a byref type", nameof(type));
599-
if (!IsTransient() && (type.Module is ModuleBuilder) && ((ModuleBuilder)type.Module).IsTransient())
600-
throw new InvalidOperationException("a non-transient module can't reference a transient module");
601594
return type.MetadataToken;
602595
}
603596

0 commit comments

Comments
 (0)