-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Revise lang_item
demo to something unrelated to Box
impl
#22499
Revise lang_item
demo to something unrelated to Box
impl
#22499
Conversation
r? @brson (rust_highfive has picked a reviewer for you, use r? to override) |
The diff looks best in split view mode. |
(note that I'm no longer trying to land #22181 for alpha2, so this can wait until after the release.) |
odd, why doesn't homu list @steveklabnik as being assigned to this PR ? |
@steveklabnik note that if you have more aggressive plans for this part of the documentation, and do not wish to review this change, I can take the alternative approach of simply removing the |
@pnkfelix no, this looks good. I do have other plans for these docs, but I don't mind updating in the meantime. thanks! |
…loc-and-free, r=steveklabnik Revise `lang_item` demo to something unrelated to `Box` impl Precursor for landing overloaded-`box`, since that will decouple the `box` syntax from the exchange heap (and should eliminate the use of the two aforementioned lang items). Instead, the new demonstration program shows a definition of the `panic_bounds_check` lang item. (We do not have that many procedural lang-items to choose from, which is a good sign for our efforts to decouple the compiler from the runtime!) ---- Precursor for overloaded-`box` and placement-`in`; see Issue rust-lang#22181.
Needs Manishearth@a283a40 to pass doctests. I'm also getting this failure with the change in the rollup:
I can't repro it on nightly, so I might take this PR out of the rollup since I'm bad at debugging llvm. Sorry :( |
@bors: r- (This is probably going to need changes along the lines that @Manishearth outlined above.) |
So, what's up with this PR? |
@steveklabnik I haven't had time to investigate it too much; the last time I looked at it, I think I had thought there might be a different lang item I could override that would not require so much surrounding infrastructure (since that was indeed one of the nice things about this example as originally composed: how short it is)! |
Aside: Having a macro that brings in lang items would be interesting and might make this easier for people trying it out. Eg |
@Manishearth better still would probably be to just make |
I'm not very fond of implicit "hidden behavior" with lang items myself. If someone is using lang items, they're probably writing something low level. Also, which would we pick? Eg for Rust generally tries to be explicit over implicit, I'd prefer to continue that philosophy to lang items if we have to add any sort of auto-lang-item feature. |
@Manishearth I guess I was mostly thinking of the various trait lang items (e.g. I agree that for procedural lang items, it make sense to require them. |
Agreed on that. |
2b7f7f2
to
3b22ed8
Compare
I've rewritten the program again, so I think it needs another review. |
`Box` then there is no need to define functions for `exchange_malloc` | ||
and `exchange_free`. `rustc` will emit an error when an item is needed | ||
but not found in the current crate or any that it depends on. | ||
array indexing `a[i]` then there is no need to define a function for |
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.
Nit: Might need to be "array indexing (a[i]
)"?
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.
Yeah, this would make it consistent with evertying else
and one for deallocation. A freestanding program that uses the `Box` | ||
sugar for dynamic allocations via `malloc` and `free`: | ||
For example, there are lang items related to the implementation of | ||
string slices (`&str`); one of these is `str_eq`, which implements the |
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.
We already talk about this all the time, so you can just say 'string slices' or &str
, rather than both. I guess it doesn't hurt though.
@pnkfelix I like this example, it's a good one. One or two very minor nits, and then r=me |
…ed to Box. Precursor for landing overloaded-`box`, since that will decouple the `box` syntax from the exchange heap (and in fact will eliminate the use of the two aforementioned lang items). Instead, the new demonstration program shows a definition of the `str_eq` lang item. (We do not have that many procedural lang-items to choose from, which is a good sign for our efforts to decouple the compiler from the runtime!) (This previously used a demo of `panic_bounds_check`, but a `str_eq` demonstration is both easier to code and arguably a more interesting aspect of the language to discuss.)
3b22ed8
to
e5fab33
Compare
@bors r- (I think the arithmetic overflow work has introduced a dependence of |
I believe you can just run -----Original Message----- @bors r- |
@Manishearth There should be a target for doc tests, even at stage1, but it might be one per-crate or something unmanageable. |
(closing pull request; I'm going to fold this commit in with #22086 because I actually put that through a full |
Argh, something has changed in the last three months that broke the new demo. :( In particular, when I try to compile it (playpen), I get:
(Its possible that fixing this is just a matter of defining and importing the appropriate comparison traits. But if that is the case, it is ... depressing...) |
Perhaps we're missing the PartialOrd &c impls? |
Precursor for landing overloaded-box, since that will decouple the box syntax from the exchange heap (and should eliminate the use of the `malloc` and `free` lang items). (This is a simplified approach to PR rust-lang#22499; note that I have once again changes which lang item to use for the illustration.)
Revise
lang_item
demo to something unrelated toBox
implPrecursor for landing overloaded-
box
, since that will decouple thebox
syntax from the exchange heap (and should eliminate the use of the two aforementioned lang items).Instead, the new demonstration program shows a definition of the
panic_bounds_check
lang item.(We do not have that many procedural lang-items to choose from, which is a good sign for our efforts to decouple the compiler from the runtime!)
Precursor for overloaded-
box
and placement-in
; see Issue #22181.