Skip to content

Cleanup the shim code - #47865

Merged
bors merged 8 commits into
rust-lang:masterfrom
Manishearth:cleanup-shim
Feb 5, 2018
Merged

Cleanup the shim code#47865
bors merged 8 commits into
rust-lang:masterfrom
Manishearth:cleanup-shim

Conversation

@Manishearth

@ManishearthManishearth commented Jan 30, 2018

Copy link
Copy Markdown
Member

r? @eddyb

@Manishearth
Manishearthforce-pushed the cleanup-shim branch 3 times, most recently from d658161 to 973881dCompareJanuary 30, 2018 06:26
@Manishearth

Copy link
Copy Markdown
MemberAuthor

r? @nikomatsakis

This is a precursor to my patches for #47796 (which may need an rfc). @eddyb noticed that the tuple shim code was suboptimal and since I'm fixing that anyway might as well get these cleanups through.

Comment threadsrc/librustc_mir/shim.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you name this dest?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

done

Comment threadsrc/librustc/mir/mod.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Isn't this also 5 lines above?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

The confusion was "is it 0-indexed variant index, 1-indexed variant index, or the discriminant value". Basically, the fact that it says that it's zero for structs and unions suggests that it's perhaps nonzero for enums, and it's better if folks don't need to verify this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can just edit that part instead of adding more elsewhere... also you wrote AdtDef::fields instead of variants. And this shouldn't be in this PR anyway.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actually structs and unions have exactly one variant so the rephrasing can be even more enum-focused.

@kennytmkennytm added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 30, 2018
@Manishearth

Copy link
Copy Markdown
MemberAuthor

fixed

Comment threadsrc/librustc/mir/mod.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The newline seems misplaced. Also, we should avoid using "discriminant", because that's a different thing that may not be equal to the variant index. All the relevant code uses "variant index" (not "variant number").

Comment threadsrc/librustc_mir/shim.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please put this before rcvr_field and rename that to src.

Comment threadsrc/librustc_mir/shim.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please pass in ret_field from below as the destination (and rename it to dest_elem - also rcvr_field should be src_elem).

Comment threadsrc/librustc_mir/shim.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment is unfinished.

Comment threadsrc/librustc_mir/shim.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please make this function also write in-place.

Comment threadsrc/librustc_mir/shim.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you name this dest_field and put it before src_field?

Comment threadsrc/librustc_mir/shim.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should be named src not rcvr.

@Manishearth
Manishearthforce-pushed the cleanup-shim branch 2 times, most recently from 9dbce3f to fbb26eeCompareJanuary 30, 2018 13:42
@ManishearthManishearth changed the title Cleanup the shim code to write directly to RETURN_PLACECleanup the shim codeJan 30, 2018
@Manishearth

Copy link
Copy Markdown
MemberAuthor

done

Comment threadsrc/librustc_mir/shim.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should be named previous_field, I think.

@Manishearth
Manishearthforce-pushed the cleanup-shim branch 2 times, most recently from b113fed to 370315dCompareJanuary 30, 2018 14:20
Comment threadsrc/librustc_mir/shim.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

dest.i instead of return.i

@eddyb

Copy link
Copy Markdown
Contributor

cc @arielb1

@Manishearth
Manishearthforce-pushed the cleanup-shim branch 3 times, most recently from dcb07dd to ca17162CompareJanuary 30, 2018 15:29
@Manishearth
Manishearthforce-pushed the cleanup-shim branch 2 times, most recently from c94151b to 633e401CompareJanuary 30, 2018 16:00

@nikomatsakisnikomatsakis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems pretty good to me. A few nits/questions.

Comment threadsrc/librustc_mir/shim.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is there a test for whatever motivated this commit?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Without this commit everything ICEs. Everything.

Any code instantiating a clone shim of tuples or arrays or closures (libcore does) will break because the type used will be TySelf (not TyArray or TyClosure or whatever) and we'll get errors because we're trying to call .index() or .field() on a place that can't be indexed. I can leave a comment to this effect somewhere.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I mean I can see why this is wrong, but I'm a bit confused -- the code works now, afaik, right? Or is this just patching up some earlier commit of yours?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It breaks once the change to the array shim is made - anything that depends on the type (e.g. indexing or enum discriminants) starts breaking because it'd see an unsubstituted Self.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Thsi commit should be earlier in the series I think.

We basically don't hit it because we write to temporary Places and then copy and that works well. I don't recall the exact details, but eddyb can explain.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ok good enough

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Oh right yeah this doesn't break the tuple stuff but it does break the array stuff (and the enum stuff from my other PR)

Comment threadsrc/librustc_mir/shim.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: can we use rustfmt-style formatting here?

Comment threadsrc/librustc_mir/shim.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm, I think this is ok, but it's interesting that we can observe the mutations even on unwind etc. Do you know off hand @eddyb if this is already true? Seems like something that we will eventually want to be legal, though. Effectively you're giving in an &mut to the (uninitialized) RETURN_PLACE, so we can do what we want there.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

But I feel like this has been an interesting question at times in the UCG discussions (when precisely can we reuse places etc).

@Manishearth

Copy link
Copy Markdown
MemberAuthor

done

@nikomatsakis

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Feb 1, 2018

Copy link
Copy Markdown
Collaborator

📌 Commit 8a8f91b has been approved by nikomatsakis

@kennytmkennytm added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 1, 2018
@bors

bors commented Feb 5, 2018

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 8a8f91b with merge dd29d3d...

bors added a commit that referenced this pull request Feb 5, 2018
Cleanup the shim code
- We now write directly to `RETURN_PLACE` instead of creating intermediates
- `tuple_like_shim` takes an iterator (used by #47867)
- `tuple_like_shim` no longer relies on it being the first thing to create blocks, and uses relative block indexing in a cleaner way (necessary for #47867)
- All the shim builders take `dest, src` arguments instead of hardcoding RETURN_PLACE
r? @eddyb
@bors

bors commented Feb 5, 2018

Copy link
Copy Markdown
Collaborator

☀️ Test successful - status-appveyor, status-travis
Approved by: nikomatsakis
Pushing dd29d3d to master...

@bors
bors merged commit 8a8f91b into rust-lang:masterFeb 5, 2018
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@Manishearth@eddyb@nikomatsakis@bors@kennytm