Skip to content

Adding support for extending objects with methods that override existing methods in the presence of self-calls #543

Closed

Description

@lkuper

This is tricky because we have to make sure that the meaning of 'self' is also overridden. Currently xfail'd test: src/test/run-pass/anon-obj-overriding.rs.

Activity

  1. ghost assigned on Jun 21, 2011
  2. lkuper commented on Jul 14, 2011

    @lkuper
    ContributorAuthor

    Status update: All the code (forwarding functions and such) is in place to support method overloading, but there's still at least one memory corruption bug to fix before I can close this issue. Here's a reduced test case:

    fn main() {
    
        obj a() {
            fn foo() -> int {
                ret 2;
            }
        }
    
        auto my_a = a();
    
        auto my_b = obj() {
            fn foo() -> int {
                ret 3;
            }
            with my_a
        };
    
        assert (my_b.foo() == 3);
    }
    

    my_b.foo() returns 3, as we want it to, but when this program runs under valgrind we get an invalid read followed by an invalid write. Here's what I've been able to suss out: the invalid read and write are happening in drop glue, when trying to decrement a refcount. In particular, we're trying to read from, then write to, a location that contains a refcount. Either it's not actually the location of the refcount we're supposed to be decrementing, or we are not actually supposed to be decrementing anyone's refcount; I don't know which. When we compile with -g, the name of the function in which the invalid read/write happen is _ZN9glue_drop17O_5B_Ffoo_5B__5D_iFfoo_5B__5D_i_5D_17_9c52ab87ea8f24c9E. I'm not actually sure which drop glue this corresponds to; presumably it's either for the anon obj or the regular obj.

    Attempting to debug from the top down, instead: the only new code that deals with drop glue (or cleanups in general) is here, where I add a cleanup for the pair I'm allocating for the anonymous object. It's entirely possible that I'm doing this wrong because I'm just guessing at what I should be passing to add_clean_temp (should it be the result of alloca, or the value from the result of trans_malloc_boxed, later, or something else?) or what type I should be passing (the node_id_type of the anon obj node, or body_ty, later, or something else?).

  3. lkuper commented on Jul 20, 2011

    @lkuper
    ContributorAuthor

    I just discovered that the tests for ths issue are suddenly passing valgrind for some reason. I'm not sure if it's because of changes to glue generation in the last few days while I've been working on other things, or if it's a side effect of the improvements I made to typechecking for anonymous objects, or something else, but I guess I'll take it. Meanwhile, the larger problem that graydon had suggested was at the heart of the memory corruption I was getting is still present and manifesting itself as issue #702. (But in the tests for that issue, we don't get memory corruption, we get flat-out wrong answers!) So there's clearly still something to fix, but in the meantime, I un-xfail'd the tests for this issue and am declaring it tentatively fixed...

  4. removed their assignment
    on Jun 16, 2014
  5. added a commit that references this issue on Dec 12, 2017
  6. added a commit that references this issue on Jun 4, 2024
    d77daf9
  7. added a commit that references this issue on Jul 30, 2026
  8. added 2 commits that reference this issue on Aug 21, 2026
    2184f7f
    80a6e73
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions