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 #[kani::unstable] attribute #2373

Merged
merged 3 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions kani-compiler/src/kani_middle/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ enum KaniAttributeKind {
ShouldPanic,
Solver,
Stub,
/// Attribute used to mark unstable APIs.
Unstable,
Unwind,
}

Expand Down Expand Up @@ -113,6 +115,10 @@ pub fn extract_harness_attributes(tcx: TyCtxt, def_id: DefId) -> Option<HarnessA
parse_unwind(tcx, expect_single(tcx, kind, &attributes))
}
KaniAttributeKind::Proof => harness.proof = true,
KaniAttributeKind::Unstable => {
// Internal attribute which shouldn't exist here.
unreachable!()
}
};
harness
},
Expand Down
3 changes: 3 additions & 0 deletions library/kani/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

// Required so we can use kani_macros attributes.
#![feature(register_tool)]
#![register_tool(kanitool)]
// Used for rustc_diagnostic_item.
#![feature(rustc_attrs)]
// This is required for the optimized version of `any_array()`
Expand Down
19 changes: 15 additions & 4 deletions library/kani_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ pub fn stub(attr: TokenStream, item: TokenStream) -> TokenStream {
pub fn solver(attr: TokenStream, item: TokenStream) -> TokenStream {
attr_impl::solver(attr, item)
}

/// Mark an API as unstable. This should only be used inside the Kani sysroot.
/// See https://model-checking.github.io/kani/rfc/rfcs/0006-unstable-api.html for more details.
#[doc(hidden)]
#[proc_macro_attribute]
pub fn unstable(attr: TokenStream, item: TokenStream) -> TokenStream {
attr_impl::unstable(attr, item)
}

/// Allow users to auto generate Arbitrary implementations by using `#[derive(Arbitrary)]` macro.
#[proc_macro_error]
#[proc_macro_derive(Arbitrary)]
Expand Down Expand Up @@ -176,9 +185,10 @@ mod sysroot {
}

kani_attribute!(should_panic, no_args);
kani_attribute!(unwind);
kani_attribute!(stub);
kani_attribute!(solver);
kani_attribute!(stub);
kani_attribute!(unstable);
kani_attribute!(unwind);
}

/// This module provides dummy implementations of Kani attributes which cannot be interpreted by
Expand Down Expand Up @@ -207,7 +217,8 @@ mod regular {
}

no_op!(should_panic);
no_op!(unwind);
no_op!(stub);
no_op!(solver);
no_op!(stub);
no_op!(unstable);
no_op!(unwind);
}