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

CLR enhancements for future features #166

Closed
leppie opened this issue Jan 29, 2015 · 15 comments
Closed

CLR enhancements for future features #166

leppie opened this issue Jan 29, 2015 · 15 comments

Comments

@leppie
Copy link
Contributor

leppie commented Jan 29, 2015

This is an open-ended discussion for enhancements to the CLR that is required to accommodate new features that cannot be implemented on the current runtime or by the compiler.

As with PEVerify, enhancements should be categorized as MD (metadata) or IL.

An example of such a CLR enhancement would be variadic generic type parameters for optimal dispatching and verification.

A hypothetical pondering thought: https://gist.github.com/leppie/f9c773ea0d69459d7021 (I dont see this happening any time soon)

@sharwell
Copy link
Member

Generic indexer properties cannot currently be represented in metadata, even though the backing accessor methods can.

Motivating example: http://stackoverflow.com/a/2178769

@mikedn
Copy link

mikedn commented Jan 29, 2015

Heh, variadic generics would probably be cool but of all possible things you could add to the runtime this is likely the most difficult to implement.

Do you know of a language that has this (apart from C++)?

@leppie
Copy link
Contributor Author

leppie commented Jan 29, 2015

@mikedn: Typed Racket has it, and follows a similar approach (like C++) with their macro system, 'instantiating' an implementation based on the callsite (or explicitly).

There is the following paper that describes the implementation details: http://www.ccs.neu.edu/racket/pubs/esop09-sthf.pdf

It also has a verification of the proposed implementation (which seems to map well to IL/MD requirements).

@ashmind
Copy link
Contributor

ashmind commented Jan 29, 2015

Some concept of shared type identity -- useful for merging all versions of e.g. new { X = 0, Y = "s" } into a single type over all loaded assemblies. Also useful for having anonymous function types, and maybe anonymous open generic function types.

There is TypeIdentifierAttribute, but it's limited to some interop scenarios.

@leppie
Copy link
Contributor Author

leppie commented Jan 29, 2015

@ashmind That almost sounds like anonymous classes in Java, but being really anonymous. Not sure if anything needs to be added to the CLR for that to happen. The compiler should be perfectly capable to determine what it needs at compile-time (and generate efficient code for it).

Example: For every anonymous class, the compiler could generate a matching interface. This type could be shared (or proxied) across assemblies/appdomains.

@ashmind
Copy link
Contributor

ashmind commented Jan 29, 2015

@leppie CLR work is to merge the type from all the loaded assemblies, so you could pass an instance created in one into another. You wouldn't be able to cast using compiler alone, unless compiler would take over all the casts in the code (and even then Reflection would fail).

I am not talking about only anon types, I am talking about marking any two types form diff assemblies as identical, as long as they have identical structure.

@ashmind
Copy link
Contributor

ashmind commented Jan 29, 2015

Another thing -- limited support for generics over <void>. Useful to have consistent algorithms over Func<T> and Action. The details can be ironed out, but example approach might be to return null if the void delegate return value is requested.

That might require some sort of opt-in on generic type, as T field; would be a very weird thing if T were allowed to be void in all cases.

@HaloFour
Copy link

@ashmind Reactive introduced the Unit struct for that purpose. And of course Java has the Void class. If the BCL had something similar then it could be used now, although some syntax candy to eliminate the need to return the null or Default value would be nice.

@redknightlois
Copy link

@jods4
Copy link

jods4 commented Jan 31, 2015

@HaloFour Void in Java has nothing special really. It's a regular final class that happens to contains Void.TYPE property. When Java says the moral equivalent of Task<Void>, it's a pun on words more than anything else. At runtime it's no different than Task<object>, and the return value exists, it's null. You could definitely do that in C# today if you wanted to.

@ashmind I think accepting void as a type argument is doable but it has a big impact on JIT. Basically all functions must return a value because you never know if they are going to be used in a delegate. That can be relatively cheap if your calling convention is to pass the return value in a register ;)

For sure it would simplify the duplicated code between Task and Task<T>, or Func<T> and Action. I don't see such a fundamental change with arguably small benefits happen in the CLR :(

The only language that I know of and which does that is Javascript (functions without return values actually "return" undefined) but it's a totally different beast (dynamic language, etc.)

@redknightlois
Copy link

Access to unsafe intrinsecs via Helper Methods for useful opcodes like PREFETCHxx that can be NOP or substituted in architectures that don't support them.

@MrJul
Copy link
Contributor

MrJul commented Feb 9, 2015

Support for Nullable<T> properties in attributes (with T restricted to a primitive type, that doesn't change). It's quite frustrating when you encounter it, and it's very puzzling that 1 isn't a constant in [SomeAttribute(SomeNullableInt32 = 1)] (because it's just syntactic sugar for new Nullable<int>(1)).

@HaloFour
Copy link

HaloFour commented Feb 9, 2015

@MrJul That would require additional runtime support, if I recall correctly. Would null be permitted? If so, how would that be encoded given that int is encoded as 4 bytes.

@MrJul
Copy link
Contributor

MrJul commented Feb 9, 2015

@HaloFour Yes, a CLR change is required, isn't that the point of this thread? :) It should be encoded as a bool and an int.

@redknightlois
Copy link

@mirhagk True, but the split in Python is not without its troubles... there are many libraries that have never been ported to 3.0 and trying to do so is a pain if you need them. Therefore, unless you are working on a 3.0 project many people choose to stick with 2.0.

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

No branches or pull requests

10 participants