-
Notifications
You must be signed in to change notification settings - Fork 2
Feat: implement #[precond]
#[hazard]
and #[option]
proc-macros
#7
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
Conversation
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
close Artisan-Lab#6 ********* "demo" [Rlib] has reached 8 instances ********* (stable mir) "test" ("src/lib.rs:9:1: 9:26") => "#[safety::precond::UnReachable(memo =\n\"It's undefined behavior to reach code ma rked with this intrinsic function.\")]\n" (stable mir) "MyStruct::get" ("src/lib.rs:37:5: 37:42") => "#[safety::precond::Init(self.ptr, u8, self.len, memo =\n\"The ptr must be initialized first!\")]\n" (stable mir) "MyStruct::get" ("src/lib.rs:37:5: 37:42") => "#[safety::precond::InBound(self.ptr, u8, self.len, memo =\n\"The ptr m ust be within the length.\")]\n" (stable mir) "MyStruct::get" ("src/lib.rs:37:5: 37:42") => "#[safety::precond::ValidNum(self.len*sizeof(u8), [0,isize::MAX], memo =\n\"Slice length can't exceed isize::MAX due to allocation limit.\")]\n" (stable mir) "MyStruct::get" ("src/lib.rs:37:5: 37:42") => "#[safety::hazard::Alias(self.ptr, memo = \"Make sure don't alias the p tr.\")]\n" ********* "demo" [Executable] has reached 18 instances ********* (internal api) "demo::MyStruct::get" ("/home/gh-zjp-CN/tag-std/demo/rustc_driver/tests/basic/src/lib.rs:37:5: 37:42") => "#[safety ::precond::Init(self.ptr, u8, self.len, memo =\n\"The ptr must be initialized first!\")]\n" (internal api) "demo::MyStruct::get" ("/home/gh-zjp-CN/tag-std/demo/rustc_driver/tests/basic/src/lib.rs:37:5: 37:42") => "#[safety ::precond::InBound(self.ptr, u8, self.len, memo =\n\"The ptr must be within the length.\")]\n" (internal api) "demo::MyStruct::get" ("/home/gh-zjp-CN/tag-std/demo/rustc_driver/tests/basic/src/lib.rs:37:5: 37:42") => "#[safety ::precond::ValidNum(self.len*sizeof(u8), [0,isize::MAX], memo =\n\"Slice length can't exceed isize::MAX due to allocation limit.\" )]\n" (internal api) "demo::MyStruct::get" ("/home/gh-zjp-CN/tag-std/demo/rustc_driver/tests/basic/src/lib.rs:37:5: 37:42") => "#[safety ::hazard::Alias(self.ptr, memo = \"Make sure don't alias the ptr.\")]\n"
\#[safety( Init(self.ptr, u8, self.len), memo = "reason" )]
/// This is a single line. fn single_line() {} /// Line 1. /// Line 2. fn multi_lines() {} /// Line 1. /// Line 2. fn multi_lines2() {} /// Line 1. /// Line 2. /// Line 3. fn multi_lines3() {}
seems cargo fill this through stdin? also fixes CARGO_SAFE_TOOL var.
********* "demo" [Rlib] has reached 8 instances ********* "test" ("src/lib.rs:12:1: 12:26") => "#[Safety::inner(UnReachable, kind = \"precond\", memo =\n\"It's undefined behavior to reach code marked with this intrinsic function.\")]\n" "MyStruct::get" ("src/lib.rs:40:5: 40:42") => "#[Safety::inner(Init(self.ptr, u8, self.len), kind = \"precond\", memo =\n\"The ptr must be initialized first!\")]\n" "MyStruct::get" ("src/lib.rs:40:5: 40:42") => "#[Safety::inner(InBound(self.ptr, u8, self.len), kind = \"precond\", memo =\n\"The ptr must be within the length.\")]\n" "MyStruct::get" ("src/lib.rs:40:5: 40:42") => "#[Safety::inner(ValidNum(self.len * sizeof(u8), [0, isize :: MAX]), kind =\n\"precond\", memo =\n\"Slice length can't exceed isize::MAX due to allocation limit.\")]\n" "MyStruct::get" ("src/lib.rs:40:5: 40:42") => "#[Safety::inner(Alias(self.ptr), kind = \"hazard\", memo =\n\"Make sure don't alias the ptr.\")]\n" ********* "demo" [Executable] has reached 18 instances ********* "demo::MyStruct::get" ("/home/gh-zjp-CN/tag-std/demo/rustc_driver/tests/basic/src/lib.rs:40:5: 40:42") => "#[Safety::inner(Init(self.ptr, u8, self.len), kind = \"precond\", memo =\n\"The ptr must be initialized first!\")]\n" "demo::MyStruct::get" ("/home/gh-zjp-CN/tag-std/demo/rustc_driver/tests/basic/src/lib.rs:40:5: 40:42") => "#[Safety::inner(InBound(self.ptr, u8, self.len), kind = \"precond\", memo =\n\"The ptr must be within the length.\")]\n" "demo::MyStruct::get" ("/home/gh-zjp-CN/tag-std/demo/rustc_driver/tests/basic/src/lib.rs:40:5: 40:42") => "#[Safety::inner(ValidNum(self.len * sizeof(u8), [0, isize :: MAX]), kind =\n\"precond\", memo =\n\"Slice length can't exceed isize::MAX due to allocation limit.\")]\n" "demo::MyStruct::get" ("/home/gh-zjp-CN/tag-std/demo/rustc_driver/tests/basic/src/lib.rs:40:5: 40:42") => "#[Safety::inner(Alias(self.ptr), kind = \"hazard\", memo =\n\"Make sure don't alias the ptr.\")]\n"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR mainly implements safety attribute proc-macros listed in the title
::memo
doesn't compile due to AST parsing from rustc, even for registered tool #6For example,
#[precond]
will expand to#[doc]
which is used to generate rustdoc content#[Safety::inner(Property, kind = "precond", ...)]
a registered tool attribute , used in the rustc driver withkind
andProperty
analyzedis expanded to
More examples
expanded to
Implementation details:
safety-tool-parser
crate is a attribute macro syntax parser, and shared betweensafety-tool-macro
and rustc driversafety-tool-macro
crate is a proc-macro lib, used to add#[doc]
and#[Safety::inner]
attributes for the annotated functionsafety-tool-lib
crate is mainly for public use, especially for another tool like klintNOTE: the registered tool attribute is changed from
safety
toSafety
.