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

Add intrinsics and Arbitrary support for no_core #3230

Merged
merged 29 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
48defa8
Shift intrinsics and arbitrary to kani_core
jaisnan May 31, 2024
d4e9a7b
Add contracts to scope of user crate
jaisnan Jun 3, 2024
e231f9d
Fix duplicated definitions error
celinval Jun 4, 2024
32ef011
Add one macro to rule them all...
celinval Jun 4, 2024
4d9b7fe
Merge branch 'add-3152' of https://github.com/jaisnan/kani into add-f…
jaisnan Jun 5, 2024
8103dd5
Add flag to disable test addition to std-regression script
jaisnan Jun 5, 2024
33eb53a
comment out flag for custom rust source
jaisnan Jun 5, 2024
d6e8dd0
Add flag to regression
jaisnan Jun 5, 2024
e093376
undo changes to arbitrary
jaisnan Jun 5, 2024
78328ed
Commit till the point of compiling std-lib
jaisnan Jun 6, 2024
b08dc9c
Merge branch 'add-fix-3152' of https://github.com/jaisnan/kani into a…
jaisnan Jun 6, 2024
63f3ea6
Merge branch 'main' of https://github.com/model-checking/kani into ad…
jaisnan Jun 6, 2024
4614e65
get core to compile everything but proof_for_contract
jaisnan Jun 7, 2024
18a556e
Add -Zfunction-contracts and cfg(no_core)
jaisnan Jun 7, 2024
b465652
Merge branch 'main' of https://github.com/model-checking/kani into tm…
jaisnan Jun 7, 2024
3566f9e
cargo fmt
jaisnan Jun 10, 2024
13c27cd
Merge branch 'tmp-branch-3152' into add-fix-3152
jaisnan Jun 10, 2024
e6a8189
Merge branch 'main' of https://github.com/model-checking/kani into ad…
jaisnan Jun 10, 2024
57dda05
Merge branch 'main' of https://github.com/model-checking/kani into ad…
jaisnan Jun 10, 2024
985adca
Add changes to the point where proof_for_Contract works as well.
jaisnan Jun 10, 2024
b211bac
Merge branch 'main' into add-fix-3152
jaisnan Jun 10, 2024
ce6cd61
Revert changes, and cleanup
jaisnan Jun 10, 2024
fb3b9c4
Merge branch 'main' of https://github.com/model-checking/kani into ad…
jaisnan Jun 10, 2024
752c7e9
Merge branch 'main' into add-fix-3152
jaisnan Jun 10, 2024
e0b1693
Remove -Z function contract; Add some tests related to function contr…
jaisnan Jun 10, 2024
219bee7
Merge branch 'add-fix-3152' of https://github.com/jaisnan/kani into a…
jaisnan Jun 10, 2024
a1f3a43
replace kani with kani_core
jaisnan Jun 10, 2024
e96d4a7
Add basic comments
jaisnan Jun 10, 2024
cbcbb72
Fix regression test for verify_std
jaisnan Jun 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
get core to compile everything but proof_for_contract
  • Loading branch information
jaisnan committed Jun 7, 2024
commit 4614e65623515ddcebae3e02984cd5cb452e20c6
4 changes: 4 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,10 @@ dependencies = [
"strum_macros",
]

[[package]]
name = "kani_verify_std"
version = "0.1.0"

[[package]]
name = "lazy_static"
version = "1.4.0"
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ members = [
"kani-driver",
"kani-compiler",
"kani_metadata",
"library/kani_core",
"library/kani_core", "target/kani_verify_std",
]

# This indicates what package to e.g. build with 'cargo build' without --workspace
Expand Down
11 changes: 9 additions & 2 deletions kani-compiler/src/codegen_cprover_gotoc/codegen/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,21 @@ impl<'tcx> GotocCtx<'tcx> {
let recursion_wrapper_id =
function_under_contract_attrs.checked_with_id().unwrap().unwrap();
let expected_name = format!("{}::REENTRY", tcx.item_name(recursion_wrapper_id));
let mut recursion_tracker = items.iter().filter_map(|i| match i {
let mut recursion_tracker = items.iter().filter_map(|i| { tracing::error!(?i, "++++++++++++++++++++++"); match i {
MonoItem::Static(recursion_tracker)
if (*recursion_tracker).name().contains(expected_name.as_str()) =>
{
Some(*recursion_tracker)
}
_ => None,
});
}});

let names = items.iter().filter_map(|item| { let MonoItem::Fn(i) = item else { return None };
Some(i.name())
}).collect::<Vec<_>>();

tracing::error!(?names, ?recursion_wrapper_id, "******************");

let recursion_tracker_def = recursion_tracker
.next()
.expect("There should be at least one recursion tracker (REENTRY) in scope");
Expand Down
1 change: 1 addition & 0 deletions kani-compiler/src/kani_middle/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ impl BodyTransformation {
Some(TransformationResult::Modified(body)) => body.clone(),
Some(TransformationResult::NotModified) => instance.body().unwrap(),
None => {
println!("****** INSTANCE NAME {:?}***********", instance.name());
let mut body = instance.body().unwrap();
let mut modified = false;
for pass in self.opt_passes.iter().chain(self.inst_passes.iter()) {
Expand Down
11 changes: 8 additions & 3 deletions kani-driver/src/call_cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ impl KaniSession {
let mut rustc_args = self.kani_rustc_flags(LibConfig::new_no_core(lib_path));
rustc_args.push(to_rustc_arg(self.kani_compiler_flags()).into());
rustc_args.push(self.reachability_arg().into());
rustc_args.push(to_rustc_arg(vec!["--ignore-global-asm".to_string()]).into());
rustc_args.push(to_rustc_arg(vec!["-Zfunction-contracts".to_string()]).into());
celinval marked this conversation as resolved.
Show resolved Hide resolved

let mut cargo_args: Vec<OsString> = vec!["build".into()];
let mut cargo_args: Vec<OsString> = vec!["rustc".into()];
cargo_args.append(&mut cargo_config_args());

// Configuration needed to parse cargo compilation status.
Expand All @@ -71,6 +73,9 @@ impl KaniSession {
cargo_args.push("-v".into());
}

// cargo_args.push("--".into());
// cargo_args.push("-Zunpretty=expanded".into());

// Since we are verifying the standard library, we set the reachability to all crates.
let mut cmd = setup_cargo_command()?;
cmd.args(&cargo_args)
Expand Down Expand Up @@ -103,8 +108,8 @@ impl KaniSession {
fs::remove_dir_all(&target_dir)?;
}

let lib_path = lib_folder().unwrap();
let mut rustc_args = self.kani_rustc_flags(LibConfig::new(lib_path));
let lib_path = lib_no_core_folder().unwrap();
let mut rustc_args = self.kani_rustc_flags(LibConfig::new_no_core(lib_path));
rustc_args.push(to_rustc_arg(self.kani_compiler_flags()).into());

let mut cargo_args: Vec<OsString> = vec!["rustc".into()];
Expand Down
4 changes: 4 additions & 0 deletions kani-driver/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ pub(crate) fn std_project(std_path: &Path, session: &KaniSession) -> Result<Proj
}
session.cargo_init_lib(&dummy_crate)?;

let mut input = String::new();
println!("Press ENTER: ");
let _n = std::io::stdin().read_line(&mut input).unwrap();

// Build cargo project for dummy crate.
let std_path = std_path.canonicalize()?;
let outputs = session.cargo_build_std(std_path.parent().unwrap(), &dummy_crate)?;
Expand Down
2 changes: 1 addition & 1 deletion library/kani/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
publish = false

[dependencies]
kani_macros = { path = "../kani_macros" }
kani_macros = { path = "../kani_macros", default-features = false }
celinval marked this conversation as resolved.
Show resolved Hide resolved

[features]
concrete_playback = []
2 changes: 1 addition & 1 deletion library/kani_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ publish = false
description = "Define core constructs to use with Kani"

[dependencies]
kani_macros = { path = "../kani_macros" }
kani_macros = { path = "../kani_macros", default-features = false }

[features]
no_core=["kani_macros/no_core"]
9 changes: 9 additions & 0 deletions library/kani_core/src/internal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

#[macro_export]
macro_rules! kani_internals {



}
27 changes: 26 additions & 1 deletion library/kani_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,5 +255,30 @@ macro_rules! kani_intrinsics {
#[allow(clippy::empty_loop)]
loop {}
}
};

pub mod internal {
/// A way to break the ownerhip rules. Only used by contracts where we can
/// guarantee it is done safely.
#[inline(never)]
#[doc(hidden)]
#[rustc_diagnostic_item = "KaniUntrackedDeref"]
pub fn untracked_deref<T>(_: &T) -> T {
todo!()
}

/// CBMC contracts currently has a limitation where `free` has to be in scope.
/// However, if there is no dynamic allocation in the harness, slicing removes `free` from the
/// scope.
///
/// Thus, this function will basically translate into:
/// ```c
/// // This is a no-op.
/// free(NULL);
/// ```
#[inline(never)]
#[doc(hidden)]
#[rustc_diagnostic_item = "KaniInitContracts"]
pub fn init_contracts() {}
}
}
}
4 changes: 2 additions & 2 deletions library/kani_macros/src/sysroot/contracts/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ pub fn make_unsafe_argument_copies(
let arg_values = renaming_map.keys();
(
quote!(#(let #arg_names = kani::internal::untracked_deref(&#arg_values);)*),
#[cfg(feature = "no_core")]
quote!(#(crate::mem::block(#also_arg_names);)*),
#[cfg(not(feature = "no_core"))]
quote!(#(std::mem::forget(#also_arg_names);)*),
#[cfg(feature = "no_core")]
quote!(#(core::mem::forget(#also_arg_names);)*),
)
}

Expand Down
1 change: 1 addition & 0 deletions scripts/std-lib-regression.sh
jaisnan marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ RUST_FLAGS=(
"-L"
"${KANI_DIR}/target/kani/no_core/lib"
"--cfg=kani"
"--cfg=no_core"
)
export RUSTFLAGS="${RUST_FLAGS[@]}"
export RUSTC_LOGS="info"
Expand Down