quark-zju / gcmodule

Garbage collection for Rust inspired by CPython's gcmodule
MIT License
20 stars 5 forks source link

Support derive for enums, add ability to skip field type from is_type_tracked #14

Open CertainLach opened 2 years ago

CertainLach commented 2 years ago

is_type_tracked causes issue in this case:

#[derive(Trace)]
struct A {
    a: Box<A>,
}

Because it expands to

impl Trace for A {
    fn is_type_tracked() -> bool {
        A::is_type_tracked()
    }
}

It causes stack overflow

To address this issue, i added additional filter for derive: ignore_tracking:

struct A {
    #[ignore_tracking]
    a: Box<A>,
}
quark-zju commented 2 years ago

Thanks. Recursive structure is a known issue. Is changing #[trace(skip)] to #[ignore_trace] because limitation of synstructure? I kind like #[trace(skip)] because it looks similar to what serde does.

CertainLach commented 2 years ago

It isn't limitation of synstructure, but easing of implementation, as it is harder to implement parsing of trace(skip) attribute

Forgot about i changed this while making this PR, will implement original style of this attribute

CertainLach commented 2 years ago

Well, it was hard to implement prettier syntax using synstructure, and because everyone implements synstructure subset in own crates nowadays, i created this abdomination

To use advantages of new macro implementation i also added with attribute, which allows to delegate tracing of single field (potentially foreign) to custom function