Skip to content

Commit

Permalink
Add #[kani::unstable] attribute (#2373)
Browse files Browse the repository at this point in the history
Add the #[unstable] attribute that will allow us to mark unstable APIs. This PR only adds the attributes and we still need to add the option to enable them and to error out if the user is trying to use an unstable item without explicitly opting-in.
  • Loading branch information
celinval authored Apr 14, 2023
1 parent 55d1557 commit c4ed7ec
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
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);
}

0 comments on commit c4ed7ec

Please sign in to comment.