Skip to content

Refactor layout to store offsets of fields, not offsets after fields#36904

Merged
bors merged 1 commit into
rust-lang:masterfrom
ahicks92:field_offsets_refactor
Oct 3, 2016
Merged

Refactor layout to store offsets of fields, not offsets after fields#36904
bors merged 1 commit into
rust-lang:masterfrom
ahicks92:field_offsets_refactor

Conversation

@ahicks92

@ahicks92 ahicks92 commented Oct 2, 2016

Copy link
Copy Markdown
Contributor

This is the next PR moving us towards being able to reorder struct fields.

The old code implicitly stored the offset of the first field. This is inadequate because the first field may no longer be offset 0 in future. This PR refactors layout to use a offsets vector instead of a offset_after_field vector.

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @nikomatsakis

(rust_highfive has picked a reviewer for you, use r? to override)

Comment thread src/librustc/ty/layout.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does eddyb's fixme still apply?
// FIXME(eddyb) use small vector optimization for the common case.

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.

Yes it does.

@ahicks92

ahicks92 commented Oct 2, 2016

Copy link
Copy Markdown
Contributor Author

@mark-buer
Probably, but I'm not concerned with that here unless those functions end up being broken.

The small vector optimization isn't about that struct, it's about avoiding a heap allocation in the compiler itself in some cases. I don't think it's worth it, unless someone adds something to the compiler that can be used in all cases where small vector optimization might be beneficial.

@ahicks92

ahicks92 commented Oct 2, 2016

Copy link
Copy Markdown
Contributor Author

Also, I should clarify: this isn't quite finalized yet.

@eddyb eddyb 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.

This looks great! I only had nits & minor extra cleanups to mention.

Comment thread src/librustc/ty/layout.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.

Yes it does.

Comment thread src/librustc/ty/layout.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.

No reason to keep this private and require the accessor.

Comment thread src/librustc/ty/layout.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.

Only reason for this method was the oddity of offset_after_field, direct access to offsets would be better.

Comment thread src/librustc_trans/glue.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 whole thing can be variant.offsets.last().map_or(0, |o| o.bytes()) - and local_prefix_bytes doesn't even need to exist as a separate function.

@ahicks92

ahicks92 commented Oct 2, 2016

Copy link
Copy Markdown
Contributor Author

I mixed up the SVO FIXME comments. My bad.

Is the small vector optimization anywhere outside layout? It seems to me that the way to fix this is to write something that implements a subset of Vec's API if we want it.

@ahicks92
ahicks92 force-pushed the field_offsets_refactor branch from 471352c to 9482bce Compare October 2, 2016 17:14
@ahicks92

ahicks92 commented Oct 2, 2016

Copy link
Copy Markdown
Contributor Author

The first set of review comments should be incorporated. I squashed the history as well, so it's one commit.

Think all that's maybe left is formatting.

@eddyb

eddyb commented Oct 2, 2016

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Oct 2, 2016

Copy link
Copy Markdown
Collaborator

📌 Commit 9482bce has been approved by eddyb

@bors

bors commented Oct 2, 2016

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 9482bce with merge 1cdc0fb...

bors added a commit that referenced this pull request Oct 2, 2016
Refactor layout to store offsets of fields, not offsets after fields

This is the next PR moving us towards being able to reorder struct fields.

The old code implicitly stored the offset of the first field.  This is inadequate because the first field may no longer be offset 0 in future.  This PR refactors `layout` to use a `offsets` vector instead of a `offset_after_field` vector.
@bors
bors merged commit 9482bce into rust-lang:master Oct 3, 2016
@ahicks92
ahicks92 deleted the field_offsets_refactor branch October 3, 2016 00:40
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.

6 participants