Skip to content

Test plan for "native ints" #38821

@jcouv

Description

@jcouv

Test plan for "native ints" #38821

Championed issue

  • ** Specification checked in to dotnet/csharplang
  • Open language issues (Open LDM issues with native integers csharplang#3259) resolved and implemented accordingly.
  • ** LangVersion
    • ** Blocks the use of the "reserved" words [NativeIntegerTests.LanguageVersion]
    • Blocks the use of the nint/nuint operators?
  • nint and nuint contextual keywords
    • bind to new types only when name lookup does not find a viable result [NativeIntegerTests.{ClassName, AliasName_*, MemberName_01}]
    • examples: [NativeIntegerTests.{NameOf_*, MemberName_02}]
      • nint x = 3;
      • _ = nameof(nint);
      • _ = nint.Equals(x, 3); [MemberName_02]
  • Compile-time constants in int and uint ranges [NativeIntegerTests.Constants_FromMetadata]
  • Constant folding supported for all unary and binary operators [NativeIntegerTests.ConstantFolding]
    • Compile-time evaluation in checked and unchecked contexts within int/uint ranges
    • Runtime evaluation in unchecked context otherwise (we have an open issue)
  • Conversions
    • Identity conversions between System.IntPtr and nint, and between System.UIntPtr and nuint [NativeIntegerTests.Conversions]
    • Common type of nint and IntPtr?
    • Common type of A<nint> and A<IntPtr> ?
    • Type inference when nint and IntPtr are both bounds
    • Identity conversions between arrays, Nullable<>, constructed types, tuples that differ only by native integers and underlying types
    • ImplicitNumeric conversions from integer types with smaller range to native integers; ExplicitNumeric otherwise [NativeIntegerTests.Conversions]
    • ImplicitNumeric conversions from native integers to integer types with larger range; ExplicitNumeric otherwise [NativeIntegerTests.Conversions]
    • Boxing/Unboxing conversions between object and native integer types [NativeIntegerTests.Conversions]
    • IEquatable<nint>
    • PointerToVoid conversions between void* and native integer types [NativeIntegerTests.Conversions]
    • Implicit/explicit nullable conversion from A to B? if implicit/explict conversion from A to B [NativeIntegerTests.Conversions]
    • Explicit nullable conversion from A? to B if identity or implicit/explicit conversion from A to B [NativeIntegerTests.Conversions]
    • Explicit nullable conversion from from A? to B? if implicit/explicit conversion from A to B [NativeIntegerTests.Conversions]
  • Built-in operators provided by the compiler: unary { ++, --, +, -, ~ }, binary { +, -, *, /, %, <, <=, >, >=, <<, >>, ==, !=, |, &, ^ }
    • Operations are emitted directly using IL operators for native integers [NativeIntegerTests.{UnaryOperators, BinaryOperators}]
    • Lifted operators provided by the compiler for the above [NativeIntegerTests.{UnaryOperators, BinaryOperators}]
    • SemanticModel exposes fake operator method syms
  • Overridiing, interface implementation, hiding consider native integers and underlying types as equivalent
    • Overrides and interface implementations may differ by native integers and underlying types alone [NativeIntegerTests.Overrides_*]
    • Overloads cannot differ by native integers and underlying types alone [NativeIntegerTests.Overloads_*]
    • Methods hide other methods that differ by native integers and underlying types alone [NativeIntegerTests.Overloads_*]
  • Type members from underlying types:
    • Constructors from underlying types are hidden for nint and nuint [NativeIntegerTests.ConstructorsAndOperators]
    • Operators from underlying types (including implicit and explicit conversion operators) are hidden for nint and nuint [NativeIntegerTests.ConstructorsAndOperators]
    • Instance and static members from underlying types are hidden except for an explicit opt-in list [NativeIntegerTests.{InstanceMembers, StaticMembers}]
    • Interfaces implemented by underlying types are implemented, with substitution for generic interfaces such as IEquatable<IntPtr> [NativeIntegerTests.Interfaces]
    • Request IComparable<nint> etc and we can expose it
  • Type unification of interfaces that differ by native integers and underlying types
  • No changes for dynamic: runtime binding to underlying types only
  • Can be used as default parameter value [NativeIntegerTests.Constants_ParameterDefaults]
  • Cannot be used as attribute argument (neither positional nor named arguments) [NativeIntegerTests.AttributeValue_*]
  • Native integers cannot be used as enum base type
  • Native integer fields may be marked volatile
  • typeof(nint) is typeof(IntPtr)
  • sizeof(nint) is supported in unsafe context only and is defined as sizeof(IntPtr) not IntPtr.Size [NativeIntegerTests.SizeOf_*]
  • Compiler diagnostics refer to nint and nuint rather than underlying types [NativeIntegerTests.ConstantConversions_*]
  • SymbolDisplay uses nint and nuint always regardless of SymbolDisplayFormat [NativeIntegerTests.TypeDefinitions_FromMetadata]
  • Metadata representation uses System.IntPtr and System.UIntPtr with additional NativeIntegerAttribute on containing type reference [AttributeTests_NativeInteger]
  • Doc for metadata representation in spec. NativeIntegerAttribute.md
  • Public API allows:
    • determine if ITypeSymbol is native integer: ITypeSymbol.IsNativeInteger [NativeIntegerTests.TypeDefinitions_FromMetadata]
    • get underlying INamedTypeSymbol for native integer: INamedTypeSymbol.NativeIntegerUnderlyingType [NativeIntegerTests.TypeDefinitions_FromMetadata]
    • get signed and unsigned native integer INamedTypeSymbol instances from compilation: Compilation.CreateNativeIntegerTypeSymbol() [NativeIntegerTests.CreateNativeIntegerTypeSymbol_FromMetadata]
  • Add NativeIntegerAttribute definition to .NET 5.0 (see Add NativeIntegerAttribute runtime#38683)
  • ** The semantic model GetTypeInfo API should return the new types when appropriate, even when compiling at an older language version. Language behavior agrees with semantic model.
  • The set of members of nint and nuint as seen through the language is tested to be as specified.
  • The set of built-in operators as seen through the language is tested to be as specified.
  • When using the built-in operators, they obey the appropriate checked/unchecked context for overflow, on platforms with 32-bit nints and 64-bit nints. [NativeIntegerTests.{UnaryOperators, BinaryOperators}]
  • Test that constant folding works as specified (including checked/unchecked) [NativeIntegerTests.ConstantFolding]
  • Test pattern-matching for nint constants, e.g. o is (nint)1
  • Test switching on a value of type nint. Do we generate an IL switch instruction?
  • Test decoding of nint in a modreq (we don't do it, intentional)

BCL

  • we should consider what Interlocked overloads the BCL/runtime should provide for those new types.

IDE Scenarios

Metadata

Metadata

Assignees

Labels

Area-CompilersTestTest failures in roslyn-CITest-GapDescribes a specific feature or scenario that does not have test coverage

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions