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

Discards, tuples and out variables #664

Merged
merged 45 commits into from
Apr 6, 2023

Conversation

MadsTorgersen
Copy link
Contributor

This is a very rough cut of discards, tuples and out variables, and is here for discussion/sharing purposes. It lacks examples and cross references throughout and doesn't touch on patterns at all. It's also missing treatment of additional declaration spaces at statement/expression level, as well as the syntactic short form var (a, b) in deconstruction.

The intent is to test out an alternative approach to #44, #63 and #596 along the lines suggested in #561, and to fill out several gaps in those PRs.

The approach differs in several ways:

  • Discards are proper variables, only without names. Otherwise, the treatment of out vars cannot explain where the variable comes from that is passed to the out parameter.
  • The entities on the left hand side of a deconstructing assignment are proper tuple expressions. Otherwise we cannot adequately account for when their elements are full-blown expressions.
  • A new expression classification for tuples helps describe when, whether and how tuples should be evaluated.
  • The variable-declaring capability of tuples and out variables is factored out into a new kind of expression, a "declaration expression" instead of adding new special cases to each of their productions.

I believe this approach is more correct now, and more resilient to future language additions. But there is still a ways to go to clean it up.

standard/conversions.md Outdated Show resolved Hide resolved
standard/types.md Outdated Show resolved Hide resolved
standard/variables.md Outdated Show resolved Hide resolved
Copy link
Contributor

@jskeet jskeet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Submitting the comments as far as I've got. (More reading and thinking to do.)

standard/conversions.md Outdated Show resolved Hide resolved
standard/expressions.md Show resolved Hide resolved
standard/expressions.md Outdated Show resolved Hide resolved
standard/expressions.md Outdated Show resolved Hide resolved
@BillWagner BillWagner self-requested a review November 2, 2022 21:37
Make sure evaluation order is described precisely in deconstructing assignments.
@BillWagner BillWagner added this to the C# 7.x milestone Nov 30, 2022
standard/variables.md Outdated Show resolved Hide resolved
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this approach. I likely went into details that were beyond where you've already speced things out, but I wanted to make sure I noted them, even if just to extend the TODO list.

This does make a number of concepts more cohesive.

standard/types.md Outdated Show resolved Hide resolved
standard/types.md Outdated Show resolved Hide resolved
standard/types.md Outdated Show resolved Hide resolved
standard/conversions.md Outdated Show resolved Hide resolved
standard/expressions.md Outdated Show resolved Hide resolved
standard/variables.md Show resolved Hide resolved
standard/expressions.md Outdated Show resolved Hide resolved
standard/expressions.md Outdated Show resolved Hide resolved
standard/expressions.md Outdated Show resolved Hide resolved
standard/expressions.md Outdated Show resolved Hide resolved
@MadsTorgersen
Copy link
Contributor Author

Current status - the PR is taking shape but the following work is still TODO:

  • Examples of Declaration expressions, Discards, Tuple expressions and Deconstructing assignments
  • Add declaration_expression to Declaration Spaces where necessary
  • Generalize scope to not just be blocks where necessary (to allow expression bodies with declaration expressions)

The scope of this PR will not include patterns.

standard/expressions.md Outdated Show resolved Hide resolved
@RexJaeschke
Copy link
Contributor

Re discards, I propose adding the following text to lexical-structure.md, near the end, just before the mention of identifiers starting with __:

The semantics of an identifier named _ depends on the context in which it appears:

  • It can denote a named program element, such as a variable, class, or method, or
  • It can denote a discard (§discards-new-clause)

@RexJaeschke
Copy link
Contributor

Some editorial feedback:

  1. Replace all "legal" with "valid."
  2. For grammar blocks, replace all "[backticks][space]ANTLR" with "[backticks]ANTLR", so the tools can find them.
  3. For C# code blocks, replace "[backticks][space]c#" with "[backticks]csharp", so the tools can find them.

@MadsTorgersen MadsTorgersen changed the title Rough cut at discards, tuples and out variables Discards, tuples and out variables Jan 31, 2023
standard/types.md Outdated Show resolved Hide resolved
standard/variables.md Outdated Show resolved Hide resolved
@MadsTorgersen
Copy link
Contributor Author

This is missing several special behaviors for tuples, e.g. the behavior of ==.

The == and != behavior is now specified.

@jskeet
Copy link
Contributor

jskeet commented Mar 22, 2023

Agreed we're good to merge this - there are still tiny bits to do, but getting this in and then raising more bits will be better than trying to get it all the way.

@MadsTorgersen MadsTorgersen merged commit 8d3820b into draft-v7 Apr 6, 2023
BillWagner added a commit to BillWagner/docs that referenced this pull request Apr 7, 2023
dotnet/csharpstandard#664 added a few new sections which rippled through the TOC.
BillWagner added a commit to dotnet/docs that referenced this pull request Apr 7, 2023
* Unpublish feature specs

These two features are now incorporated into the draft V7 standard. Remove the feature speclets from docs.

* build issues

* missed a comma

* Yet another feature PR was merged

Update per new feature PR merged in the standard.

* address warnings from standard PR

dotnet/csharpstandard#664 added a few new sections which rippled through the TOC.

* warnings, take 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meeting: discuss This issue should be discussed at the next TC49-TG2 meeting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants