Unsizing for trait objects#150
Conversation
b738977 to
cd62265
Compare
This might still be an issue with your encoding (or something related to mutrefs in the testcase?) -- Prusti is simply saying that Viper returned an error, but we did not expect that error to happen (i.e., it is not an error that can be back-translated to the violation of a particular assertion or contract). Usually, I see these errors say there is a permission error in a precondition. What does Viper actually report? Does the generated |
|
So there are multiple problems here:
This can be fixed by patching PCG to only create edges when
but
|
|
The second of these points is actually also the case when unsizing arrays to slices, and mutably borrowing them. Unlike tait objects, these only have one lifetime parameter. Example: fn consume(v: &mut [i32]) {
}
fn main() {
let mut arr = [1, 2, 3];
consume(&mut arr);
} |
cd62265 to
70b82b6
Compare
|
|
In principle, this PR is ready to review. It does depend on #162, so we should merge that one first. |
7baea86 to
be5b76b
Compare
|
Since #162 is now merged, this PR is ready for review |
2703f69 to
4dc255f
Compare
5b3530d to
1c7afcc
Compare
a49d926 to
ba75f19
Compare
PR #149 implements trait objects as opaque types in Viper. However, to pass references to trait objects to functions, these are unsized before being borrowed, which is currently not supported:
The handler in
MirBuiltinEnc::handle_unsizecurrently only supports unsizing from arrays/slices to slices and panics on everything else. This PR enables unsizing of structs to trait objects and trait objects to themselves: Given a structMyStructthat implements TraitMyTrait, this PR allows for unsizing&MyStruct->&dyn MyTrait(as well as the&mutversions). It also allows for unsizing&dyn MyTrait->&dyn MyTrait(as well as themutversions) which happens in functions which take&dyn MyTraitand pass it into other functions.Since trait objects are opaque, no postconditions about their content are encoded.
Supporting this unsizing has the effect of enabling significant standard library functionality, like
#[derive(Debug)], making the following snippet not crash anymore:TODO
I would like to add a test case with
&mut dyn MyTrait. However, I get an error "verification error could not be backtranslated". However, this error also occurs outside of test cases that have to do with this PR, so it's maybe unrelated?