Make reprs use a structured representation instead of a slice #39595

Merged
merged 2 commits into from Feb 9, 2017

Conversation

Projects
None yet
3 participants
@camlorn
Contributor

camlorn commented Feb 6, 2017

This is needed for -z reorder-fields. The old design uses a slice taken from HIR, plus a cache that lazily parses. The new design stores it directly in the AdtDef as a ReprOptions. We're doing this now because we need to be able to add reprs that don't necessarily exist in HIR for -z reorder-fields, but it needs to happen anyway.

lookup_repr_hints should be mostly deprecated. I want to remove it from layout before closing this, unless people think that should be a separate PR. The [WIP] is because of this. The problem with closing this as-is is that the code here isn't actually testable until some parts of the compiler start using it.

r? @eddyb

src/librustc/ty/mod.rs
@@ -1818,6 +1847,14 @@ impl<'tcx> TyS<'tcx> {
}
}
}
+
+

This comment has been minimized.

@eddyb

eddyb Feb 6, 2017

Member

Extraneous empty line.

@eddyb

eddyb Feb 6, 2017

Member

Extraneous empty line.

src/librustc/ty/mod.rs
@@ -1818,6 +1847,14 @@ impl<'tcx> TyS<'tcx> {
}
}
}
+
+
+ pub fn get_repr(&self) -> Option<&ReprOptions> {

This comment has been minimized.

@eddyb

eddyb Feb 6, 2017

Member

This is only used in encoder.rs, could it be a helper method there?

@eddyb

eddyb Feb 6, 2017

Member

This is only used in encoder.rs, could it be a helper method there?

This comment has been minimized.

@camlorn

camlorn Feb 6, 2017

Contributor

Yeah, it could. But my thought is that things like future lints are going to want it as well.

@camlorn

camlorn Feb 6, 2017

Contributor

Yeah, it could. But my thought is that things like future lints are going to want it as well.

src/librustc_metadata/encoder.rs
@@ -401,8 +401,12 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
}
}
+ let repr_options = *self.tcx.item_type(adt_def_id).get_repr().expect(
+ &format!("{:?} is not an ADT", def_id)

This comment has been minimized.

@eddyb

eddyb Feb 6, 2017

Member

Probably not the best to have this allocating here. If you make an encoding-specific helper method you can just use bug! in cases other than TyAdt.

@eddyb

eddyb Feb 6, 2017

Member

Probably not the best to have this allocating here. If you make an encoding-specific helper method you can just use bug! in cases other than TyAdt.

This comment has been minimized.

@camlorn

camlorn Feb 6, 2017

Contributor

I'll factor those out.

@camlorn

camlorn Feb 6, 2017

Contributor

I'll factor those out.

@camlorn

This comment has been minimized.

Show comment
Hide comment
@camlorn

camlorn Feb 7, 2017

Contributor

I've moved all of this to a helper method in encoder.rs for now. We can introduce something more general later if needed.

Contributor

camlorn commented Feb 7, 2017

I've moved all of this to a helper method in encoder.rs for now. We can introduce something more general later if needed.

@camlorn

This comment has been minimized.

Show comment
Hide comment
@camlorn

camlorn Feb 7, 2017

Contributor

Unless we want me to try to kill more lookup_repr_hints calls, I think this is at a mergable point. it should at least be sufficient for -z reorder-fields if nothing else.

if someone wants to suggest a large crate with a lot of tests that I can build really quickly to see if metadata is actually working, that's not necessarily a bad idea.

Contributor

camlorn commented Feb 7, 2017

Unless we want me to try to kill more lookup_repr_hints calls, I think this is at a mergable point. it should at least be sufficient for -z reorder-fields if nothing else.

if someone wants to suggest a large crate with a lot of tests that I can build really quickly to see if metadata is actually working, that's not necessarily a bad idea.

@eddyb

This comment has been minimized.

Show comment
Hide comment
@eddyb

eddyb Feb 7, 2017

Member

@bors r+

Member

eddyb commented Feb 7, 2017

@bors r+

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Feb 7, 2017

Contributor

📋 Looks like this PR is still in progress, ignoring approval

Contributor

bors commented Feb 7, 2017

📋 Looks like this PR is still in progress, ignoring approval

@eddyb eddyb changed the title from [WIP] Make reprs use a structured representation instead of a slice to Make reprs use a structured representation instead of a slice Feb 7, 2017

@eddyb

This comment has been minimized.

Show comment
Hide comment
@eddyb

eddyb Feb 7, 2017

Member

@bors r+

Member

eddyb commented Feb 7, 2017

@bors r+

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Feb 7, 2017

Contributor

📌 Commit c3b64cf has been approved by eddyb

Contributor

bors commented Feb 7, 2017

📌 Commit c3b64cf has been approved by eddyb

bors added a commit that referenced this pull request Feb 8, 2017

bors added a commit that referenced this pull request Feb 8, 2017

bors added a commit that referenced this pull request Feb 8, 2017

Auto merge of #39652 - frewsxcv:rollup, r=frewsxcv
Rollup of 6 pull requests

- Successful merges: #38165, #39456, #39587, #39589, #39598, #39641
- Failed merges: #39586, #39595

bors added a commit that referenced this pull request Feb 9, 2017

Auto merge of #39663 - frewsxcv:rollup, r=frewsxcv
Rollup of 7 pull requests

- Successful merges: #37928, #39456, #39587, #39589, #39641, #39649, #39662
- Failed merges: #39586, #39595

bors added a commit that referenced this pull request Feb 9, 2017

Auto merge of #39663 - frewsxcv:rollup, r=frewsxcv
Rollup of 7 pull requests

- Successful merges: #37928, #39456, #39587, #39589, #39641, #39649, #39662
- Failed merges: #39586, #39595

frewsxcv added a commit to frewsxcv/rust that referenced this pull request Feb 9, 2017

Rollup merge of #39595 - camlorn:structured_repr, r=eddyb
Make reprs use a structured representation instead of a slice

This is needed for `-z reorder-fields`.  The old design uses a slice taken from HIR, plus a cache that lazily parses.  The new design stores it directly in the `AdtDef` as a `ReprOptions`.  We're doing this now because we need to be able to add reprs that don't necessarily exist in HIR for `-z reorder-fields`, but it needs to happen anyway.

`lookup_repr_hints` should be mostly deprecated.  I want to remove it from `layout` before closing this, unless people think that should be a separate PR.  The `[WIP]` is because of this.  The problem with closing this as-is is that the code here isn't actually testable until some parts of the compiler start using it.

r? @eddyb

bors added a commit that referenced this pull request Feb 9, 2017

Auto merge of #39686 - frewsxcv:rollup, r=frewsxcv
Rollup of 5 pull requests

- Successful merges: #39595, #39601, #39602, #39615, #39647
- Failed merges:

@bors bors merged commit c3b64cf into rust-lang:master Feb 9, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@camlorn camlorn deleted the camlorn:structured_repr branch Feb 9, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment