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

Remove Reflection.Emit APIs #56153

Merged
merged 10 commits into from
Jul 29, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,6 @@ internal static AssemblyBuilder InternalDefineDynamicAssembly(
public ModuleBuilder DefineDynamicModule(string name) =>
DefineDynamicModuleInternal(name, emitSymbolInfo: false);

[DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod.
public ModuleBuilder DefineDynamicModule(string name, bool emitSymbolInfo) =>
DefineDynamicModuleInternal(name, emitSymbolInfo);

private ModuleBuilder DefineDynamicModuleInternal(string name, bool emitSymbolInfo)
{
lock (SyncRoot)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,11 @@ public override CallingConventions CallingConvention
}
}

public Module GetModule()
{
return m_methodBuilder.GetModule();
}

internal override Type GetReturnType()
{
return m_methodBuilder.ReturnType;
}

public string Signature => m_methodBuilder.Signature;

public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
{
m_methodBuilder.SetCustomAttribute(con, binaryAttribute);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -758,13 +758,11 @@ public bool InitLocals
set { ThrowIfGeneric(); m_fInitLocals = value; }
}

public Module GetModule()
internal Module GetModule()
{
return GetModuleBuilder();
}

public string Signature => GetMethodSignature().ToString();

public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
{
if (con is null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1598,20 +1598,6 @@ public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
// Regardless, this is a reliability bug.
internal ISymbolWriter? GetSymWriter() => _iSymWriter;

public ISymbolDocumentWriter? DefineDocument(string url, Guid language, Guid languageVendor, Guid documentType)
{
// url cannot be null but can be an empty string
if (url == null)
{
throw new ArgumentNullException(nameof(url));
}

lock (SyncRoot)
{
return DefineDocumentNoLock(url, language, languageVendor, documentType);
}
}

private ISymbolDocumentWriter? DefineDocumentNoLock(string url, Guid language, Guid languageVendor, Guid documentType)
{
if (_iSymWriter == null)
Expand All @@ -1623,8 +1609,6 @@ public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
return _iSymWriter.DefineDocument(url, language, languageVendor, documentType);
}

public bool IsTransient() => InternalModule.IsTransientInternal();

#endregion

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ internal class RuntimeModule : Module
[DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)]
private static extern void GetType(QCallModule module, string className, bool throwOnError, bool ignoreCase, ObjectHandleOnStack type, ObjectHandleOnStack keepAlive);

[DllImport(RuntimeHelpers.QCall)]
private static extern bool nIsTransientInternal(QCallModule module);

[DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)]
private static extern void GetScopeName(QCallModule module, StringHandleOnStack retString);

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

internal bool IsTransientInternal()
{
RuntimeModule thisAsLocal = this;
return RuntimeModule.nIsTransientInternal(new QCallModule(ref thisAsLocal));
}

internal MetadataImport MetadataImport => ModuleHandle.GetMetadataImport(this);
#endregion

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/assembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void Assembly::Init(AllocMemTracker *pamTracker, LoaderAllocator *pLoaderAllocat
#ifndef CROSSGEN_COMPILE
if (GetManifestFile()->IsDynamic())
// manifest modules of dynamic assemblies are always transient
m_pManifest = ReflectionModule::Create(this, GetManifestFile(), pamTracker, REFEMIT_MANIFEST_MODULE_NAME, TRUE);
m_pManifest = ReflectionModule::Create(this, GetManifestFile(), pamTracker, REFEMIT_MANIFEST_MODULE_NAME);
else
#endif
m_pManifest = Module::Create(this, mdFileNil, GetManifestFile(), pamTracker);
Expand Down
6 changes: 1 addition & 5 deletions src/coreclr/vm/ceeload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12442,7 +12442,7 @@ idMethodSpec Module::LogInstantiatedMethod(const MethodDesc * md, ULONG flagNum)
// ===========================================================================

/* static */
ReflectionModule *ReflectionModule::Create(Assembly *pAssembly, PEFile *pFile, AllocMemTracker *pamTracker, LPCWSTR szName, BOOL fIsTransient)
ReflectionModule *ReflectionModule::Create(Assembly *pAssembly, PEFile *pFile, AllocMemTracker *pamTracker, LPCWSTR szName)
{
CONTRACT(ReflectionModule *)
{
Expand All @@ -12468,9 +12468,6 @@ ReflectionModule *ReflectionModule::Create(Assembly *pAssembly, PEFile *pFile, A

pModule->DoInit(pamTracker, szName);

// Set this at module creation time. The m_fIsTransient field should never change during the lifetime of this ReflectionModule.
pModule->SetIsTransient(fIsTransient ? true : false);

RETURN pModule.Extract();
}

Expand Down Expand Up @@ -12498,7 +12495,6 @@ ReflectionModule::ReflectionModule(Assembly *pAssembly, mdFile token, PEFile *pF
m_pCeeFileGen = NULL;
m_pDynamicMetadata = NULL;
m_fSuppressMetadataCapture = false;
m_fIsTransient = false;
}

HRESULT STDMETHODCALLTYPE CreateICeeGen(REFIID riid, void **pCeeGen);
Expand Down
19 changes: 1 addition & 18 deletions src/coreclr/vm/ceeload.h
Original file line number Diff line number Diff line change
Expand Up @@ -3210,9 +3210,6 @@ class ReflectionModule : public Module
// This is used to allow bulk emitting types without re-emitting the metadata between each type.
bool m_fSuppressMetadataCapture;

// If true, then only other transient modules can depend on this module.
bool m_fIsTransient;

#if !defined DACCESS_COMPILE && !defined CROSSGEN_COMPILE
// Returns true iff metadata capturing is suppressed
bool IsMetadataCaptureSuppressed();
Expand Down Expand Up @@ -3244,7 +3241,7 @@ class ReflectionModule : public Module
#endif

#if !defined DACCESS_COMPILE && !defined CROSSGEN_COMPILE
static ReflectionModule *Create(Assembly *pAssembly, PEFile *pFile, AllocMemTracker *pamTracker, LPCWSTR szName, BOOL fIsTransient);
static ReflectionModule *Create(Assembly *pAssembly, PEFile *pFile, AllocMemTracker *pamTracker, LPCWSTR szName);
void Initialize(AllocMemTracker *pamTracker, LPCWSTR szName);
void Destruct();
#endif // !DACCESS_COMPILE && !CROSSGEN_COMPILE
Expand Down Expand Up @@ -3296,20 +3293,6 @@ class ReflectionModule : public Module
return &m_pISymUnmanagedWriter;
}

bool IsTransient()
{
LIMITED_METHOD_CONTRACT;

return m_fIsTransient;
}

void SetIsTransient(bool fIsTransient)
{
LIMITED_METHOD_CONTRACT;

m_fIsTransient = fIsTransient;
}

#ifndef DACCESS_COMPILE
#ifndef CROSSGEN_COMPILE

Expand Down
22 changes: 0 additions & 22 deletions src/coreclr/vm/commodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,28 +704,6 @@ void QCALLTYPE COMModule::SetModuleName(QCall::ModuleHandle pModule, LPCWSTR wsz
END_QCALL;
}

//******************************************************************************
//
// Return a type spec token given a byte array
//
//******************************************************************************
BOOL QCALLTYPE COMModule::IsTransient(QCall::ModuleHandle pModule)
{
QCALL_CONTRACT;

BOOL fIsTransient = FALSE;

BEGIN_QCALL;

/* Only reflection modules can be transient */
if (pModule->IsReflection())
fIsTransient = pModule->GetReflectionModule()->IsTransient();

END_QCALL;

return fIsTransient;
}

//******************************************************************************
//
// Return a type spec token given a byte array
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/vm/ecalllist.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ FCFuncStart(gCOMModuleFuncs)
QCFuncElement("GetScopeName", COMModule::GetScopeName)
FCFuncElement("GetTypes", COMModule::GetTypes)
QCFuncElement("GetFullyQualifiedName", COMModule::GetFullyQualifiedName)
QCFuncElement("nIsTransientInternal", COMModule::IsTransient)
FCFuncElement("IsResource", COMModule::IsResource)
FCFuncEnd()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
Compat issues with assembly System.Reflection.Emit:
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.
MembersMustExist : Member 'public System.Reflection.Module System.Reflection.Emit.ConstructorBuilder.GetModule()' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public System.String System.Reflection.Emit.ConstructorBuilder.Signature.get()' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public System.Reflection.Module System.Reflection.Emit.MethodBuilder.GetModule()' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public System.String System.Reflection.Emit.MethodBuilder.Signature.get()' does not exist in the reference but it does exist in the implementation.
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.
MembersMustExist : Member 'protected System.ModuleHandle System.Reflection.Emit.ModuleBuilder.GetModuleHandleImpl()' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public System.Boolean System.Reflection.Emit.ModuleBuilder.IsTransient()' does not exist in the reference but it does exist in the implementation.
Total Issues: 8
Total Issues: 1
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,7 @@ public static AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyB
return ab;
}

public ModuleBuilder DefineDynamicModule(string name) => DefineDynamicModule(name, false);

public ModuleBuilder DefineDynamicModule(string name, bool emitSymbolInfo)
public ModuleBuilder DefineDynamicModule(string name)
{
if (name == null)
throw new ArgumentNullException(nameof(name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,6 @@ public override string Name
}
}

public string Signature
{
get
{
return "constructor signature";
}
}

public ParameterBuilder DefineParameter(int iSequence, ParameterAttributes attributes, string? strParamName)
{
// The 0th ParameterBuilder does not correspond to an
Expand Down Expand Up @@ -313,16 +305,11 @@ public void SetImplementationFlags(MethodImplAttributes attributes)
iattrs = attributes;
}

public Module GetModule()
{
return type.Module;
}

public override Module Module
{
get
{
return GetModule();
return type.Module;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,6 @@ public override CallingConventions CallingConvention
get { return call_conv; }
}

// FIXME: "Not implemented"
public string Signature
{
get
{
throw new NotImplementedException();
}
}

/* Used by mcs */
internal bool BestFitMapping
{
Expand Down Expand Up @@ -278,7 +269,7 @@ internal MethodBase RuntimeResolve()
return type.RuntimeResolve().GetMethod(this);
}

public Module GetModule()
internal Module GetModule()
{
return type.Module;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,6 @@ public override string FullyQualifiedName
}
}

public bool IsTransient()
{
return true;
}

public void CreateGlobalFunctions()
{
if (global_type_created != null)
Expand Down Expand Up @@ -596,8 +591,6 @@ internal int GetTypeToken(Type type)
throw new ArgumentNullException(nameof(type));
if (type.IsByRef)
throw new ArgumentException("type can't be a byref type", nameof(type));
if (!IsTransient() && (type.Module is ModuleBuilder) && ((ModuleBuilder)type.Module).IsTransient())
throw new InvalidOperationException("a non-transient module can't reference a transient module");
return type.MetadataToken;
}

Expand Down