Comments (7)
Ok, thanks. It's not a big deal, I was just surprised it didn't work. The same thing is possible just with item.GetType() == typeof(ReadOnlySpan<char>)
or typeof(T) == typeof(ReadOnlySpan<char>)
.
from roslyn.
@AaronRobinsonMSFT I am a bit confused by your IL example in the #73918 (comment) comment and by what https://github.com/dotnet/runtime/blob/main/docs/design/features/byreflike-generics.md says.
The https://github.com/dotnet/runtime/blob/main/docs/design/features/byreflike-generics.md#runtime-impact section says:
isinst
– Will always placenull
on stack.
box
;isinst
;br_true/false
– The box target type is equal to the unboxed target type or the box target type isNullable<T>
and target type equalities can be computed.
In the IL example (#73918 (comment)) we are boxing T
and unboxing some concrete ref struct. This doesn't match the requirement for the special IL sequence. The types are not equal. I interpret it as though types of both instructions (box
, isinst
) should be the same, statically, in IL, not merely at runtime.
And the statement that "isinst
always produces null
on stack" doesn't help either. Meaning, even if the sequence doesn't cause a runtime failure, the value on the stack will always be null
, therefore, even when type matches, the result will imply that it doesn't. The special IL sequence doesn't come with detailed description of its semantics, therefore I am still interpreting its semantics instruction-by-instruction. There is a phrase: "in cases where the result can be computed at JIT time and elided safely." However, this leaves us at the mercy of JIT behavior rather than prescribing/guarantying specific JIT behavior. Since I have no idea what exactly JIT is capable of at the moment, the phrase doesn't tell me much.
To summarize, I think that https://github.com/dotnet/runtime/blob/main/docs/design/features/byreflike-generics.md can benefit from clarification and various examples for special IL sequences. We can sync up on that offline. I would like this to be done before we start making any changes in compiler.
from roslyn.
The compiler errors here because the underlying runtime doesn't support this type of check. If the runtime provides a path for this check, I think we'd be willing to take advantage of it.
https://github.com/dotnet/runtime/blob/main/docs/design/features/byreflike-generics.md
from roslyn.
@jaredpar Just for my understanding and I accept I could be missing something here, the following IL sequences are optimized by the runtimes - test. This doesn't use the ldnull
pattern though, which is what I see is generated via SharpLab.io.
.method public hidebysig
instance bool BoxIsinstBranch(!T) cil managed
{
ldarg.1
// Begin sequence
box !T
isinst ByRefLikeType
brfalse.s NEXT_1
// End sequence
NEXT_1:
from roslyn.
@jaredpar and I chatted and it looks I didn't call out the fact that certain IL sequences are special-cased by the runtimes. See https://github.com/dotnet/runtime/blob/main/docs/design/features/byreflike-generics.md#special-il-sequences. Usage of box
, isinst
and unbox.any
are permitted in narrow use cases.
from roslyn.
So this is expected to work and should be reopened?
from roslyn.
So this is expected to work and should be reopened?
Yes, I believe so.
from roslyn.
Related Issues (20)
- Hovering over a method gives the wrong overload
- Syntax highlight is half broken in both VS 17.10 and VS 17.11 P3
- False positive CS8618 null reference type warning when using required members and [SetsRequiredMembers] in derived class
- C# rename default constructor argument which is used as a property HOT 1
- Replacing using System with #include <stdio.h> in Roslyn C# Syntax Tree Rewriter HOT 3
- Debug assert triggered for interpolated string convserion
- "dotnet build-server shutdown" warning for missing dll HOT 3
- Enabling latest-All analyzers hangs build
- TestCode classification breaks in LSP for lines that begin with whitespace
- See squigglies in #if'd code but Quick Actions don't work. HOT 1
- Method name style is not consistent along the code HOT 1
- EnC: Emit System.Runtime.CompilerServices.HotReloadException
- Go to definition is not consistent with C# compilation when a symbol is missing HOT 8
- Auto-indent doesn't work in inline diff mode HOT 1
- $$ in source code causes test always to fail
- Nonsense identifier expected error depending on how you edit unrelated code HOT 1
- [Automated] PRs inserted in VS build feature.debugger.main-35118.200
- [Automated] PRs inserted in VS build main-35118.130
- IDE0270 creates invalid code HOT 2
- NuGet packages need to include a README.md HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from roslyn.