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

RFC: String Reflection #2233

Closed
wants to merge 3 commits into
base: master
from

Conversation

Projects
None yet
7 participants
@mzabaluev
Contributor

mzabaluev commented Dec 3, 2017

Add link-time hooks to libcore that would allow the Debug implementation
for trait object types Any and Any + Send to:

  • type-check against the runtime's implementation of String,
    if one is available;
  • get the owned string's content if the type matches.

Rendered

@mzabaluev

This comment has been minimized.

Show comment
Hide comment
@mzabaluev

mzabaluev Dec 3, 2017

Contributor

NB: I have reused rust-lang/rust#46261 as the tracking issue for this would-be RFC.

Contributor

mzabaluev commented Dec 3, 2017

NB: I have reused rust-lang/rust#46261 as the tracking issue for this would-be RFC.

Show outdated Hide outdated text/0000-string-reflection.md Outdated
```rust
extern {
fn __rust_type_is_string(id: TypeId) -> bool;
fn __rust_downcast_string_as_str<'a>(p: *const Any) -> &'a str;

This comment has been minimized.

@sfackler

sfackler Dec 4, 2017

Member

~~~This is just &**(p as *const String).~~~

EDIT: oh this is for libcore?

@sfackler

sfackler Dec 4, 2017

Member

~~~This is just &**(p as *const String).~~~

EDIT: oh this is for libcore?

@Diggsey

This comment has been minimized.

Show comment
Hide comment
@Diggsey

Diggsey Dec 4, 2017

Contributor

It seems to me that there are a number of options that could make Any able to forward on any Debug implementation, not just for strings.

The most basic one would be adding a new method to the Any trait:

fn debug_fmt(&self, f: &mut Formatter) -> Result<(), Error> { ... }

The compiler would then use specialisation to forward calls to debug_fmt to the underlying Debug implementation for types where that exists. Otherwise it resorts to a default implementation which simply prints the type information.

Contributor

Diggsey commented Dec 4, 2017

It seems to me that there are a number of options that could make Any able to forward on any Debug implementation, not just for strings.

The most basic one would be adding a new method to the Any trait:

fn debug_fmt(&self, f: &mut Formatter) -> Result<(), Error> { ... }

The compiler would then use specialisation to forward calls to debug_fmt to the underlying Debug implementation for types where that exists. Otherwise it resorts to a default implementation which simply prints the type information.

@mzabaluev

This comment has been minimized.

Show comment
Hide comment
@mzabaluev

mzabaluev Dec 4, 2017

Contributor

@Diggsey impl Debug for Any is not generic; I'm not getting what specialisation do you mean?

Contributor

mzabaluev commented Dec 4, 2017

@Diggsey impl Debug for Any is not generic; I'm not getting what specialisation do you mean?

@Diggsey

This comment has been minimized.

Show comment
Hide comment
@Diggsey

Diggsey Dec 4, 2017

Contributor

@mzabaluev impl Debug for Any would not be specialised - it would be implemented to call the new debug_fmt on the Any trait.

The compiler automatically implements Any for all types - it would be this implementation that would be specialised for types which also implement Debug.

Contributor

Diggsey commented Dec 4, 2017

@mzabaluev impl Debug for Any would not be specialised - it would be implemented to call the new debug_fmt on the Any trait.

The compiler automatically implements Any for all types - it would be this implementation that would be specialised for types which also implement Debug.

@sfackler

This comment has been minimized.

Show comment
Hide comment
@sfackler

sfackler Dec 4, 2017

Member

The specialization based implementation does seem better, but it would (arguably) be a user-visible use of specialization which is still unstable. @aturon how iffy does using specialization in this way feel pre-stabilization?

Member

sfackler commented Dec 4, 2017

The specialization based implementation does seem better, but it would (arguably) be a user-visible use of specialization which is still unstable. @aturon how iffy does using specialization in this way feel pre-stabilization?

@mzabaluev

This comment has been minimized.

Show comment
Hide comment
@mzabaluev

mzabaluev Dec 4, 2017

Contributor

@Diggsey, I definitely like your proposed approach better! Compiler-provided template specialization has been beyond my grasp of evolution of Rust. I think introspective Debug on Any could wait for specialization to stabilize (to the necessary extent), rather than introduce yet another link time hack in the interim. Feel free to close this PR, and let's agree to submit your proposal in a more elaborate form.

Contributor

mzabaluev commented Dec 4, 2017

@Diggsey, I definitely like your proposed approach better! Compiler-provided template specialization has been beyond my grasp of evolution of Rust. I think introspective Debug on Any could wait for specialization to stabilize (to the necessary extent), rather than introduce yet another link time hack in the interim. Feel free to close this PR, and let's agree to submit your proposal in a more elaborate form.

@Centril Centril added the T-libs label Feb 23, 2018

@SimonSapin

This comment has been minimized.

Show comment
Hide comment
@SimonSapin

SimonSapin Jun 27, 2018

Contributor

This sounds like consensus to postpone until specialization is stable and have an alternative solution that uses it.

@rfcbot postpone

(Personally I’d prefer this to rely on some trait other than Debug so that the string’s contents can be accessed without escaping. Maybe Display or AsRef<str>. But that’s discussion for a future RFC.)

Contributor

SimonSapin commented Jun 27, 2018

This sounds like consensus to postpone until specialization is stable and have an alternative solution that uses it.

@rfcbot postpone

(Personally I’d prefer this to rely on some trait other than Debug so that the string’s contents can be accessed without escaping. Maybe Display or AsRef<str>. But that’s discussion for a future RFC.)

@rfcbot

This comment has been minimized.

Show comment
Hide comment
@rfcbot

rfcbot Jun 27, 2018

Team member @SimonSapin has proposed to postpone this. The next step is review by the rest of the tagged teams:

No concerns currently listed.

Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

rfcbot commented Jun 27, 2018

Team member @SimonSapin has proposed to postpone this. The next step is review by the rest of the tagged teams:

No concerns currently listed.

Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot

This comment has been minimized.

Show comment
Hide comment
@rfcbot

rfcbot Jun 27, 2018

🔔 This is now entering its final comment period, as per the review above. 🔔

rfcbot commented Jun 27, 2018

🔔 This is now entering its final comment period, as per the review above. 🔔

@AllenChong

This comment has been minimized.

Show comment
Hide comment
@AllenChong

AllenChong commented on cbebb61 Jul 2, 2018

@rfcbot

This comment has been minimized.

Show comment
Hide comment
@rfcbot

rfcbot Jul 7, 2018

The final comment period, with a disposition to postpone, as per the review above, is now complete.

By the power vested in me by Rust, I hereby postpone this RFC.

rfcbot commented Jul 7, 2018

The final comment period, with a disposition to postpone, as per the review above, is now complete.

By the power vested in me by Rust, I hereby postpone this RFC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment