dotnet / csharplang

The official repo for the design of the C# programming language
11.56k stars 1.03k forks source link

IL-specific C# implementation spec #897

Open jnm2 opened 7 years ago

jnm2 commented 7 years ago

Best I can tell, the C# language spec doesn't specify how custom operators are translated to and from IL.

I wanted an exhaustive list of all specially-recognized operator method names (e.g. op_Modulus). The only place any op_* names show up in the spec is in explaining how to target operators in doc comments.

  1. Would you please maintain a single table mapping C# operator definition syntax to IL method name?
  2. Since the language seems to be at least coupled to the IL implementation names via the doc comments spec, though the syntax/IL mapping is never specified, wouldn't such a table belong as a specification nearer the operators section and not as an afterthought for doc comments?
HaloFour commented 7 years ago

IL has no concept of custom operators. The op_Whatever convention is simply one established and understood between the various compilers. Even then not all compilers agree exactly on those operator conventions which is why some languages have operators that others don't.

HaloFour commented 7 years ago

Oh, nevermind. Reading that again what you're looking for is that convention, at least as it relates to C#.

You might want to ask on the VB.NET and F# forums too as their answers will be slightly different.

svick commented 7 years ago

The ECMA CLI spec does contain informative mapping between operator names and C++ operators, in §I.10.3 Operator overloading.

Those C++ operators are largely the same as C# operators, but I understand if that's not good enough for you.

Maybe this shouldn't be part of the C# spec, but it could be part of Roslyn's documentation?

AnthonyDGreen commented 7 years ago

This might help: http://source.roslyn.io/#Microsoft.CodeAnalysis/Symbols/WellKnownMemberNames.cs,6d17843a3c182cb7

tannergooding commented 5 years ago

IL has no concept of custom operators.

IL doesn't, but the runtime spec (ECMA 335) does. It actually defines a number of "well-defined names". Most of which are supported by C#, but several of which (such as op_PointerDereference) are not. You can see Section I.10.3 Operator Overloading for more details.

BillWagner commented 3 years ago

Reviewed, and not moving to dotnet/csharpstandard. This shouldn't be part of the language standard, but should be documented elsewhere.