Skip to content

Latest commit

 

History

History
43 lines (31 loc) · 4.62 KB

iii.1.6-implicit-argument-coercion.md

File metadata and controls

43 lines (31 loc) · 4.62 KB

III.1.6 Implicit argument coercion

A method call involves the implicit assignment of argument values on the stack to the parameters of the called method (accessed using the ldarg, §III.3.38, or ldarga, §III.3.39, instructions). The assignment is an implicit stargIII.3.61) instruction and may be referred to as implicit argument coercion. In Verified CLI the validity of implicit argument coercion, as with the stargIII.3.61) instruction, is determined by the verifier-assignable-to relation (§III.1.8.1.2.3). Correct CIL also allows a native int to be passed as a byref (&); in which case following implicit conversion the value will be tracked by garbage collection.

The remainder of this clause contains only informative text.

While the CLI operates only on 6 types (int32, native int, int64, F, O, and &) the metadata supplies a much richer model for parameters of methods. When about to call a method, the CLI performs implicit type conversions, detailed in the following table. (Conceptually, it inserts the appropriate conv.* instruction into the CIL stream, which might result in an information loss through truncation or rounding) This implicit conversion occurs for boxes marked ✓. Shaded boxes Boxes marked nv are not verifiable. Boxes marked ✗ indicate invalid CIL sequences. (A compiler is, of course, free to emit explicit conv.* or conv.*.ovf instructions to achieve any desired effect.)

Table III.9: Signature Matching

Type In Signature Stack Parameter            
  int32 native int int64 F & O value type1
int8
Truncate

Truncate
unsigned int8,
bool

Truncate

Truncate
int16
Truncate

Truncate
unsigned int16,
char

Truncate

Truncate
int32
Nop

Truncate
unsigned int32
Nop

Truncate
int64
Nop
unsigned int64
Nop
native int
Sign extend

Nop
native unsigned int
Zero extend

Nop
float32 ✗ Note4
float64 ✗ Note4
Class
Value Type1 2
By-reference (Byref) (&)
Start GC trackingnv
Typed Reference (RefAny)3

1 A value type in a signature cannot be the long form of a built-in type (§II.23.2.15).

2 The CLI's stack can contain a value type. These can only be passed if the particular value type on the stack exactly matches the value type required by the corresponding parameter.

3 There are special instructions to construct and pass a RefAny.

4 The CLI is permitted to pass floating point arguments using its internal F type, see §III.1.1.1. CIL generators can, of course, include an explicit conv.r4, conv.r4.ovf, or similar instruction.

Further notes concerning this table:

  • The meaning of Truncate is defined for Table 8 above; Nop means no conversion is performed.

  • "Start GC Tracking" means that, following the implicit conversion, the item's value will be reported to any subsequent garbage-collection operations, and perhaps changed as a result of the item pointed-to being relocated in the heap.