Warn on variables marked state in actors that don't need to be state
- Dominant language
- C++
- Stars
- 16.7k
- Forks
- 1.6k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 126
Description
Example:
```
ACTOR Future foo() {
state int x = 1;
bar(x);
wait(Never());
return 1;
}
```
Here `x` is trivially destructible and is only used in one callback, so it does not need to be a state variable.
Note that it's important to make sure that `x` is trivially destructible. We don't want to warn for this actor:
```
ACTOR Future foo(Foo* self) {
wait(self->lock.take());
state FlowLock::Releaser releaser(*self->lock);
wait(doSomethingThatRequiresLock(self));
return 1;
}
```
Two reasons why it's important that we identify such variables
1. A reader might expect a variable marked state to be used across `waits` or have a non-trivial destructor, so it's confusing.
2. It bloats the size of the actor
One approach for implementing this would be to collect the set of all state variables that are used in only one callback, and then generate a `static_assert(!std::is_trivially_destructible_v);` for each of them.
Contributor guide
Research direction
No files, tests, or entry points are named. Start by locating the actor compiler's analysis of state variables and callback usage; done means warning only for trivially destructible state variables used in one callback, without warning for non-trivially destructible variables such as the lock releaser.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100