dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.12k stars 4.04k forks source link

Make Microsoft.Cci.RootModuleType methods virtual #40526

Open jakubmisek opened 4 years ago

jakubmisek commented 4 years ago

A proposal to make methods on Microsoft.Cci.RootModuleType virtual so it can be overridden. 3rd party compilers would be able to define static module constructors and other methods in there (which is in comply with MSIL specs)

Especially helpful would be to alter the method GetMethods https://github.com/dotnet/roslyn/blob/e09c42a1e779208b97f6dc122d47e27c2679004b/src/Compilers/Core/Portable/PEWriter/RootModuleType.cs#L139 to

public virtual IEnumerable<IMethodDefinition> GetMethods(EmitContext context)
jnm2 commented 4 years ago

I ran into this with https://github.com/dotnet/roslyn/issues/40500.

Would reimplementing the Cci.ITypeDefinition.GetMethods interface method be a good workaround, or are there cases where GetMethods is not called using the interface?

/cc @jcouv

jakubmisek commented 4 years ago

thank you! An implementation of Cci.ITypeDefinition.GetMethods providing some extension points would be sufficient.

As of now we had to re-implement the class just to make GetMethods to return a symbol for our .cctor

https://github.com/peachpiecompiler/peachpie/blob/a2b9abf1516c206c34cd8095076382bf85688d0a/src/Peachpie.CodeAnalysis/Emitter/Model/PhpRootModuleType.cs#L146

gafter commented 4 years ago

I understand this feature request is to enhance Roslyn's APIs to support 3rd party compilers. Supporting 3rd party compilers is not a goal of Roslyn, but I'll keep this feature request open.

jakubmisek commented 4 years ago

That's alright, thank you. It can be workarounded by copy-pasting the RootModuleType source.