willcrichton / flowistry

Flowistry is an IDE plugin for Rust that helps you focus on relevant code.
https://marketplace.visualstudio.com/items?itemName=wcrichton.flowistry
MIT License
1.91k stars 45 forks source link

Extend flowistry to types with interior mutability #53

Open jyn514 opened 2 years ago

jyn514 commented 2 years ago

You mentioned two things during your thesis defense:

  1. There are two analyses that flowistry supports: whole-program analysis, and (very accurate) heuristics using the lifetime annotations people already provide for the borrow checker.
  2. The lifetime annotations only work for exterior mutability; things like AtomicUsize::set are not considered by flowistry to affect the data flow of the program.

I think it would be possible to extend this to interior mutability by using the intra-procedural analysis that looks into dependencies, but only for types which have interior mutability. The compiler already knows statically which types have interior mutability, because they have to contain an UnsafeCell (anything else is already undefined behavior).

WaffleLapkin commented 2 years ago

The compiler already knows statically which types have interior mutability, because they have to contain an UnsafeCell (anything else is already undefined behavior).

That's true only for owned types though, something like NonNull<T> or *mut T can also mutate the value.

jyn514 commented 2 years ago

@WaffleLapkin those types aren't using interior mutability, they're using unsafe. Writing to a *mut T when you only have a &T is undefined behavior. So flowistry can just treat them like normal types.

WaffleLapkin commented 2 years ago

@jyn514 pointers can point to the heap, they not necessarily come from &T . Or they can actually point to an UnsafeCell somewhere, they were just casted to point to T (that's ok because UnsafeCell is repr(transparent)).

jyn514 commented 2 years ago

@WaffleLapkin ah, sure. But I think it's ok to support interior mutability without first supporting raw pointers, the second will be much more difficult (it probably will require whole-program analysis).