Skip to content

Requiring RuntimeFeature.DefaultImplementationsOfInterfaces for C# 8 #1532

@jnm2

Description

@jnm2

@tannergooding has made a case that, if the C# 8 spec does not allow DIMs to be a fully optional language feature, then the C# 8 spec should at least require the standard library to provide the System.Runtime.CompilerServices.RuntimeFeature static class with a DefaultImplementationsOfInterfaces string constant. This would document a flag which signals the presence of runtime support for Default Interface Members (DIMs) which started in .NET Core 3.0. If this prerequisite is missing, the behavior could be specified to be either undefined (requiring nothing of the implementers) or implementation-defined (requiring the implementers to document what happens).

This standard library requirement serves to warn that C# 8 cannot be used on runtimes that don't support DIMs (since C# 8 no longer has a specification for what is allowed for interfaces sans DIMs). If the behavior when this flag is missing is undefined or implementation-defined, the spec would not have to fully maintain the original interface rules alongside the updated rules that allow DIMs.

What Roslyn does when the flag is missing is "switch off" the DIMs feature, abiding by the original interface rules, and any attempt to use default interface methods causes compile errors explaining why the feature is unavailable.

A hypothetical implementation would be free to choose to do that also, or it could refuse to compile C# 8 programs at all for that runtime, or it could successfully compile programs which fail to run on that runtime, or any other undefined or implementation-defined way to deal with the situation where it is infeasible to emit a program that uses DIMs and runs on a runtime whose features are as indicated by the standard library's RuntimeFeature class.

This would come up again several times with the new language versions, including with the RuntimeFeature.NumericIntPtr field, required for C# 11 to endow (U)IntPtr with all the features of n(u)int. On a runtime where this field is missing, the runtime is known to not be capable of the requirements of the C# 11 feature.

Alternatively, we could make DIMs a fully optional language feature, meaning that an implementation is fully compliant with C# 8 if it does not allow DIMs when compiling for some (or any) runtimes, and that to be compliant, the implementation must still maintain the prior rules for interface members sans DIMs. Or, that it must support DIMs when the flag is present, and must abide by the previous behavior when it is not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    meeting: discussThis issue should be discussed at the next TC49-TG2 meeting

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions