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

Deconstruction assignment: basic implementation #11290

Closed
wants to merge 10 commits into from

Conversation

jcouv
Copy link
Member

@jcouv jcouv commented May 13, 2016

Here's a first basic implementation of deconstruction-assignment. I'm wondering if this should go into a feature branch instead as I only did limited IDE testing so far.

In terms of design:

  • The parsing was barely changed. It now allows a tuple literal on the left side of an assignment.
  • The binding for assignment forks off when such a tuple literal is found on the left:
    • The binding produces a new bound node (BoundDeconstructionAssignmentOperator). This bound node contains the list of variables on the left (bound and checked), the receiver for Deconstruct, the symbol for the Deconstruct method and information to complete the assignment of individual values (including conversions).
      -The Deconstruct method is resolved with restrictive rules at this point (we should find exactly one).
  • The lowering for this new bound node generates the following sequence:
    • lower the variables on the left,
    • get their side-effects and keep expressions to access them later without side-effect (like compound assignment does),
    • lower the right-hand-side expression (that will be the receiver for Deconstruct below),
    • prepare locals as out parameters,
    • invoke Deconstruct with those out parameters,
    • assign the values from those out parameters back into their proper left-hand-side variable (including conversions).
  • There is also some small change to the data flow logic, to ensure that variables on the left count as being assigned.

Vlad, the initial approach that we discussed for binding was very difficult (significant refactoring on tricky code). So the bound node holds onto the assignment expressions for each variable, as opposed to a Conversion object. Not only was this much simpler and natural, I think this will actually help later (when dealing with nesting case).

@dotnet/roslyn-compiler for review.

Tuple and underlying type unification. Part 1.
Tuple and underlying type unification. Part 2.
Tuple and underlying type unification. Part 3.
new BoundExpression[] { BindValue(arguments[0].Expression, diagnostics, BindValueKind.Assignment) } :
SpecializedCollections.EmptyArray<BoundExpression>();

return BadExpression(node, args);
Copy link
Member

Choose a reason for hiding this comment

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

You forgot to bind the right-hand-side here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll stop by to ask you more about this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@jcouv
Copy link
Member Author

jcouv commented May 13, 2016

Btw, I started a new work items list for deconstructions: #11299.

The known holes I'm tracking so far:

  • Return type issue
  • Refine data flow analysis to simulate final evaluation and order
  • Optimize the case where LHS variable is simple ref value
  • Nesting case
  • ValueTuple deconstruction, and System.Tuple too

/// Replaces substitution currently used by the rewriter for a placeholder node with a different substitution.
/// Asserts if there isn't already a substitution.
/// </summary>
private void UpdatePlaceholderReplacement(BoundValuePlaceholderBase placeholder, BoundExpression value)
Copy link
Member

Choose a reason for hiding this comment

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

Where is this used? It seems dangerous.

Copy link
Member Author

Choose a reason for hiding this comment

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

The 'update' is not used yet. I'll remove.

@gafter
Copy link
Member

gafter commented May 13, 2016

🕐

@jcouv
Copy link
Member Author

jcouv commented May 13, 2016

I'm closing this PR and will create a new one for the features/tuples branch after I work out the parsing issue.

@gafter gafter added the 4 - In Review A fix for the issue is submitted for review. label May 15, 2016
@jcouv jcouv closed this May 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants