Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Add support for emitting finally regions in ILEmitter #27109

Merged
merged 1 commit into from
Oct 11, 2019

Conversation

MichalStrehovsky
Copy link
Member

@MichalStrehovsky MichalStrehovsky commented Oct 9, 2019

This will be needed to properly do cleanups in marshalling stubs.

The usage goes like (I couldn't come up with anything better):

ILExceptionRegionBuilder b = emit.NewFinallyRegion();
codeStream.BeginTry(b);
//...
codeStream.EndTry(b);
codeStream.BeginHandler(b);
// ...
codeStream.EndHandler(b);

@jakobbotsch
Copy link
Member

jakobbotsch commented Oct 9, 2019

I couldn't come up with anything better

In #26418 I added the same capability to the C++ versions of these classes and there I modeled the design after System.Reflection.Emit:
https://github.com/jakobbotsch/coreclr/blob/ef86c2584a19e4cfe05d61a2a98d215e32189016/src/vm/stubgen.cpp#L1059-L1126

The only difference seems to be that it keeps track of the try-catch in a stack inside the code stream. Just some food for thought.

@MichalStrehovsky
Copy link
Member Author

In #26418 I added the same capability to the C++ versions of these classes and there I modeled the design after System.Reflection.Emit

Oh, cool. Didn't realize that was there too!

I did it the awkward way (where one needs to hold on to the exception region builder) because I though it might be useful to be able to have regions/handlers spanning multiple ILCodeStreams. That might be of dubious value (I certainly don't need it now).

@jakobbotsch
Copy link
Member

I did it the awkward way (where one needs to hold on to the exception region builder) because I though it might be useful to be able to have regions/handlers spanning multiple ILCodeStreams. That might be of dubious value (I certainly don't need it now).

Ironically I think this would be needed to switch the current PInvoke stubs generated in the runtime to use the more general mechanism instead of its own custom thrown together thing, so maybe I should be using your design 😄

This will be needed to properly do cleanups in marshalling stubs.

The usage goes like (I couldn't come up with anything better):

```
var b = codeStream.BeginTry();
//...
codeStream.EndTry(b);
codeStream.BeginHandler(b);
// ...
codeStream.EndHandler(b);

emit.NewFinallyRegion(b);
```
@MichalStrehovsky
Copy link
Member Author

Cc @dotnet/crossgen-contrib

@jkotas jkotas merged commit a7ffbba into dotnet:master Oct 11, 2019
@MichalStrehovsky MichalStrehovsky deleted the emitFinally branch October 11, 2019 15:48
MichalStrehovsky added a commit to MichalStrehovsky/coreclr that referenced this pull request Oct 14, 2019
This is used to create MethodIL for the interop stubs. I introduced this field in dotnet#27109 but forgot to make a copy here.
jkotas pushed a commit that referenced this pull request Oct 14, 2019
This is used to create MethodIL for the interop stubs. I introduced this field in #27109 but forgot to make a copy here.
MichalStrehovsky added a commit that referenced this pull request Oct 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants