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

New Ownership Part 2 Lecture #50

Closed
wants to merge 16 commits into from
Closed

New Ownership Part 2 Lecture #50

wants to merge 16 commits into from

Conversation

connortsui20
Copy link
Member

Recovered from #41

@connortsui20 connortsui20 marked this pull request as ready for review January 24, 2025 16:32
Copy link
Member Author

@connortsui20 connortsui20 left a comment

Choose a reason for hiding this comment

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

@jespiron

Second pass review comments of the first section

Copy link
Member Author

Choose a reason for hiding this comment

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

Is this supposed to be a supplement or are we actually talking about this during lecture?

Copy link
Member

@jespiron jespiron Jan 24, 2025

Choose a reason for hiding this comment

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

Good question! We're not presenting the Downgrade slides, but I saved them in downgrade-mutable.md in case we add it back.

My reason for leaving them out was not timing concern (5 slides, about a minute or two) but its placement w.r.t the rest of lecture.

(1) The current placement of Downgrade isn't ideal, since it increases forgetting between when we introduce the concept "x can only take R..." here and call upon it here

Mutable References - introduces "x can only take R..."
[Optional] Downgrading Mutable References
Example: Fixing a Safe Program - calls upon "x can only take R..."

(2) If we discuss downgrading, ideally we provide an example of how understanding this concept can prevent common bugs. Also, I wonder whether students need to understand it to the low-level extent of RWO permissions, as opposed to high level "Cool, if you create an immutable reference, then the previous mutable reference is downgraded to immutable." I don't have an example as of now

Copy link
Member

Choose a reason for hiding this comment

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

Actually, since we can add 20 minutes more content, this can be among the topics we discuss

week5/plan.md Show resolved Hide resolved
week5/ownership_p2.md Show resolved Hide resolved
week5/ownership_p2.md Show resolved Hide resolved
week5/ownership_p2.md Outdated Show resolved Hide resolved
week5/ownership_p2.md Outdated Show resolved Hide resolved
week5/ownership_p2.md Outdated Show resolved Hide resolved
week5/ownership_p2.md Outdated Show resolved Hide resolved
week5/ownership_p2.md Outdated Show resolved Hide resolved
week5/ownership_p2.md Outdated Show resolved Hide resolved
@jespiron
Copy link
Member

jespiron commented Jan 25, 2025

I timed this to be 20 minutes, so definitely can add more content.
I put some ideas in more-examples.md. Ideally, we find problems where there's multiple solutions, or that could benefit from knowing RWO permissions

Edit: I added the Struct Double Free example after "Motivating Ownership," since it directly makes use of the idea that owners == stack frames

Copy link
Member Author

@connortsui20 connortsui20 left a comment

Choose a reason for hiding this comment

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

I think the example that motivates the ownership rules needs a bit of a rework, as there is a lot of stuff going on that even I had a bit of trouble trying to grok. See comments above more details



# Today
Copy link
Member Author

Choose a reason for hiding this comment

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

You can just say Ownership Revisited here too, no strong feelings about it

Today, we'll provide another way of thinking about ownership:

* Our goal: Transform ownership from a mysterious ruleset into an elegant problem-solving technique
Copy link
Member Author

Choose a reason for hiding this comment

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

Our goal: Transform ownership from a mysterious ruleset into an elegant problem-solving technique

Is this actually what this lecture teaches? I definitely agree with the 3 bullet points below but I'm wondering if this is a bit flowery for what we are actually saying

Copy link
Member

Choose a reason for hiding this comment

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

Please reword it however you like
Ideally some foundation for these questions

Today we're going to address these questions:

  • How do ownership rules prevent memory safety issues?
  • What makes the borrow checker reject seemingly safe code?

# The Catch

Getting code to compile is one thing. Understanding why is another.
Copy link
Member Author

Choose a reason for hiding this comment

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

another...


* Sometimes we follow the rules blindly
* Missing the principles, repeating mistakes
Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe instead of "Missing the principles, repeating mistakes" it could be:

When we break the rules, we may not fully understand why it is a problem

![bg right 100%](./img/frames/3-crop.png)

We have a 15GB vector?
Copy link
Member Author

Choose a reason for hiding this comment

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

Nit: 15 GB

![bg right 50%](./img/frames/0.png)

Inspired by the stack
Copy link
Member Author

Choose a reason for hiding this comment

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

Add colon at the end

Comment on lines +555 to +558
- Local variable "owned by" stack frame
- One stack frame (owner) per variable
- Dropped on function return
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 think it is fine to have the "sound familiar" as a bullet point on the previous slide, I actually found the rewording here to be a bit confusing

Comment on lines 582 to 597

![bg right 100%](./img/frames/7-crop.png)

* Each value in Rust has an _owner_
* Owner is stack frame
* A value can only have one owner at a time
* When the owner goes out of scope, the value will be _dropped_
* Deallocate the value here
* Safe because only one owner

<!--Speaker note:
One owner at a time
Emphasize that v is grayed out in diagram
=> ownership transfer
-->
Copy link
Member Author

Choose a reason for hiding this comment

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

Is it possible to break this into 2 slides? The first slide can have all of this text, and the next slide can have only the text necessary to help describe the image?

struct Warrior {
name: String,
score: u64
Copy link
Member Author

Choose a reason for hiding this comment

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

add comma at the end of u64 and a newline in between the struct def and main (try to use rustfmt guidelines for all code blocks in slides as well)

week5/ownership_p2.md Show resolved Hide resolved
@jespiron
Copy link
Member

Ok, I added outline.md
A 64-line outline is easier to review and iterate than a 2000-line slides.md 😁

@jespiron
Copy link
Member

Resuming at #62

@jespiron jespiron closed this Feb 11, 2025
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.

2 participants