Skip to content

-Z extra-debug-info injects reference-count problem on @managed boxes #10609

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

Closed
pnkfelix opened this issue Nov 22, 2013 · 3 comments
Closed

-Z extra-debug-info injects reference-count problem on @managed boxes #10609

pnkfelix opened this issue Nov 22, 2013 · 3 comments

Comments

@pnkfelix
Copy link
Member

Caveat from the outset: The current ref-counting system will (or at least should) be replaced by a proper GC. I am fully aware of this, and I am fully aware that the test case below is making deliberate use of the ref-counting semantics.

Having said that... it still might be worth looking into this, since it might represent a bug in -Z extra-debug-info.

The bug is that the test below assert fails when compiled with -Z extra-debug-info:

% rustc a.rs && ./a
% rustc -Z extra-debug-info a.rs && ./a
warning: no debug symbols in executable (-arch x86_64)
task '<main>' failed at 'assertion failed: shared_count_at_outset == shared_count_at_finale', a.rs:29

The test (a.rs):

#[feature(managed_boxes)];
#[allow(unused_imports)];
use std::ptr;
use std::rt::local_heap;
use std::rt::local_heap::{MemoryRegion, Box};

fn sub(_prefix: &'static str, _x: ~Option<@int>) -> ~Option<@int> {
    debug!("{} x: {:?}", _prefix, _x);
    traverse_live_allocs();
    _x
}

fn subroutine_alloc() {
    #[allow(dead_assignment)];
    let mut x = ~None;
    x = sub("naughtyet", x);

    x = ~Some(@3);
    x = sub("allocated", x);

    *x = None;
    x = sub("overwrote", x);
}

fn main() {
    let shared_count_at_outset = traverse_live_allocs();
    subroutine_alloc();
    let shared_count_at_finale = traverse_live_allocs();
    assert!(shared_count_at_outset == shared_count_at_finale);
}

fn traverse_live_allocs() -> int {
    let bp : *mut Box = local_heap::live_allocs();
    debug!("bp: {:?}", bp);
    let mut cursor = bp;
    let mut count = 0;
    if cursor != ptr::mut_null() {
        loop {
            unsafe {
                debug!("{: >5d}: *cursor: \\{ ref_count: \
                         {}\n                  type_desc: \
                         {}\n                  prev: \
                         {}\n                  next: \
                         {}\n                  data: \
                         {:?}               \\}",
                         count,
                         (*cursor).ref_count,
                         (*cursor).type_desc,
                         (*cursor).prev,
                         (*cursor).next,
                         (*cursor).data );
                cursor = (*cursor).next;
            }
            count += 1;
            if cursor == ptr::mut_null() { break; }
            if cursor == bp { fail!("uh oh"); }
        }
    }
    count
}
@jdm
Copy link
Contributor

jdm commented Nov 23, 2013

What's the purpose of sub?

@pnkfelix
Copy link
Member Author

@jdm "purpose", you say? :)

I think sub is just an artifact of me cleaning up my original test case, which originally had the invocations of debug! and traverse_live_allocs invoked inline where we now have the invocations of sub.

(The fact that it is consuming and returning an ~Option<@int> is just an artifact of how I did that refactoring; I am pretty sure the problem described still occurs if you undo my refactoring and manually inline the body of sub into its call sites.)

@thestinger
Copy link
Contributor

The Gc<T> type has been removed.

flip1995 pushed a commit to flip1995/rust that referenced this issue May 5, 2023
…n, r=Manishearth

Fixes rust-lang#10609: Adds lint to detect construction of unit struct using `default`

Using `default` to construct a unit struct increases code complexity and adds a function call. This can be avoided by simply removing the call to `default` and simply construct by name.

changelog: [`default_constructed_unit_structs`]: detects construction of unit structs using `default`

fixes rust-lang#10609
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants