Skip to content

Conversation

@jckarter
Copy link
Contributor

No description provided.

Copy link
Contributor

@gottesmm gottesmm left a comment

Choose a reason for hiding this comment

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

Two small nits.

```

Notice how the compiler gives us all of the information that we need to resolve
this: it tells us where the move was and gives tells us the later uses that
Copy link
Contributor

Choose a reason for hiding this comment

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

gives tells looks like a thought stream being crossed.

}
```

we get separable nice diagnostics:
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure if nice is needed here. But I am fine with it staying ; ).

@hborla hborla self-assigned this Jul 19, 2022
@hborla
Copy link
Member

hborla commented Jul 21, 2022

Hi @gottesmm and @atrick, I'll be managing the review for this proposal! I just finished going through the pitch thread and reading the updated proposal. Here are my notes on reviewers' feedback that I think you should consider addressing in the proposal:

  • The term "binding" seems to have caused significant confusion in the pitch thread - consider defining it in the proposal.
  • The proposal is missing a "Motivation" section. The motivation is outlined in the introduction, but please put the motivation under a "Motivation" heading.
  • The alternative syntax suggestions are already covered in the proposal, but it may be helpful to more directly discuss the mentioned "potential impact to the language syntax" that is minimized by choosing to define move as a function.
    • For example, any was recently added as a contextual keyword in expression context, and to avoid stomping on the top-level any function, you cannot parenthesize the constraint operand to a contextual any keyword in expressions.
  • Clarification on what types of values can be passed to move
  • Justification for not annotating move with @discardableResult.
    • Michael addressed this in the pitch discussion, but I think it's worth adding to the proposal.
  • How move fits into the overarching ownership story, perhaps by linking the recent roadmap in a "Future Directions" section.

Let me know if you have any questions! I'll schedule this for review once you've had a chance to consider my notes.

Notice how in the above, we are able to use `x` both in the true block AND the
continuation block since over all paths, x now has a valid value.

The value based analysis uses Ownership SSA to determine if values are used
Copy link
Member

Choose a reason for hiding this comment

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

Is there a resource that can be linking out to here for folks who are not familiar with Ownership SSA?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should be referring to Ownership SSA in a language-level document. We should focus on what the compiler does, not how it does it.

tbkka
tbkka previously requested changes Jul 21, 2022
Copy link
Contributor

@tbkka tbkka left a comment

Choose a reason for hiding this comment

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

On the whole, the examples are good, but there's far too much discussion of how your particular implementation of the proposed feature works.

Here's a way to think about it: Pretend that some other group had implemented a from-scratch implementation of a Swift compiler. That compiler might not use SIL nor OSSA nor any other particular internal technology, but everything in this document should still be relevant to that other implementation.

useY(y) // do some stuff with local variable y
useX(x) // error, x's lifetime was ended at [1]

// Ends lifetime of y. Since _ is no-op, we perform an actual release here.
Copy link
Contributor

Choose a reason for hiding this comment

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

Whether there is a "release" depends on the type of x. Focus on the language implications:

  Ends the lifetime of the variable `y`.  Assigning to `_` avoids creation of a new lifetime.

I would also through here be careful to distinguish the lifetime of a "variable" from the lifetime of the "value" that may be temporarily stored in that value.


In this document, we propose adding a new function called `move` to the swift
standard library, which ends the lifetime of a specific local `let`,
local `var`, or `consuming` parameter. In order to enforce this, the compiler will
Copy link
Contributor

Choose a reason for hiding this comment

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

Overall suggestion for making markup documents easier to review: Put a line break after every full stop.

I suggest you add a sentence here after "parameter."

This gives developers a way to control retain/release operations and avoid
unnecessary copy-on-write behaviors in performance-critical code.

Then this paragraph will provide a good summary: A sentence saying what you propose, a sentence about why, and a sentence summarizing how the compiler will support this operation.

useY(y) // error, y's lifetime was ended at [2]
```

This allows the user to influence the uniqueness of COW data structures
Copy link
Contributor

Choose a reason for hiding this comment

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

I would start the "Motivation" section here, and reword things some to focus
on the problems that you're trying to solve:

Performance-critical code can suffer from unexpected copy-on-write operations
and unnecessary retain/release calls.
Consider the following array/uniqueness example:

}
```

in the example above, without `move`, `y`'s formal lifetime extends to the end of
Copy link
Contributor

Choose a reason for hiding this comment

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

Capitalize "In"

```


In the future, we may add support for globals and stored properties, although
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, you're talking about the implementation. You need to explain why you do not think the feature requires this support today.

Hmmm.... This paragraph might be better off moved to "alternatives considered".

}
```

Builtin.move is a hook in the compiler to force emission of special SIL "move"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should delete the rest of this section from this point.

At most, I would like to see a brief paragraph that says in essence that "Builtin.move() causes the compiler to perform additional data flow analysis to verify that the argument is not in fact used after this point." The details of how that is implemented in this particular compiler is not relevant; a different compiler may implement it in very different ways.

an SSA based analysis that determines if any uses of an address are reachable
from a move. All of these are already in tree and can be used today by invoking
the stdlib non-API function `_move` on a local let or move. *NOTE* This function
is always emit into client and transparent so there isn't an ABI impact so it is
Copy link
Contributor

Choose a reason for hiding this comment

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

This NOTE is useful to keep, since it explains the library implementation shown at the top of this section.


None, this is additive.

## Alternatives considered
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a reasonable place to explain why you don't think global support is necessary and could be considered separately.

term that has already been used in other Swift standard library APIs such as
the `UnsafeMutablePointer.move*` family of methods that move a value out of
memory referenced by a pointer. Declaring it as a function also minimizes the
potential impact to the language syntax. We are however open to discussing
Copy link
Contributor

Choose a reason for hiding this comment

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

Strike the sentence beginning "We are however open ..."

@jckarter
Copy link
Contributor Author

I'll go ahead and start working on the requested revisions. Thanks @hborla and @tbkka!

@jckarter
Copy link
Contributor Author

@hborla @tbkka How's this look now?

In this case, we get the following output from the compiler as expected:

```swift
test.swift:10:7: error: 'y' used after being moved
Copy link
Contributor

Choose a reason for hiding this comment

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

I would drop this entire example and just put the error message directly into the example above:

   useYAgain(y) // Error: 'y' used after being moved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@tbkka
Copy link
Contributor

tbkka commented Jul 21, 2022

Definitely improved. Still some work to do, but it's improving nicely.

Copy link
Member

@hborla hborla left a comment

Choose a reason for hiding this comment

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

Thank you!


If the binding is a `var`, the analysis additionally allows for code to
conditionally reinitialize the var and thus be able to use it in positions
that are dominated by the reinitialization. continuation path. Consider the
Copy link
Contributor

Choose a reason for hiding this comment

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

Extra words?

@hborla hborla dismissed tbkka’s stale review July 22, 2022 19:44

Feedback has been addressed

@hborla hborla merged commit e655bc1 into swiftlang:main Jul 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants