Skip to content
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

Homogenising hwt + swt and fixing swt #980

Open
ltratt opened this issue Feb 20, 2024 · 1 comment
Open

Homogenising hwt + swt and fixing swt #980

ltratt opened this issue Feb 20, 2024 · 1 comment
Assignees

Comments

@ltratt
Copy link
Contributor

ltratt commented Feb 20, 2024

Consider (and I'll use Rust syntax because I'm lazy) code like this:

trait T { fn m() ; }
// A mappable module
struct S1;
impl T for S1 { fn m() { ... } }
// An unmappable module
struct S2;
impl T for S2 { fn m() { ... } }

fn main() {
  let x: Box<dyn T> = if ... { Box::new(S1) } else { Box::new(S2) };
  x.m();
  ...
}

We don't know statically if the indirect call x.m() will call S1::m or S2::m.

hwt solves this because PT merrily traces through both mappable and unmappable functions, so we know at run-time which m was called.

swt, though, doesn't know which m will be called. We could say "if the call to x.m() is followed by a mappable block that isn't ... then we called S1::m otherwise we called S2::m. However, there is a wonderful pathological case where we call S2::m which then calls S1::m: we can't distinguish that case from calling S1::m directly.

The problem is that swt needs to "look into" unmappable functions, but it can't do so. Fortunately we have a probable solution (in conjunction with @ptersilie and @Pavel-Durov). First, swt adds a func_record function at every indirect function which records the function pointer that's about to be called. So our main should be transformed by ykllvm into something like:

fn main() {
  let x: Box<dyn T> = if ... { Box::new(S1) } else { Box::new(S2) };
  func_record(x.m);
  x.m();
  ...
}

func_record allows us to check with 100% precision "do we have mapped blocks for the function pointed to by x?". We then change TraceAction from talking about "Mapped" and "Unmapped" blocks to "Mapped blocks" and "Indirect calls". This allows us to distinguish all the cases we could come up with so far.

This will also require a change in hwt so that it deals with this change to TraceAction.

@ltratt
Copy link
Contributor Author

ltratt commented Apr 5, 2024

#1086 has identified some more tests that fail in some situations with swt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants