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

analyze: add --rewrite-mode pointwise #1073

Merged
merged 7 commits into from
Apr 15, 2024
Merged

Conversation

spernsteiner
Copy link
Collaborator

This adds a new --rewrite-mode called "pointwise", which rewrites each function in isolation, with all other definitions marked FIXED. The static analysis runs only once, then we run multiple rewriting passes using the same analysis results, making this much more efficient than running the whole c2rust-analyze tool multiple times.

The rewritten code is output to a separate file for each function. For example, given foo.rs containing a function bar, this mode will write to foo.bar.rs the new code produced by rewriting only bar.

Pointwise mode is the basis for our new "pointwise success rate" metric.

Copy link
Contributor

@fw-immunant fw-immunant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, the added loop around run2 seems like it could benefit from a refactor to multiply less work (or at least output less) but I'm not sure exactly which portions could be reused across all definitions as the analysis does have to vary.

@spernsteiner spernsteiner force-pushed the analyze-rewrite-pointwise-base branch from e0a2de5 to ff1fa02 Compare April 15, 2024 16:02
@spernsteiner spernsteiner force-pushed the analyze-rewrite-pointwise branch from d397814 to a015ff3 Compare April 15, 2024 16:02
@spernsteiner spernsteiner changed the base branch from analyze-rewrite-pointwise-base to master April 15, 2024 16:02
@spernsteiner spernsteiner merged commit 6264fae into master Apr 15, 2024
8 checks passed
spernsteiner added a commit that referenced this pull request Apr 29, 2024
Adds scripts for computing "pointwise success rate" metrics. For each
function, we run the static analysis and rewrite that function in
isolation, producing a new `.rs` file where that function has been
rewritten but all other code remains the same. Then we remove the
`unsafe` qualifier from the target function and try to compile the code.
The "pointwise success rate" is the number of functions on which this
procedure succeeds.

The main entry point is
`c2rust-analyze/scripts/run_pointwise_metrics_lighttpd.sh` (as the name
suggests, this is designed to compute the success rate on lighttpd
specifically). It uses a few helpers: `pointwise_try_build.sh` tries to
remove `unsafe` and compile the rewritten code for a specific function,
`pointwise_try_build_unmodified.sh` does the same but on the unmodified,
non-rewritten code (used for computing a baseline success rate), and
`pointwise_metrics.py` tallies up the results and prints overall counts.

Current output on lighttpd:
```
pointwise:     98/1008 functions passed
unmodified:   149/1008 functions passed
improved 20 functions
broke 71 functions
```

This PR depends on #1073, which implements the `pointwise` rewrite mode
in `c2rust-analyze`.
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

Successfully merging this pull request may close these issues.

2 participants