-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rudimentary support for dynamic trait objects #664
Conversation
This pr already helps a ton, although there are still some struct Cow {}
trait CowContainer<'a> {
fn get_cow(&self) -> &'a Cow;
}
pub struct CowCell<'a> {
inner: &'a dyn CowContainer<'a>,
} When you run flux on this code, it errors with: Which points to this code: flux/crates/flux-fhir-analysis/src/conv/mod.rs Lines 438 to 450 in 23c7453
Comparing this code to other code that passes, it appears that that the problem is that the the trait being parameterized by the dyn trait has a lifetime parameter. Let me know if you need any other info |
I'll probably have some time to look at this tomorrow |
Found one more issue: dyn traits are not implemented as possible return values. trait Animal {
fn noise(&self);
}
#[flux::trusted]
fn get_animal() -> &dyn Animal {
unimplemented!()
} It will error with: flux/crates/flux-middle/src/rty/mod.rs Line 1160 in 23c7453
|
@enjhnsn2 are you sure about the second one, it seems to work fine for me:
|
Whoops, I think I may have messed up the minimization for that one. When I was minimizing I started with tock code that pulled in the tock kernel and I think the error was in the dependency, not the minimized code. Let me try to get a better example |
Alright, I found a minimized example that triggers the error. Unfortunately its a little more complicated: pub trait Animal {
fn noise(&self);
}
fn apply_closure_to_animal<F>(closure: F, animal: &'static dyn Animal)
where
F: FnOnce(&dyn Animal),
{
closure(animal);
} This bug isn't too frequent and is possible to work around, so I don't think you should block this pr on it. |
Thanks, on it!
- Ranjit.
…On Wed, Jul 24, 2024 at 10:33 AM enjhnsn2 ***@***.***> wrote:
Alright, I found a minimized example that triggers the error.
Unfortunately its a little more complicated:
pub trait Animal {
fn noise(&self);}
fn apply_closure_to_animal<F>(closure: F, animal: &'static dyn Animal)where
F: FnOnce(&dyn Animal),{
closure(animal);}
—
Reply to this email directly, view it on GitHub
<https://urldefense.com/v3/__https://github.com/flux-rs/flux/pull/664*issuecomment-2248555787__;Iw!!Mih3wA!HMp_f3DiAmkkZyGYTraImuODudwhdIKDCrIJrm2GsTIaWArQDMIXCnEPBLprCdOC47H0ZBEGXZ2Wk2KUKDXHXJnO$>,
or unsubscribe
<https://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/AAMS4OCINCS2FSTVUEW3ZTTZN7QPNAVCNFSM6AAAAABLK6BQ4GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBYGU2TKNZYG4__;!!Mih3wA!HMp_f3DiAmkkZyGYTraImuODudwhdIKDCrIJrm2GsTIaWArQDMIXCnEPBLprCdOC47H0ZBEGXZ2Wk2KUKF0HazE_$>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
This feels it'll fail for various reasons not just dynamic objects. I'd prefer if we don't fix it in this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ranjitjhala first round of comments. I focused only on the way dynamic objects are being represented.
Ok I think I've fixed the |
@nilehmann -- it turns out that for @enjhnsn2 example with |
@@ -1099,6 +1133,7 @@ impl BaseTy { | |||
| BaseTy::Array(_, _) | |||
| BaseTy::Closure(_, _) | |||
| BaseTy::Coroutine(..) | |||
| BaseTy::Dynamic(_, _) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's something I don't quite understand yet. We are putting Dynamic
in BaseTy
which means they can be indexed (by unit
as returned by this function), however, the concrete type under the dynamic type could be indexed by another sort. I don't know if these should be somehow related or if they are completely orthogonal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think its fine, because once its Dynamic
you have zero information about the underlying concrete type, everything is abstracted to whatever is know about the dyn
...
Co-authored-by: Nico Lehmann <[email protected]>
ierge branch 'dyn' of github.com:flux-rs/flux into dyn
Ok I think I addressed all the issues above -- except the
But I'm pretty certain that's (for now at least) the sensible choice - as in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I think this is good to go. we should be able to iterate from here once we have concrete examples.
re indices: more than worried about being unsound or anything I was wondering whether it will ever make sense to have indices on dynamic objects. We will see, but for now unit
sounds like a safe option.
Fixes #655
Totally ignores all the bound-vars stuff for
TraitObject
because I haven't understood it at all, but wanted to start iterating.