Skip to content

Test Plan for Function Pointers feature #43321

@AlekseyTs

Description

@AlekseyTs

This is a placeholder for a test plan for the set of changes related to Function Pointers C# 9.0 feature.
The feature specification is here https://github.com/dotnet/csharplang/blob/master/proposals/csharp-9.0/function-pointers.md

  • Language version tests.

    • Language version is checked for a function pointer type in syntax.
    • When function pointer types come from references (metadata or compilation), compilations targeting earlier versions of the language should probably be prevented from taking advantage of the feature. This scenario is similar to one for Native Int Types feature, should probably handle it the same way.
  • Use-site diagnostics are properly calculated for a function pointer type symbol and bubble up to fields, methods and properties as appropriate.

  • Generic substitution

    • A function pointer type cannot be used as a type argument
    • Cannot be used as generic type constraint
    • Verify generic substitution works within a function pointer types
      • Within return type
      • Within return type custom modifiers
      • Within ref custom modifiers
      • Within parameter type
      • Within parameter type custom modifiers
      • Within parameter ref custom modifiers
  • Retargeting, all constituent types (including custom modifiers) are properly re-targeted

  • Parsing of types follows https://github.com/dotnet/csharplang/blob/master/proposals/function-pointers.md#function-pointer-syntax

  • Binding of function pointer types

  • Cannot use static type within a function pointer type as return type or parameter type.

  • Function pointer types are properly encoded within signatures in metadata

  • Function pointer types are properly decoded within signatures in metadata

  • Use of function pointer types results in an error outside of unsafe context.

  • A function pointer can be invoked by supplying an argument list.

    • Ref-ness of arguments should match
    • Arguments should be implicitly convertible to parameter types
    • Result type is the return type of the function pointer
    • calli instruction is used in IL
  • Can construct an array of function pointer types

  • Test constants of a function pointer type

  • Test default parameter values

  • Conversions

    • No conversion to object or dynamic
    • There is an implicit conversion from null literal
    • There is an implicit conversion from a function pointer to void*
    • There is an explicit conversion from void* to a function pointer
    • There is an explicit conversion from any pointer type to a function pointer type and back.
    • There is an explicit conversion from sbyte, byte, short, ushort, int, uint, long, or ulong to any function pointer type and back.
    • The implicit and explicit reference conversions from a single-dimensional array type S[] to System.Collections.Generic.IList<T> and its generic base interfaces never apply to function pointer arrays, since pointer types cannot be used as type arguments
    • There is an implicit conversion between function pointer types as specified at https://github.com/dotnet/csharplang/blob/master/proposals/function-pointers.md#function-pointer-conversions
    • There is an implicit conversion from an address-of-a-method group as specified at https://github.com/dotnet/csharplang/blob/master/proposals/function-pointers.md#allow-address-of-to-target-methods
    • Target typed default
    • Target-typed switch expressions
    • Target-typed new
  • Operators

    • Pointer indirection ``*``` is disallowed
    • Pointer member access -> is disallowed
    • Pointer indexing [ ] is disallowed
    • Address of & is allowed
    • ++, --, +, - are disallowed
    • Pointer comparison operators ==, !=, <, >, <=, => are allowed.
    • Stackalloc can be used with an array of function pointers
    • sizeof works with function pointer types
    • typeof works with function pointer types
  • Overload resolution

  • Overloading

    • Overload on differing function pointer types
    • By parameter or by return type
    • Allowed on ref vs not for param/returns
    • Disallowed on in vs out/ref vs ref readonly
  • Common type inference

    • Array initializers
    • Conditional expression
    • Lambda return type
  • Overriding

    • It is possible to override a method/ property/event with a function pointer in its signature
    • Calling convention, ref-ness, return type and parameter types should match ignoring dynamic, nullability, custom modifiers, tuple names, array size and native int differences.
    • Custom modifiers and array sizes are inherited from the overridden method
    • Dynamic, tuple names, nullability and native int should be preserved from the overriding signature,
  • Implementing an interface

    • It is possible to implement a method/property/event with a function pointer in its signature
    • Calling convention, ref-ness, return type and parameter types should match ignoring dynamic, nullability, custom modifiers, tuple names, array size and native int differences.
    • Custom modifiers and array sizes are inherited from the implemented method for explicit implementations
      • Custom Modifiers
      • Array Sizes
    • Stubs are created for implicit implementations as appropriate to compensate for custom modifiers and array size differences within function pointer types.
    • Dynamic, tuple names, nullability and native int should be preserved from the implementing signature,
  • Tuples

    • Can be used in function pointers
    • Tuple names in function pointers are properly encoded in metadata
    • Tuple names in function pointers are properly decoded from metadata
    • Type inference with tuple type inside function pointer: void M<T, U>(delegate* [ ]<(T, U)> parameter)
  • Dynamic

    • Can be used in function pointers
    • Dynamic in function pointers is properly encoded in metadata
    • Dynamic in function pointers is properly decoded from metadata
  • Nullability

    • Annotations can be used in function pointers
    • Annotations in function pointers are properly encoded in metadata
    • Annotations in function pointers are properly decoded from metadata
    • Nullability mismatch is reported as appropriate around usage of function pointers in executable code
    • Nullability mismatch is reported as appropriate in other contexts
      • Base type
      • Implemented interfaces
      • Generic constraints
      • Overriding
      • Implicit interface implementation
      • Explicit interface implementation
  • Native Int

    • Can be used in function pointers
    • Native Int in function pointers is properly encoded in metadata
    • Native Int in function pointers is properly decoded from metadata
  • A function pointer type cannot be a this parameter of an extension method

  • A function pointer type cannot be used as a type of a constituent expression of a dynamically bound operation

  • A function pointer type may be used as the type of a volatile field

  • A special expansion is used to iterate over a multi-dimensional array of function pointers (https://github.com/dotnet/csharplang/blob/master/spec/unsafe-code.md#pointer-arrays)

  • Review existing checks for TypeKind.Pointer and adjust for function pointers as appropriate

  • Review existing checks for SymbolKind.PointerType and adjust for function pointers as appropriate

  • Restricted type safety (span)

  • Using aliases

  • Address of partial method

    • Implemented method
    • Not implemented method
  • Usage in anonymous types

  • Tests for public symbol model

    • Getting information about function pointer types
    • Creating function pointer type symbols
    • Equality
  • SemanticModel

    • GetTypeInfo on the function pointer type and inside
    • GetDeclaredSymbol on the function pointer type and inside
    • GetSymbolInfo on the function pointer type and inside
    • GetSymbolInfo/GetTypeInfo for address of
    • GetSymbolInfo/GetTypeInfo for invocation
  • IOperation support

    • Address of
    • Invocation
  • IDE Test pass

    • Language version bump is offered
    • Completion and formatting for/within function pointer types
    • Completion for delegate*
    • Completion for calling conventions
    • Highlighting/Colorization
    • Go to definition on entire type and constituent types
    • Find all references on entire type and constituent types
    • Quick info
    • Metadata as source
  • Edit and Continue

    • Symbol matcher might need an update
  • Other IDE scenarios

    • Symbol key and anything that depends on it?
  • APIs

Metadata

Metadata

Labels

Area-CompilersFeature - Function PointersAdding Function PointersTestTest failures in roslyn-CITest-GapDescribes a specific feature or scenario that does not have test coverage

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions