Skip to content

Fill out the borrowck chapter a bit more #234

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

Merged
merged 5 commits into from
Jan 11, 2019

Conversation

mark-i-m
Copy link
Member

@mark-i-m mark-i-m commented Nov 9, 2018

I'm planning to play around with the borrow checker a bit for a class project, so I've learning a bit more.

Please let me know if anything is inaccurate or incomplete.

r? @nikomatsakis @pnkfelix

@mark-i-m
Copy link
Member Author

cc #180

@nikomatsakis nikomatsakis self-assigned this Nov 20, 2018
Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

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

looks great. Left a few nits. I'm happy to land with typos fixed and keep iterating.


## Universal regions

*to be written* – explain the `UniversalRegions` type
The [`UnversalRegions`] type represents a collection of _unversal_ regions
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: "Universal" is misspelled as "unversal" in few places here. I think I would explain this through an example. Basically say something about how it computes information about the various named lifetimes in scope and their relationships to one another e.g., for the following function:

fn foo<'a>(x: &'a u32) { .. }

we would create a "universal region" 'a as well as 'static. (I really want to rename this, but anyway.)

That's probably good enough to start. The various categories of lifetimes around closures are interesting but maybe not needed 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.

TBH, I didn't dig into this part of the code, so I'm not really sure how it computes that info. I did add the other things you mentioned, though, and a note to add more.

The value of a region can be thought of as a **set**; we call the
domain of this set a `RegionElement`. In the code, the value for all
regions is maintained in
The value of a region can be thought of as a **set** of points in the MIR where
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't really complete. It's actually a set of points + a set of universal regions.

Copy link
Member Author

Choose a reason for hiding this comment

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

But adding a universal region is adding a set, no?

Also, the universal regions are the end('foo) elements, correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

I wondered if you would call me on that. =)

Yes, it's best I think to think of universal regions as "unknown sets", but they are not sets of points in MIR -- or at least they include points from outside the fn being investigated (to me, MIR implies "the source of one function).

I think it's also valid to think of a region as a "set of elements" where an "element" is a "MIR point" or "universal regions". That's certainly how it's implemented.

I guess I'm not sure what's the best way to describe it. I'm trying to remember if there is some point where the distinction is important. I'm also more and more trying to move into the polonius mindset, which is sort of different.

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 updated this sentence. Let me know what you think.

I'm trying to remember if there is some point where the distinction is important.

Perhaps something around placeholders?

I'm also more and more trying to move into the polonius mindset, which is sort of different.

Would it be better to stay in the "NLL" mindset here for consistency and add a new chapter on Polonius?


Here are some of the fields of the struct:

- `constraints`: contains all the outlives constraints.
Copy link
Contributor

Choose a reason for hiding this comment

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

can we link to the rustdoc here, or otherwise try to prevent bitrot?

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe not worth it, I have some thoughts on how to revisit this 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.

I tried to rework this section a bit to factor out the details from the meat. I also added an example.

I am a bit fuzzy on this part, so please let me know if you spot any problems. In particular, the example is a bit hand-wavey in some places...

we are inside a closure, we just collect all the constraints we can't prove yet
and return them. Later, when we are borrow check the MIR node that created the
closure, we can also check that these constraints hold. At that time, if we
can't prove they hold, we report an error.
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems fine, but really needs some examples

- `closure_bounds_mapping`: used for propagating region constraints from
closures back out to the creater of the closure.

TODO: should we discuss any of the others fields? What about the SCCs?
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like overall this discussion is a bit too focused on the "low-level details" and not much about the high-level process, but it seems like a good start.

@mark-i-m
Copy link
Member Author

Thanks Niko! I will take a look at your comments and update accordingly. It might be a little while though...

@nikomatsakis nikomatsakis merged commit 3f3f0e3 into rust-lang:master Jan 11, 2019
@nikomatsakis
Copy link
Contributor

Thanks @mark-i-m =) finally merged

@mark-i-m mark-i-m deleted the mir_borrowck branch June 15, 2019 21:10
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