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

Propose the borrow operator #2693

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rjmccall
Copy link
Contributor

No description provided.


```swift
// Force the value of c to be borrowed. If c is somehow modified during
// this call, there may be an error at runtime.
Copy link
Contributor

Choose a reason for hiding this comment

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

"error at runtime" here implies that borrows carry runtime costs that do not apply to similar copies. Since most people's mental model seems to be that "borrow" is "pointer to" with no other overhead, that cost likely needs to be called out a little more explicitly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah. I see you've explored that in the borrows-by-default section at the end.

- *borrows*, which just read the low-level information in the value, or
- *copies*, which create a new, independent copy of that low-level
information according to the rules of the type.

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if there should be a footnote here that points out that "borrow" does not necessarily mean "pointer to." For small items, it's more efficient to "bitwise borrow" by (temporarily) copying the contents.

@rjmccall rjmccall added the LSG Contains topics under the domain of the Language Steering Group label Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LSG Contains topics under the domain of the Language Steering Group
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants