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

Test Plan for Function Pointers feature #43321

Closed
AlekseyTs opened this issue Apr 13, 2020 · 5 comments
Closed

Test Plan for Function Pointers feature #43321

AlekseyTs opened this issue Apr 13, 2020 · 5 comments
Assignees
Labels
Area-Compilers Feature - Function Pointers Adding Function Pointers Test Test failures in roslyn-CI Test-Gap Describes a specific feature or scenario that does not have test coverage
Milestone

Comments

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Apr 13, 2020

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

@AlekseyTs AlekseyTs added Area-Compilers Test Test failures in roslyn-CI Test-Gap Describes a specific feature or scenario that does not have test coverage Feature - Function Pointers Adding Function Pointers labels Apr 13, 2020
@333fred
Copy link
Member

333fred commented Apr 16, 2020

Notes from test plan meeting:

Additional Tests:

  • Confirm the lang version approach used by native ints for function pointers
  • Test for target-typed default
  • Ensure that we have a test with restricted types
  • Common type inference with switch expressions (including target-typing)
  • Type inference with tuple type inside function pointer: void M<T, U>(delegate* [ ]<(T, U)> parameter)
  • Ensure we have tests with nint/nuint
  • Target-typed new tests.
  • Using alias tests.
  • Address of a partial method.
  • delegate* <void> x = () => { };
  • consider testing 'ref struct' parameters and returns (maybe obvious..)
  • consider testing MetadataAsSource as part of the IDE test pass
  • maybe test with anonymous type: new { A = (delegate* <void>)null }

Required:

  • Native int tests
  • Overloading tests
  • Custom modifiers around overriding and implementing
  • Retargeting

@tmat
Copy link
Member

tmat commented May 7, 2020

Added a checkbox for EnC.

@333fred
Copy link
Member

333fred commented May 12, 2020

Note: I'm not checking off the parsing box yet as we're going to be updating the syntax, but parsing as proposed today works.

@333fred
Copy link
Member

333fred commented May 12, 2020

Note: there is support for exact type inference for type parameters. The full rules need to be added to the spec and then implemented. It will likely be very similar to the rules for delegates.

This was referenced May 15, 2020
@jcouv
Copy link
Member

jcouv commented Oct 15, 2020

Just want to link to list of supported calling conventions in BCL for future reference.

@jcouv jcouv added this to the 17.2 milestone Mar 17, 2022
@jcouv jcouv modified the milestones: 17.2, 17.3 May 14, 2022
@arunchndr arunchndr modified the milestones: 17.3, Backlog Sep 12, 2023
@333fred 333fred closed this as completed Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Feature - Function Pointers Adding Function Pointers Test Test failures in roslyn-CI Test-Gap Describes a specific feature or scenario that does not have test coverage
Projects
None yet
Development

No branches or pull requests

5 participants