Skip to content

Champion "Permit stackalloc in nested expressions" (16.3, Core 3) #1412

Open
@gafter

Description

  • Proposal added
  • Discussed in LDM
  • Decision in LDM
  • Finalized (done, rejected, inactive)
  • Spec'ed

The Roslyn compilers have the machinery to rewrite expressions so that they occur in non-nested contexts if necessary. We use that mechanism as part of the translation of await. We could use it to easily permit stackalloc in contexts where they are not simply the initializer of a local declaration.

The specification would be something like:

Stack allocation

We modify the section Stack allocation of the C# language specification to relax the places when a stackalloc expression may appear. We delete

local_variable_initializer_unsafe
    : stackalloc_initializer
    ;

stackalloc_initializer
    : 'stackalloc' unmanaged_type '[' expression ']'
    ;

and replace them with one production in which the left-hand-side is primary_no_array_creation_expression and the right-hand-side is the stackalloc expression.

primary_no_array_creation_expression
    : 'stackalloc' unmanaged_type '[' expression ']'
    ;

Other changes to the stackalloc expression that occurred in C# 7.3 should be reflected as well.

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions