-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Logging unsafe removal #9593
Logging unsafe removal #9593
Conversation
loop {
match thing.next() {
Some(val) => {...}
None => break
}
} and the prelude isn't imported inside of |
Thanks, should be updated now! |
|
||
struct CrateMapT3 { | ||
struct CrateMap<'self> { |
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 could use this definition above, rather than duplicating them. (I think moving this above would only require changing the static
declaration in the extern
block, and possibly the signature of the windows function for retrieving the CrateMap.)
Very cool! Much much less |
} | ||
|
||
#[cfg(windows)] | ||
#[fixed_stack_segment] | ||
#[inline(never)] | ||
pub fn get_crate_map() -> *CrateMap { | ||
pub fn get_crate_map() -> &'static CrateMap { |
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.
I think this should give back Option<&'static CrateMap>
and rt::logging::init
should basically ignore the None case.
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.
That would make things like this not segfault https://gist.github.com/luqmana/6748487
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.
I'm not sure, in which case get_crate_map
should return None
?
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.
The way get_crate_map
works right now is that it relies on a _rust_crate_map_toplevel
symbol existing in the final executable that libstd gets linked against. This symbol is emitted by rustc when you're compiling an executable crate. But there are valid uses cases in which the symbol won't exist like in the gist I linked where you have a rust library that exports an extern fn that starts up the runtime by itself which is called by some C program. In that case, the final executable isn't a rust executable and hence the cratemap symbol doesn't exist and thus would be NULL causing a segfault right now since the logging setup currently assumes it is never NULL.
Thanks for the feedback. However, it seems like |
What's your (Also, the most recent changes look good.) |
After rebasing to the current master, all tests pass. Another point I'm looking into is converting |
Yes, |
} | ||
#[cfg(stage0)] | ||
/// Iterates recursively over `crate_map` and all child crate maps | ||
pub fn iter_crate_map<'a>(crate_map: &'a CrateMap<'a>, f: &fn(&ModEntry)) { |
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.
This seems like a bad idea to turn off all stage1 logging. It doesn't seem like you need the stage0
guard here?
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.
After changing the memory layout of CrateMap
the new code will segfault when compiled with the older stage0
compiler. We could bump the version number in the structure and keep the old code?
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.
Oh I see, it still seems a shame to lose all stage1 logging because I imagine it's used quite frequently.
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.
Take a snap soon after this lands?
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.
This or bumping the version number in the structure (I guess it was intended for cases like this)
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.
Let's bump the version number, I'll try to make a snap after this lands, but no guarantees.
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.
... with a goal to remove the old code after the next snapshot. (Since we're still not backward-compatible, I think we should take the opportunity to make the code as nice as possible now, while we still don't have handle logging from legacy libs.)
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.
I'll look into adding the old code again and add a note to delete it after the next snapshot. Btw, then we pobably could remove the CrateMapV0
struct as well?
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.
I don't see why not, I'd want to make sure with others, though, first.
I've pushed another commit, replacing I hope I'll be able to add the backward compatible code for the previous versions of CrateMap and the change suggested by @luqmana tomorrow. |
I've added the code for older versions of the CrateMap struct and the old test cases.
|
version: i32, | ||
entries: &'self [ModEntry<'self>], | ||
/// a dynamically sized struct, where all pointers to children are listed adjacent | ||
/// to the struct, terminated with NULL |
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.
This comment needs updating.
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.
I've removed it, the code should be expressive enough now I think.
This is pretty awesome, nice work! I'd be OK with some rebasings as well to clean up the commit history, but I don't really consider that a blocker either. Once we warn on a non-empty |
I've added the warning. Should I rebase everything in a big commit? I tried to address a part of the rewrite with every commit, but some could be squashed. |
} | ||
}, | ||
_ => { | ||
dumb_println("warning: RUST_LOG set, but no crate map found."); |
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.
This isn't necessarily true I think that you still need to test that os::getenv
returns Some
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.
Of course, I think I did push it too soon, sorry for that!
I don't think that this necessarily needs to become one large commit, but 11 seems a little excessive. Perhaps squashing a few of the intermediate commits? |
I think fixed the failure on windows (this cast is required, because sym is a But I have no idea why the other builds got interrupted during compilation (eg, http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-t/builds/968/steps/compile/logs/stdio ) |
If a build fails the other builds get interrupted, so that we're not wasting the CPU time. |
A thanks. It seems like there was something wrong with the |
This pull request changes to memory layout of the `CrateMap` struct to use static slices instead of raw pointers. Most of the discussion took place [here](fhahn@63b5975#L1R92) . The memory layout of CrateMap changed, without bumping the version number in the struct. Another, more backward compatible, solution would be to keep the old code and increase the version number in the new struct. On the other hand, the `annihilate_fn` pointer was removed without bumping the version number recently. At the moment, the stage0 compiler does not use the new memory layout, which would lead the segfaults during stage0 compilation, so I've added a dummy `iter_crate_map` function for stage0, which does nothing. Again, this could be avoided if we'd bump the version number in the struct and keep the old code. I'd like to use a normal `for` loop [here](https://github.com/fhahn/rust/compare/logging-unsafe-removal?expand=1#L1R109), for child in children.iter() { do_iter_crate_map(child, |x| f(x), visited); } but for some reason this only yields `error: unresolved enum variant, struct or const 'Some'` and I have no idea why.
Finally, thanks for all the feedback and patience. |
@fhahn Thank you! 😀 |
…hton This patch removes the code responsible for handling older CrateMap versions (as discussed during #9593). Only the new (safer) layout is supported now.
lint::unsafe_removed_from_name: fix false positive result when allowed changelog: [`unsafe_removed_from_name`] Fix allowing on imports produces a false positive on `useless_attribute`. Fixes: rust-lang#9197 Signed-off-by: Andy-Python-Programmer <andypythonappdeveloper@gmail.com>
This pull request changes to memory layout of the
CrateMap
struct to use static slices instead of raw pointers. Most of the discussion took place here .The memory layout of CrateMap changed, without bumping the version number in the struct. Another, more backward compatible, solution would be to keep the old code and increase the version number in the new struct. On the other hand, the
annihilate_fn
pointer was removed without bumping the version number recently.At the moment, the stage0 compiler does not use the new memory layout, which would lead the segfaults during stage0 compilation, so I've added a dummy
iter_crate_map
function for stage0, which does nothing. Again, this could be avoided if we'd bump the version number in the struct and keep the old code.I'd like to use a normal
for
loop here,but for some reason this only yields
error: unresolved enum variant, struct or const 'Some'
and I have no idea why.