-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Tracking issue for Reflect
stabilization
#27749
Comments
I am in favor of it going away, I've had no use for it (and have heard of none) other than as necessary boilerplate whenever I want to do downcasting. I know of absolutely no types either in std or in the ecosystem which opt out of Reflect (and I can't really think of a good reason to do so). |
This is intentional. The point is precisely to prevent downcasting of opaque type parameters. |
I agree that the outcome of specialization is the key question. |
Nominating for 1.6 discussion |
@alexcrichton I do not understand, isn't the situation still :
(And, to my knowledge, specialiation is not settled?) |
That was part of the discussion I'd like to have :) With nonparametric dropck I wanted to check in on this and see if we could deprecate/remove, but if it still has to do with specialization then I think we'd just keep punting. |
@alexcrichton Yeah, it's tied to specialization. The change to dropck was a conservative one that will make room for specialization but doesn't imply that we give up on parametricity. |
Alex has been taught the error of his ways, so this issue is not moving into FCP this cycle. |
We discussed this in the @rust-lang/lang meeting. We would like to move this issue to final-comment period with the intention to deprecate and remove the Note: This final-comment-period lasts for (roughly) the current release cycle, which began on Aug 18, 2016. |
On the general topic of parametricity, there have been numerous comments. In an effort to summarize the conversation, I wanted to link to some of the most salient exchanges:
|
Reviewing this thread did reveal one interesting thing to me: the opt-in proposal still relied on the |
Also, @eddyb has pointed out a few times that the current |
@nikomatsakis Do you mean specialization can "remove" the requirement? Because that's unsound (or rather, it would be for |
What I meant is that the specialization RFC does not mention the I am not sure of what relationship you see between |
@nikomatsakis Ah, sure, I was talking about a |
I'm curious what this means in the larger picture, not specific to this tracking issue. |
@withoutboats In a nutshell, it means that Rust will not attempt to ensure traditional parametricity for type arguments (i.e. that generic code behaves "equivalently" when instantiated with different types). This is already formally the case due to the ability to get the size of a type parameter, but we're opening the door to observable, behavioral differences under different type arguments. That means we will permit language features that let you write a function like: fn print<T>(t: &T) { ... } which e.g. prints its argument using The tradeoff is:
Note that all of the above is specific to type parameters. Lifetime parameters, on the other hand, are intended to remain parametric -- e.g. you can't change the behavior of your function depending on whether a given lifetime is |
In my opinion, strict parametricity is not so important, but explicit, algorithmic reflection almost always is a band-aid over a wrong abstraction which results in increasingly unmaintainable spaghetti. Having automatically determined aparametricity during monomorphization (so specialization) is fine, in my opinion, but making explicit downcasting a normal and commonly used part of the language would be a very negative change. The fact that its so hard to do this is one of the language's key selling points to me. That is, I'm comfortable with this: default fn print<T>(t: &T) { ... }
default fn print<T: Debug>(t: &T) { ... }
default fn print<T: Display>(t: &T) { ... }
fn print<T: Debug + Display>(t: &T) { ... } But I'm uncomfortable with something like this: fn print<T>(t: &T) {
if T::implements::<Display>() { ... }
else if T::implements::<Debug>() { ... }
else { ... }
} Partly this is an intuitive judgment, but some obvious advantages of the first:
|
I admit I have no horse in this race since I haven't gotten to use Rust for any projects, but I do follow the theoretical side of Rust. This discussion of introducing typecase puzzles me, particularly because Rust already supports ad-hoc overloading via traits, so why introduce yet another way to overload, and via a mechanism that is more limited to boot, ie. typecase is closed where traits are open? With impl specialization seemingly merged, zero-cost open overloading already seems available, so what's the real use for typecase, aside from reducing a little typing by avoiding trait and impls? |
|
You can already use |
@eddyb, if that was a reply to me, then:
|
Rust supporting dynamic multidispatch and specialization at the language level (2) would cause 1. |
Yes (2) implies (1). An if-chain discriminating on What am I missing? |
I don't understand, are you arguing against specialization as a whole? |
[tracking issue](rust-lang#27749)
Will it affect rustc-serialize? |
@e-oz Can you elaborate the question? Reflection in Rust allows some dynamic type checks, but it does not have any structural information like enumeration of struct fields or so, which I imagine could be what you mean? |
@bluss I didn't know it and thought rustc-serialize does use reflection. Thanks for clarification :) |
Ah the deprecation here has hit stable, so this issue is resolved! |
…chton vec: Write the .extend() specialization in cleaner style As far as possible, use regular `default fn` specialization in favour of ad-hoc conditionals. No intentional functional change. Code quality was validated against the same benchmarks that were used in initial trusted len development. This change is prompted by taking impressions from rust-lang#27749 (comment)
…chton vec: Write the .extend() specialization in cleaner style As far as possible, use regular `default fn` specialization in favour of ad-hoc conditionals. No intentional functional change. Code quality was validated against the same benchmarks that were used in initial trusted len development. This change is prompted by taking impressions from rust-lang#27749 (comment)
I'm a bit confused. |
I'm asking because of issue #39059. |
@est31 the trait itself was deprecated but not removed. As it was never stable, we can remove it in Rust 1.x. And it was deprecated in 1.14, so maybe we can consider removing it in 1.16. But I think the feature gate stays "active" until then, as you can still mention |
If we're going to remove |
@withoutboats I've created a PR to do such a crater run on: #39075 (I don't have any opinion on whether to remove Reflect or not). |
I started a crater run on @est31's PR. |
crater report by @brson on the PR above. |
I too am confused on why this issue is closed. I'm going to open it. =) I think we can remove |
Remove Reflect PR for removing the `Reflect` trait. Opened so that a crater run can be done for testing the impact: #27749 (comment) Fixes #27749
The
Reflect
trait is currently unstable. It was intended to narrow the use of things likeAny
for runtime introspection, to help retain parametricity properties. However, with impl specialization these properties would go away anyhow, so it's not clear how useful the trait would be.Thus, stabilization should wait at least until specialization is settled.
cc @reem @nikomatsakis @pnkfelix
The text was updated successfully, but these errors were encountered: