Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

lschuermann
Copy link
Member

Pull Request Overview

This pull request changes the semantics of OptionalCell::map to move a copy of the internal Option's value into the provided closure. Proving a mutable reference to a copy that is then immediately discarded is very confusing.

An alternative design would remove the map APIs and add a get() method, which returns an Option<T>. Then we can use the map* methods on that returned type.

Testing Strategy

This pull request was tested by compiling.

TODO or Help Wanted

This pull request still needs porting of the rest of the kernel to this new interface. This should be mostly mechanical changes.

Documentation Updated

  • Updated the relevant files in /docs, or no updates are required.

Formatting

  • Ran make prepush.

@github-actions github-actions bot added the tock-libraries This affects libraries supported by the Tock project label Jul 7, 2023
@lschuermann lschuermann marked this pull request as draft July 7, 2023 16:17
@kupiakos
Copy link
Contributor

kupiakos commented Jul 7, 2023

On the call, we also discussed renaming the extract field to get. Should that be in a different PR or this one? I brought up my reasoning for calling it get on the original PR that named it extract.

@lschuermann
Copy link
Member Author

@kupiakos It's simple enough to be tacked onto here, but given there's already a history behind that (#2531, #2531), having the discussion in a separate PR seems reasonable. Happy to be the one to take the blame here and creating the PR, given I initially introduced get() and then also renamed it extract(). 😆

Apart from that, I do think that these changes are mostly orthogonal, right?

@lschuermann lschuermann force-pushed the dev/optionalcell-map branch from 5c4fd1c to 26bb869 Compare July 7, 2023 20:30
@github-actions github-actions bot added kernel chips/stm32 Change pertains to the stm32 family of MCUSs labels Jul 7, 2023
@lschuermann
Copy link
Member Author

I implemented this change throughout the Tock codebase. Most of these changes have been done mechanically through sed(1) magic, and then verified in the git diff.

Unsurprisingly, the diff confirms that we've been dereferencing the closure parameter almost everywhere, implicitly copying it. This confirms that this change more closely reflects the intended behavior.

The actual change to OptionalCell is quite small; here's a link to avoid having to scroll through the diff: https://github.com/tock/tock/pull/3535/files#diff-8e0f1d8c375dc7a41a4ffd6511e8029fc478ba6425c80cd455710f54e2b75188L188-R210

@lschuermann lschuermann marked this pull request as ready for review July 7, 2023 20:34
@lschuermann
Copy link
Member Author

For context, this has been brought up by @kupiakos on the call today, and was also the source of confusion for some OpenTitan developers.

Copy link
Contributor

@hudson-ayers hudson-ayers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is definitely better

Copy link
Contributor

@bradjc bradjc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I never understood why we needed the * there and just did what the compiler told me to.

@hudson-ayers hudson-ayers added this pull request to the merge queue Jul 11, 2023
Merged via the queue into tock:master with commit b173b0a Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chips/stm32 Change pertains to the stm32 family of MCUSs kernel tock-libraries This affects libraries supported by the Tock project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants