-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
all but the last field of a tuple must be Sized #1592
Conversation
@arielb1 looks good, can you add an "Edit history" near the end with an entry like
|
@@ -719,7 +719,8 @@ declare one), but we'll take those basic conditions for granted. | |||
|
|||
WfTuple: | |||
∀i. R ⊢ Ti WF | |||
-------------------------------------------------- | |||
∀i<n. R ⊢ Ti: Sized // the *last* field may be unsized | |||
-------------------------------------------------- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation on this inference rule seems to have been lost
This is already the requirement for structs. This RFC PR is fixing that oversight. |
Yeah, I realized that, which is why I deleted the comment. |
Hear ye, hear ye! This RFC is now entering final comment period. |
I'm repeating myself, but this RFC seems to conflict with the representation ideas in /pull/1582, what do you think about that? |
The problem is that the ill-formed tuples cause ICEs. |
If we ever wanted to go with the tuple representation proposed in #1582 then this would need to be "all but the first field of a tuple must be
|
@arielb1 I mean that there are Rfcs that propose alternate tuple representations that directly conflict with allowing the last field be unsized, at least it is a conflict as I understand it. That needs to be addressed explicitly. For example, you could say it is best to have tuple fields be laid out in order with a possible flexible size field last. |
@bluss sorry, for the record can you summarize or give some pointers to the conflict? One problem I am aware of is that, if you try to use tuple types as the basis for "variadic generics", that would require tuple types that can permit multiple unsized values to be stored within them (but I don't think this is really tied to the representation per se. That is, the same problem arises regardless of how tuples are laid out in memory.) I've not been able to follow the other RFC thread in great detail, so I may not be caught up on the latest complications there. @arielb1 the fact that ICEs are caused doesn't seem, in and of itself, to mean much. =) It's more interesting to dig into the causes of those ICEs. Perhaps you can say more about that? There is definitely an inherent inconsistent in allowing tuples to have multiple unsized values but not structs, but perhaps a reconcilable one. I could also imagine some rules that say that a tuple type may contain multiple unsized values, but that such a type could not be used in most contexts, but it seems kind of complicated. In any case, I don't necessarily think that THIS RFC amendment is the right place to resolve this conflict. That is, I think that this RFC is (as @arielb1 suggested) adding something that ought to have been in the initial RFC to begin with. Rather, the onus is on later RFCs to make the WF rules for tuples more liberal and work out the conflicts that arise as a result (I believe such a change would be backwards compatible). |
@nikomatsakis Why would using tuple types as the basis for variadic generics require permitting multiple unsized values? As far as @eddyb and I could tell, they just required some compiler trait implementation support and they were fine. You can't actually pass unsized types. Note: incorrect assumptions. It's to do with being able to map over types, as someone explained to me. |
Causes ICEs = the tuple can't be represented, so unless we want to introduce a new |
@nikomatsakis RFC #1582 proposes being able to write tuples as a head-element, tail-tuple pair like so: If we take a few steps back we can fix this problem by changing the cons-cell syntax so that the Also I think it's an abuse of tuples to use them as lists of types. |
The current situation: none of the fields of a tuple are required to be What this RFC proposes: require the first N-1 fields of a tuple to be What's up for debate w.r.t. #1582: should we also require the last field of a tuple to be So I don't think this RFC and #1582 are in conflict. |
@glaebhoerl this RFC also further reinforces that the last field of the tuple is allowed to be ?Sized and that is a technical conflict with a reversed tuple representation. I was thinking of the simple case where the representation's last field is unsized. This RFC would in that sense mandate that tuples are explicitly ordered so that the logically last field is also last in the actual representation. That's a technical conflict with the proposal for "tuple slicing" in the other RFC which canndrew describes in this thread. I don't think that's a big deal, but it just needs some coordination or acknowledgement if you rule out an idea that is being developed in parallel. I think the current order of fields in the tuple representation is better, and that "tuple slicing" should instead destructure them into |
That is definitely something which should be debated and decided, but I don't see why it needs to hold up fixing the obvious bug that currently the first N-1 fields are allowed to be Maybe tweak the wording of the RFC text with respect to the last field if it's currently too definitive. But I don't think this should stop us from moving forward on the part that everyone agrees about. The debate about the last field can continue on #1582 which I think is a better place for it anyways. |
You're right, sorry, I was just worried that this RFC would solidify allowing the last field to be |
Yes, good point -- the reason is because of my desire to allow passing On Tue, May 10, 2016 at 07:01:17AM -0700, Nicole Mazzuca wrote:
|
I am, I admit, a bit torn. On the one hand, I think that this RFC On the other, if we did wind up wanting some change here that required But of course in practice it's all quite moot since the compiler So this is leading me to wonder if we should (for now) say that tuples On Wed, May 11, 2016 at 06:46:37AM -0700, Gábor Lehel wrote:
|
@nikomatsakis I don't think that passing an unsized type by value is a useful enough extension to the language to change tuples from being tuple struct like (over owned stack pointers); in fact, I haven't seen any change that makes me think that tuples should be any different from tuple structs. |
(that is useful enough to complicate the language into making tuples more than just an anonymous struct type) |
Well, I think this is quite unclear, in two respects. First, with respect to general utility, I consider passing unsized types by value a very useful extension to the language (and closing an unnecessary lack of symmetry). But in any case it's not a question that must be settled at this time. The second question is whether that would require making tuples be different from structs. One could imagine variadic generic systems that are not based on tuples. |
@nikomatsakis Allowing passing DSTs as function parameters is pretty much the only place where we could allow it; elsewhere, unsized types are not allowed (for example, in returns). It would open an unnecessary lack of symmetry in the language, IMO. |
@ubsan Couldn't DST returns, in principle, be allowed with the placement syntax? |
Huzzah! The @rust-lang/lang team has decided to accept this RFC. We debated going further (e.g., requiring that tuples consist purely of sized values) in the interest of maximum compatibility, but decided in the end that it was better to take the RFC as is, since it represents the most natural extension of the existing RFC. (It's still the case though that tuples with unsized values are not well supported by the existing compiler.) |
This oversight was found while working on rust-lang/rust#33138.
Tuples with an unsized field in the middle can't possibly work. Tuples with an unsized field at the end should work after we refactor
trans::adt
.