forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 58
Move std-analysis.sh script from Kani repository #261
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
Merged
tautschnig
merged 2 commits into
model-checking:main
from
tautschnig:move-metrics-script
Mar 4, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
#!/usr/bin/env bash | ||
# Copyright Kani Contributors | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
# Collect some metrics related to the crates that compose the standard library. | ||
# | ||
# Files generates so far: | ||
# | ||
# - ${crate}_scan_overall.csv: Summary of function metrics, such as safe vs unsafe. | ||
# - ${crate}_scan_input_tys.csv: Detailed information about the inputs' type of each | ||
# function found in this crate. | ||
# | ||
# How we collect metrics: | ||
# | ||
# - Compile the standard library using the `scan` tool to collect some metrics. | ||
# - After compilation, move all CSV files that were generated by the scanner, | ||
# to the results folder. | ||
set -eu | ||
|
||
# Test for platform | ||
PLATFORM=$(uname -sp) | ||
if [[ $PLATFORM == "Linux x86_64" ]] | ||
then | ||
TARGET="x86_64-unknown-linux-gnu" | ||
# 'env' necessary to avoid bash built-in 'time' | ||
WRAPPER="env time -v" | ||
elif [[ $PLATFORM == "Darwin i386" ]] | ||
then | ||
TARGET="x86_64-apple-darwin" | ||
# mac 'time' doesn't have -v | ||
WRAPPER="time" | ||
elif [[ $PLATFORM == "Darwin arm" ]] | ||
then | ||
TARGET="aarch64-apple-darwin" | ||
# mac 'time' doesn't have -v | ||
WRAPPER="time" | ||
else | ||
echo | ||
echo "Std-Lib codegen regression only works on Linux or OSX x86 platforms, skipping..." | ||
echo | ||
exit 0 | ||
fi | ||
|
||
# Get Kani root | ||
if [[ $# -ne 1 ]] | ||
then | ||
echo "Required command-line argument <KANI-DIR> missing" | ||
exit 1 | ||
fi | ||
KANI_DIR=$1 | ||
|
||
echo "-------------------------------------------------------" | ||
echo "-- Starting analysis of the Rust standard library... --" | ||
echo "-------------------------------------------------------" | ||
|
||
echo "-- Build scanner" | ||
cd $KANI_DIR | ||
cargo build -p scanner | ||
|
||
echo "-- Build std" | ||
cd /tmp | ||
if [ -d std_lib_analysis ] | ||
then | ||
rm -rf std_lib_analysis | ||
fi | ||
cargo new std_lib_analysis --lib | ||
cd std_lib_analysis | ||
sed -i '1i cargo-features = ["edition2024"]' Cargo.toml | ||
|
||
echo ' | ||
pub fn dummy() { | ||
} | ||
' > src/lib.rs | ||
|
||
# Use same nightly toolchain used to build Kani | ||
cp ${KANI_DIR}/rust-toolchain.toml . | ||
|
||
export RUST_BACKTRACE=1 | ||
export RUSTC_LOG=error | ||
|
||
RUST_FLAGS=( | ||
"-Cpanic=abort" | ||
"-Zalways-encode-mir" | ||
) | ||
export RUSTFLAGS="${RUST_FLAGS[@]}" | ||
export RUSTC="$KANI_DIR/target/debug/scan" | ||
# Compile rust with our extension | ||
$WRAPPER cargo build --verbose -Z build-std --lib --target $TARGET | ||
|
||
echo "-- Process results" | ||
|
||
# Move files to results folder | ||
results=/tmp/std_lib_analysis/results | ||
mkdir $results | ||
find /tmp/std_lib_analysis/target -name "*.csv" -exec mv {} $results \; | ||
|
||
# Create a summary table | ||
summary=$results/summary.csv | ||
|
||
# write header | ||
echo -n "crate," > $summary | ||
tr -d "[:digit:],;" < $results/alloc_scan_overall.csv \ | ||
| tr -s '\n' ',' >> $summary | ||
echo "" >> $summary | ||
|
||
# write body | ||
for f in $results/*overall.csv; do | ||
# Join all crate summaries into one table | ||
fname=$(basename $f) | ||
crate=${fname%_scan_overall.csv} | ||
echo -n "$crate," >> $summary | ||
tr -d '[:alpha:]_,;' < $f | tr -s '\n' ',' \ | ||
>> $summary | ||
echo "" >> $summary | ||
done | ||
|
||
echo "-------------------------------------------------------" | ||
echo "Finished analysis successfully..." | ||
echo "- See results at ${results}" | ||
echo "-------------------------------------------------------" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.