Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd RFC to feature gate some slice patterns #164
Conversation
lilyball
reviewed
Jul 14, 2014
|
|
||
| # Summary | ||
|
|
||
| Rust's support for pattern matching on sices has grown steadily and incrementally without a lot of oversight, |
This comment has been minimized.
This comment has been minimized.
lilyball
reviewed
Jul 14, 2014
| # Summary | ||
|
|
||
| Rust's support for pattern matching on sices has grown steadily and incrementally without a lot of oversight, | ||
| and we have concern that Rust is doing too much here, that the complexity is not worth it. This RFC proposes |
This comment has been minimized.
This comment has been minimized.
lilyball
Jul 14, 2014
Contributor
Who is "we"? Is this the general opinion of the Mozilla employees? Is this your personal opinion?
This comment has been minimized.
This comment has been minimized.
|
There was an extensive discussion recently about this issue (no link handy). I didn't follow it through to the end, but I thought it had established that a head-position slice ( I also had the impression that at least one person believed that a mid-position slice could be properly checked without as much complexity as initially thought, though as I said I didn't follow the discussion through to the end so I don't know if that was actually determined. Finally, how does our exhaustiveness check for slice patterns work today? This RFC suggests that it is known to work properly for tail-position slices, but not known to work properly for any other slice type, but what's the actual failure mode? |
This comment has been minimized.
This comment has been minimized.
|
cc @jakub- |
This comment has been minimized.
This comment has been minimized.
ghost
commented
Jul 15, 2014
|
@kballard Discussion you're referring to is #144. I made the mistake of filing that RFC without actually putting much/any thought into how slice patterns worked in the compiler. I closed it because I determined that we can make them work and indeed have no reason to believe that either the exhaustiveness or codegen parts are incorrect after the recent changes (though not sure about the latter, haven't spent much time there yet). I do not think there are any open issues for it at the moment. There's a long discussion in that RFC, parts of which seem to suggest that the feature is genuinely useful. I think feature gating would be fine, though (after all, we're not removing it).
True. Slice patterns are only part of the problem, though. They are treated by the match infrastructure a little differently than other types of patterns in that they complicate the compiled decision tree but so do guards.
Yeah, I think I agree but the same argument also applies to strings. Historically, rustc has removed match support for types that were no longer blessed by the language (~str, ~[T]) so if post-DST it'd be possible to do so with slices as well then maybe it's a good idea.
I don't think this is true any more. It's my fault I raised this alarm last time. Again, this is just feature gating so I wouldn't mind. It's a safer bet for most features the Rust team is uncertain about to be feature gated. But there's a balance there and a risk in growing the number of gated features to the point where most trivial Rust programs require at least one. However, last time I did run numbers on this one though it turned out slice patterns were only used a couple of times in the major Rust codebases. |
This comment has been minimized.
This comment has been minimized.
|
@jakub- I get the argument that "it's just feature-gating", but I don't see the benefit in adding a feature gate where there wasn't one previously if the feature currently works and there's no compelling reason to remove it. Adding a feature gate makes sense in the following situations:
I don't think any of that applies to slices. The only remaining reason is as a prelude to removing the functionality for reasons other than it not working, and I don't see there being any compelling reason to remove slice patterns. They are useful.
Did you ever run the numbers on what these codebases looked like back when |
This comment has been minimized.
This comment has been minimized.
ghost
commented
Jul 15, 2014
No, I did not. You have a point here. |
This comment has been minimized.
This comment has been minimized.
|
There's at least one more condition in which things should be feature gated:
|
This comment has been minimized.
This comment has been minimized.
|
I'd be fine with feature gating just out of caution, if there's any reason to be cautious, but otherwise I think that, arrays being a language primitive and a pretty important thing in general, our support for working with them should be as expressive and powerful as we can make it.
Arrays are built into the language (for good reason), while slices are references to arrays, existentially quantified over their length (DST). I.e. they arise from the combination of basic language features, rather than being one collection type among many singled out for special support by the language. (This is from the perspective of current/future Rust; obviously historically this wasn't the case.) |
This comment has been minimized.
This comment has been minimized.
|
There doesn't seem to be much motivation for slice patterns in their current form; they do make some things simpler, but when it was brought up before there weren't many uses of them found. The As discussed in #144, exhaustiveness checking in the case of a single unbounded |
This comment has been minimized.
This comment has been minimized.
|
@zwarich I think we could restore the subset of This kind of matching obviously doesn't solve everything, but it would allow me to restore some of the vector matching code in one of my projects that I lost when we could no longer match on A similar approach could then be use to allow matching on The only real weirdness to this approach that comes to mind is when using |
This comment has been minimized.
This comment has been minimized.
|
@kballard I thought that people generally wanted the |
This comment has been minimized.
This comment has been minimized.
|
@zwarich Getting it back for bind-by-move is indeed something that people (including I) would love to have. My overall point is that getting it back in the limited form of slices would be better than what we have today. Also FWIW, the |
alexcrichton
referenced this pull request
Sep 3, 2014
Closed
Feature gate some slice pattern features #16951
alexcrichton
merged commit 720e3ad
into
rust-lang:master
Sep 3, 2014
This comment has been minimized.
This comment has been minimized.
|
This was discussed in today's weekly meeting and it was decided to merge this as-is. |
brson commentedJul 14, 2014
text/tracking issue: rust-lang/rust#16951