Skip to content
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

Add a simple way to convert a CommandReturn into a Result #370

Merged
merged 5 commits into from
Feb 2, 2022

Conversation

kupiakos
Copy link
Contributor

@kupiakos kupiakos commented Feb 1, 2022

There are a few changes that this makes:

  • CommandReturn is #[must_use]
  • ErrorCode includes BadRVal
  • CommandReturn has a to_result method

I experimented with a few methods of structuring to_result to have the
smallest overhead per monomorphization. What you see here is the best I
could do. I also tried:

  • Providing a try_to_result and using that (lots of overhead)
  • Preserving the error code of the failure variant on BADRVAL
  • Associated constant FailureData::BADRVAL
  • Associated fn FailureData::from_wrong_variant(r1: ErrorCode) -> Self
  • A helper function fn to_result_helper(self, success_variant: ReturnVariant, error_variant: ReturnVariant) -> (bool, u32, u32, u32) that would do the branches and replacing r1 with BadRVal and other registers with 0 in the case of the wrong variant. I thought this would reduce things further but it seemed to make it worse in my tests. Then again - I only had one instance of each monomorphization.

There are a few changes that this makes:
- CommandReturn is #[must_use]
- ErrorCode includes BadRVal
- CommandReturn has a to_result method

I experimented with a few methods of structuring to_result to have the
smallest overhead per monomorphization. What you see here is the best I
could do. I also tried:

- Providing a `try_into_result` and using that (lots of overhead)
- Preserving the error code of the failure variant on BADRVAL
- Associated constant `FailureData::BADRVAL`
- Associated fn `FailureData::from_wrong_variant(r1: ErrorCode) -> Self`
apis/leds/src/tests.rs Outdated Show resolved Hide resolved
platform/src/error_code.rs Show resolved Hide resolved
platform/src/command_return.rs Show resolved Hide resolved
@jrvanwhy
Copy link
Collaborator

jrvanwhy commented Feb 2, 2022

bors r+

@bors
Copy link
Contributor

bors bot commented Feb 2, 2022

Build succeeded:

@bors bors bot merged commit a0440ba into tock:master Feb 2, 2022
hudson-ayers pushed a commit that referenced this pull request Feb 3, 2022
The only major change from upstream that this preserves is customized
external assembly linkage. This should be mostly removed once libtock
switches to using `global_asm!` - now that that will be stabilized.

This CL is a squash merge of the following commits:

28ebb70 Merge #365
a0440ba Merge #370
abff51c Merge #359
85242dc Merge #364
f1bd0d4 Merge #361
b0f8593 Merge #355
4c7ecb6 Merge #358
6f8b512 Merge #356
73cbbde Merge #357
022984f Merge #353
b2e6471 Merge #352
9eb12c0 Merge #351

This was retrieved with the following command:
```
git log ti50-internal/upstream/master --not \
  $(git merge-base --all ti50-internal/upstream/master m/main) \
  --first-parent
```

BUG=None
TEST=ti50/common make build
SOURCE=UPSTREAM(28ebb70)

Change-Id: I0aa1606f407a0b4bcf0c76b62261414903479092
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants