Add external_trait_extension feature to extend external traits with spec functions#1629
Add external_trait_extension feature to extend external traits with spec functions#1629Chris-Hawblitzel merged 8 commits intomainfrom
Conversation
|
Great to see this. i'm a little confused about how this merging works. are the spec functions added to the vir TraitX object? |
They are not. |
|
[retreat 2025] it may be useful to refer to #1465 |
|
I've gone back and forth on this. In the original proposal ( #1618 ), there was no magic renaming. Instead, the programmer explicitly named the third trait (e.g. One thing that bugged me about this is that the This implicit renaming, though, also has drawbacks, particularly if you have to Would it be better to be more verbose? For example, would it be better to have no implicit renaming, and to require that the programmer repeat the entire |
I decided to remove the magic renaming and go with: This was the simplest alternative. |
This implements the proposal in #1618 , with some minor changes. Given an external trait:
You can declare an external trait specification that extends
Twith additionalspecfunctions that are held in a new traitTSpec:The syntax macro generates additional internal declarations for this:
A program can then implement
TandTSpec, where the syntax macro will internally renameimpl TSpectoimpl VERUS_SPEC__TSpecto avoid conflicting with the blanket impl shown above:In VIR,
impl VERUS_SPEC__TSpecis renamed back intoimpl TSpec, so that the impl provides an implementation for the otherwise uninterpretedspecfunctionTSpec::r. If Rust's trait coherence rules are an obstacle, a program can also just provide axioms about the uninterpretedspecfunctionTSpec::r.In VIR's call graph,
TandTSpecare merged together so thatT's associated types,TSpec'sspecfunctions, andT'sexecfunctions are treated as if they had been declared together in a single trait in the first place when checking for cycles in the call graph. This allowsT'sexecfunctions to refer toTSpec'sspecfunctions inrequires/ensuresand allowsTSpec'sspecfunctions to refer toT's associated types.By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.