GaloisInc / mir-json

Plugin for rustc to dump MIR in JSON format
Apache License 2.0
8 stars 2 forks source link

Default implementations are not included with traits #8

Closed sweirich closed 5 years ago

sweirich commented 5 years ago

In this example, the trait T has an implementation of the method g that can be inherited by implementations.

trait T {
    fn m (&self) -> i32;
    fn g (&self) -> i32 { 42 }
}
impl T for i32 {
    fn m (&self) -> i32 { *self }
}

This implementation is included in the output but it is difficult to connect to the trait.

fn ::T::g(_1 : &_0) -> i32  {
   let mut _0 : i32;
   bb0: {
      _0 = use(42);
      return;
   }
}

There may be a way to work around the issue and notice that the default method is present, but it would be simpler if this implementation were connected to the trait more explicitly.

spernsteiner commented 5 years ago

There is already a connection between the trait item and the fn, in that the trait contains an item { "kind": "Method", "name": "::T[0]::g[0]", ... } with the same name as the entry in fns. Would it be useful for the fns entry to also contain a reference to its containing trait/impl? And/or would it be useful for the trait item entry to contain a flag indicating that a default implementation for the method exists in fns?

sweirich commented 5 years ago

Ah, I didn't notice that the default ops were named that way. I think I can use this information to match it up. Thanks.

sweirich commented 5 years ago

That works, thanks.