-
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
Remove static bound from type_id #1849
Conversation
One could not do any sensible reflection on lifetimes anyways, right? |
That's true of the current state of the world. What this RFC would let you do is get a type id for whatever you can stick in a |
How can you fetch data back? I can store something that points to the stack and then retrieve it with |
The motivating example would work like this:
I have an implementation of this in a sandbox repo. (Note it's just can we make this work? quality). This is a fairly specific motivating usecase, but this RFC is an important baby step towards expanding the scope of reflection traits. It'll let us start to experiment with building APIs outside of the standard library and understand the landscape better. |
No, you can't, I can put |
Note you can probably do this with less unsafe code than my example, because it returns data with a lifetime that isn't tied to the borrow of the map. It's probably not worth focussing on the exact semantics of that though. |
@eddyb Ah I see what you mean! Yup that's a problem, I'll take that design back to the drawing board and see what I can do. |
There is absolutely no way to use this with |
To be clear: you can't use the |
Hmm I see your point. The idea was to treat the type id as a unique id for the type at runtime, and rely on binding pointers to that data to concrete lifetimes as soon as possible. It's obviously much more subtle than I thought though. |
I don't know about |
What do you mean "satisfy"? How do you prevent me changing a lifetime from the upcast to the downcast? |
Instead of impl Any + 'static {
fn downcast_ref<T>(&self) -> Option<&T> where T: Any;
} as we have currently, we would have: impl<'a> Any<'a> + 'a {
fn downcast_ref<T>(&self) -> Option<&T> where T: Any<'a> + 'a;
} Here both the input (the (I think those |
"valid for the same lifetime" doesn't mean much. How do you prevent a |
Hm. We'd need to express that |
Again, "valid for some lifetime" doesn't mean anything when you don't know the actual type. Lile I said, what you want is a |
@eddyb in any case, this is the intrinsic; some (such as @sdleffler) would like to at least be able to play with it. |
I'd like to see an example usecase that is not unsound (also, can they not use an HRTB encoding?). |
@eddyb I don't know if you'd call it "sound", but I've been using On the other hand, I can keep |
@sdleffler I am now convinced there is a valid usecase, but we have to put a lot of warnings, because it's unusable for actually having a lifetime-parametrized |
My usecase, a scoped IoC container, is a bit of a bust since it relied on the lifetime of the container borrow being shorter than the lifetime of the reference it returned. I thought I had the scope of that reference nailed down but, as @eddyb has shown, you can't do that. So it's unsound as it stands. I'll just go back to using ref counting for that. @sdleffler I think you have a better case, I'll update the RFC to focus on the experiment/build with tools outside std, which is what you seem to be doing with |
@KodrAus
This is a locally nameless variable encoding for doing substitution in, say, a lambda calculus. The funny thing about this example is that lifetimes are actually totally irrelevant, and this works fine for me; I use phantom types here to ensure that I am correctly substituting say, an That said I'll be coming back to |
@sdleffler @eddyb I've replaced the motivation. It's a bit more hand-wavy now because I didn't want to describe the exact details of @sdleffler's usecase, but I can update it if you think that should be in there. What do you think of the new intrinsic idea, that's specifically stripping concrete lifetimes? I'm not sure what the maintenance burden would be for forking the type id if the main implementation was updated. So it may be a silly idea. |
FWIW the current intrinsic strips lifetimes (we can't actually preserve them to that point) and if you copy the libcore definition but remove |
Just curious if I understand the issue with |
@burdges Yeh, I think a great example @eddyb showed before is a tuple of |
I see. I hadn't even considered what happens if you get some |
I did specify a scheme that should be sound though, by using ATC (or a trait with a lifetime parameter). |
Hmm, this caveat from @eddyb:
is ... important to me. I would not be comfortable accepting this RFC if it were not for the above conditions (the most important one being that accessing this relies on an unstable feature anyway and would presumably remain behind that wall)... I am debating about whether the RFC itself is sufficiently clear about how limited its scope is ... but I guess we aren't ever planning to stabilize compiler intrinsics...? |
@rfcbot reviewed |
That’s right. Compiler intrinsics are permanently unstable. The caveat is that somebody proposing a stable wrapper later on might not know about this RFC at the time. That’s the most likely scenario to get a stable access to this intrinsic without |
I do not agree with this at all. I think compiler intrinsics happen to all be unstable right now, but I expect we will stabilize some of them sooner or later. |
Sorry, this was curt. To expand: I don't see any reason to say that "for ever and ever" we will never stabilize an intrinsic. For that matter, I view |
@pnkfelix You're right this is relying on the fact that the intrinsic is unstable and users have to go looking for it, otherwise its potential edges would be a bigger problem. I think documentation on the intrinsic should be enough to communicate those edges in this case, but there is more we could do, like add a new intrinsic without the bound and mark it For |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period is now complete. |
So now that the final comment period is complete what are the next steps for this RFC? |
The RFC will need to be merged. I just wrote up a description of the steps, here, as it happens... |
Huzzah! The @rust-lang/lang team has decided to accept this RFC. To track further discussion, subscribe to the tracking issue here: rust-lang/rust#41875 |
Have you considered opening an RFC for that? The syntax |
@mikeyhew I haven't, I don't even feel like I understand it. |
@glaebhoerl you're right, it is more complicated than I originally thought — if the type can't outlive @eddyb's suggestion of an |
Rendered