Uh oh!
There was an error while loading. Please reload this page.
Add DatatypeDef - #22564
Conversation
rust-highfive
commented
Feb 20, 2015
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see CONTRIBUTING.md for more information. |
eddyb
commented
Feb 20, 2015
I would prefer a name like |
There was a problem hiding this comment.
Doesn't/can't ty::expr_ty handle this?
There was a problem hiding this comment.
Ah right, that reminds me, I was going to fold the span_bug stuff into ty::expr_ty. Makes debugging easier.
eddyb
commented
Feb 20, 2015
LGTM modulo some nits, but I'd be happy with a second pair of eyes. |
alexcrichton
commented
Feb 20, 2015
(I'm probably not the right reviewer for this) |
nikomatsakis
commented
Feb 25, 2015
Sorry for the delay. I somehow missed this PR. |
There was a problem hiding this comment.
The current setup, iiuc, initially stores a ty_err and then updates it to the actual type. This seems like it will hide bugs where we read the type of a field before it is fully initialized. I would prefer to use Cell<Option<Ty<'tcx>>> and initially set it to None. Then ty can call self.ty.get().unwrap(), which will give the same (stronger) guarantees we get today. Similarly set_ty can check that the type is set exactly once. (There is no space inefficiency because Ty<'tcx> is a non-nullable-pointer.)
nikomatsakis
commented
Feb 25, 2015
ok, I have to run for the moment. I'm a big fan of this general approach. I've been wanting to see the struct/enum code made nicer (and unified!) for a long time, and I think moving away from storing all the information in distinct side-tables is generally a good idea. I've only had time though to read over the high-level details of what is here, so I'll want some more time to soak in finer points. |
There was a problem hiding this comment.
Nit: Please don't drop this comment.
nikomatsakis
commented
Feb 25, 2015
I think I'd like to see the /// A "write once" cell.pubstructIvar<T:Copy>{data:Cell<Option<T>>}impl<T:Copy>Ivar<T>{pubfnget(&self) -> Option<T>{self.data.get()}pubfnfulfill(&self,value:T){assert!(self.data.get().is_none());self.data.set(value);}pubfnunwrap(&self) -> T{self.get().unwrap()}}This has the advantage that (a) privacy ensures that we will only write to the cell once and (b) it can, in the future, be made |
Aatch
commented
Feb 26, 2015
I've squashed all the previous commits since rebasing was getting difficult due to functions being removed/replaced and me having to manually re-remove them post-rebase. I have also added the |
There was a problem hiding this comment.
Pre-existing,but this comment formatting is terrible.
nikomatsakis
commented
Feb 26, 2015
@Aatch I commented on a few points that were made before but not corrected in your latest rebase. Overall I'm pretty happy with this. One thing I was wondering -- perhaps it would make sense to merge |
nikomatsakis
commented
Feb 26, 2015
Modulo those nits though I'm ready to r+. |
There was a problem hiding this comment.
I personally know what an "I-var" is, but it might be nice to either have some comments here just saying what the big picture is about them, or a pointer to http://en.wikipedia.org/wiki/Futures_and_promises or something.
(This comment should have been on the struct definition itself)
Aatch
commented
Feb 27, 2015
@nikomatsakis yeah, I looked at merging them into a |
Add a DatatypeDef type that contains information for both structs and enums. Most places already treated structs like single-variant enums or vice-versa, so this actually simplifies a lot of code.
Adds an Ivar for write-once variables, and makes DatatypeDef use it. Removes some now-unused arguments.
Re-add removed comment in librustc_privacy Remove `vis` field from `VariantDef` Fixup weirdly-formatted comments in metadata::encoder
Documents `Ivar` and adds some common trait implementations for it
nikomatsakis
commented
Feb 27, 2015
r+ from me, but of course there are tidy errors it looks like |
bors
commented
Feb 28, 2015
☔ The latest upstream changes (presumably #22801) made this pull request unmergeable. Please resolve the merge conflicts. |
Ms2ger
commented
Feb 28, 2015
There's a lot of |
nikomatsakis
commented
Feb 28, 2015
I was thinking about |
eddyb
commented
Feb 28, 2015
@nikomatsakis sounds like an "OnceCell". |
pnkfelix
commented
Mar 1, 2015
@eddyb I am not 100% sure I would apply the |
eddyb
commented
Mar 1, 2015
@pnkfelix fair enough, I was just trying to force it into |
nikomatsakis
commented
Mar 17, 2015
@Aatch do you plan to rebase this? |
nikomatsakis
commented
Apr 8, 2015
@Aatch would you object if I rebased this? |
Aatch
commented
Apr 17, 2015
@nikomatsakis go for it. Sorry, I've been really busy with work + life recently, not much time for compiler-hacking. |
nikomatsakis
commented
Apr 17, 2015
@Aatch I started it. Lots of conflicts (of course). I might just try to cherry-pick and re-implement instead...gotta finish a few other things first. |
alexcrichton
commented
May 1, 2015
Closing in favor of @nikomatsakis's upcoming rebase |
Add a DatatypeDef type that contains information for both structs and enums. Most places already treated structs like single-variant enums or vice-versa, so this actually simplifies a lot of code.
There is a small but significant performance increase in typechecking and translation (pre-optimisations) of about 5% in both phases. All the other phases seemed to have some performance improvements too, but the differences were too small to be meaningful.
This change is also a step towards overall simplification of the type system code. Given how many places are now treating enums and structs completely identically, a move towards a unified
ty_datatype is somewhat feasible.