fix: Skip builtin methods in trait impl struct literals#953
fix: Skip builtin methods in trait impl struct literals#953mennanov wants to merge 1 commit intoAeneasVerif:mainfrom
Conversation
When a trait impl method is a builtin (e.g. PartialOrd::lt, Ord::max, PartialEq::ne), Aeneas does not emit a `def` for it — the Lean library provides the implementation. However, `extract_trait_impl` was still emitting a field reference to the non-existent def in the struct literal, creating a dangling self-reference that Lean cannot resolve. Now, when iterating over `impl.methods`, we check whether the method's translated function has `builtin_info` set. If so, the field is omitted from the struct literal, relying on the default field values added in AeneasVerif#940. Also adds a `wrap_lt` test exercising derived PartialOrd `<` on a newtype.
|
Thanks for looking into this! The fact that the output contains an axiom is a bit suspicious given that there is a model of the default implementation in the Lean library. What is generated without your fix? Looking at this from a distance, my intuition is that we may want to use |
|
Thanks for the feedback! With the current Charon, the output is identical with and without my fix. The output in both cases is: axiom Wrap.Insts.CoreCmpPartialOrdWrap.lt : Wrap → Wrap → Result Bool
@[reducible]
def Wrap.Insts.CoreCmpPartialOrdWrap : core.cmp.PartialOrd Wrap Wrap := {
partialEqInst := Wrap.Insts.CoreCmpPartialEqWrap
partial_cmp := Wrap.Insts.CoreCmpPartialOrdWrap.partial_cmp
lt := Wrap.Insts.CoreCmpPartialOrdWrap.lt
}This compiles, but it contains an axiom. Apparently Charon marks the impl method as opaque in the LLBC ( Btw, on main (without my On Do you envision smth like this? Plan:
In theory this should eliminate both the axiom and self-reference issues. I'll leave it up to you to decide whether it's worth merging this quick fix. |
When a trait impl method is a builtin (e.g. PartialOrd::lt, Ord::max, PartialEq::ne), Aeneas does not emit a
deffor it — the Lean library provides the implementation. However,extract_trait_implwas still emitting a field reference to the non-existent def in the struct literal, creating a dangling self-reference that Lean cannot resolve.Now, when iterating over
impl.methods, we check whether the method's translated function hasbuiltin_infoset. If so, the field is omitted from the struct literal, relying on the default field values added in #940.Also adds a
wrap_lttest exercising derived PartialOrd<on a newtype.