Repository navigation
Support ThreadLocalRef (by treating it like a static variable) - #1452
Conversation
| #[kani::proof] | ||
| fn main() { | ||
| COND.with(|&b|{ | ||
| COND.with(|&b| { |
There was a problem hiding this comment.
How did the formatter miss this?
There was a problem hiding this comment.
I think this test may have been committed before we had the format checker?
There was a problem hiding this comment.
The format checker runs in all files, not just the ones that have changed. So that's a mystery.
There was a problem hiding this comment.
I don't think cargo fmt formats everything in all subfolders. Opened an issue: #1455
| } | ||
| } | ||
|
|
||
| pub fn codegen_static_pointer(&mut self, def_id: DefId, is_thread_local: bool) -> Expr { |
| static COMPLEX_DATA: RefCell<&'static str> = RefCell::new("before"); | ||
| } | ||
|
|
||
| pub fn main() {} |
| Location::none(), | ||
| "https://github.com/model-checking/kani/issues/541", | ||
| ) | ||
| Rvalue::ThreadLocalRef(def_id) => { |
There was a problem hiding this comment.
Maybe we should add a user warning here.
There was a problem hiding this comment.
What kind of warning do you have in mind? If you mean the single-threaded assumption, I don't think this is the place to warn about it. If anything, we should warn about that if the user tries to spawn threads. But at the moment it is not possible to spawn threads anyway. If we warn for thread locals, the user will get spurious warnings even if they only use one thread (tokio uses thread locals even in single-threaded mode for instance).
There was a problem hiding this comment.
I do understand the concern of giving spurious warnings and that using thread-local in single threaded analysis is a legit use case.
However, my main concern is that we are making assumptions here that might not hold later. This assumption could be easily missed when we enable multi-thread support.
Note that this is already the behavior for all intrinsics that assume single threads. Here is the message we print:
kani/kani-compiler/src/codegen_cprover_gotoc/codegen/intrinsic.rs
Lines 14 to 22 in f719b56
There was a problem hiding this comment.
Yeah, I've seen that message before (actually a whole wall of text made up of just this message) and found it very distracting. If it's not actually a soundness issue in Kani, I don't think we should print warnings. That's just going to lower the user's trust in the tool. But that's a separate issue, for this PR, I'll go with the emit_concurrency_warning as you suggested.
There was a problem hiding this comment.
Added a concurrency warning in this PR.
danielsn
left a comment
There was a problem hiding this comment.
Should probably address Celina's comments, but beyond that LGTM
Description of changes:
Kani did not support thread locals, in particular the MIR construct
ThreadLocalRef. As discovered #1400, this is the most used feature that is currently unsupported in Kani. In particular it is needed to compile tokio.Since Kani is single-threaded, thread locals are treated like static variables and translated in the same way.
Resolved issues:
Resolves #1450
Resolves #541
Resolves #157
Call-outs:
Testing:
How is this change tested? A previously failing regression test that now passes. It uses the same code as static variables, so the same code path is also tested in other tests using static variables.
Is this a refactor change? No
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.