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

Implement Stream.HasOverridenBeginEndXXX #72252

Merged
merged 2 commits into from
Jul 16, 2022

Conversation

MichalStrehovsky
Copy link
Member

Fixes dotnet/corert#3251.

Stream.HasOverriddenBeginEndRead/Stream.HasOverriddenBeginEndWrite are magic methods that call into the runtime on both CoreCLR and Mono to find out whether Stream.BeginRead/EndRead/BeginWrite/EndWrite are overriden on the current class.

Since we don't have a runtime in NativeAOT, implement this in the compiler. The answer to this question is expressible in IL: load function pointer to the method virtually and non-virtually and compare. I'm not calling into FunctionPointerOps because I can't imagine a scenario where this wouldn't work, but I can be persuaded to call to FunctionPointerOps to do the comparison.

Should make us pass all System.IO libraries tests.

Cc @dotnet/ilc-contrib

Fixes dotnet/corert#3251.

`Stream.HasOverriddenBeginEndRead`/`Stream.HasOverriddenBeginEndWrite` are magic methods that call into the runtime on both CoreCLR and Mono to find out whether `Stream.BeginRead`/`EndRead`/`BeginWrite`/`EndWrite` are overriden on the current class.

Since we don't have a runtime in NativeAOT, implement this in the compiler. The answer to this question is expressible in IL: load function pointer to the method virtually and non-virtually and compare. I'm not calling into `FunctionPointerOps` because I can't imagine a scenario where this wouldn't work, but I can be persuaded to call to `FunctionPointerOps` to do the comparison.

Should make us pass all System.IO libraries tests.
@MichalStrehovsky
Copy link
Member Author

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@jkotas
Copy link
Member

jkotas commented Jul 16, 2022

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jkotas jkotas merged commit fae5314 into dotnet:main Jul 16, 2022
@MichalStrehovsky MichalStrehovsky deleted the hasoverriden branch July 16, 2022 21:21
@TonyValenti
Copy link

This seems like a good use case for the proposed methodof() c# operator.

@MichalStrehovsky
Copy link
Member Author

This seems like a good use case for the proposed methodof() c# operator

Methodof is reflection and I don't think we can answer this efficiently with reflection. We would need LoadFunctionPointer and LoadVirtualFunctionPointer from dotnet/roslyn#11475

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NS2.0 Implement Synchronized(Stream).BeginRead() and BeginWrite()
3 participants