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 test suites to check Reanimated Babel plugin idempotency #4441

Merged
merged 2 commits into from
May 9, 2023

Conversation

tjzel
Copy link
Contributor

@tjzel tjzel commented May 9, 2023

Summary

For correct functioning of Reanimated idempotency of our Babel plugin is important. This PR adds a few unit tests for plugin's triggers in more-or-less complicated situations.

This obviously is not a confirmation of idempotency, that's arguably unachievable with simple unit tests. There is however some additional step that can be taken here.

In plugin/ we have a development README with some simple chart of plugin's logic included. This chart could be expanded to contain more details about the results of code transformations thus lead to proof of idempotency. For example:

  • Plugin is idempotent within explicit worklets scope (FunctionDeclarations, FunctionExpressions, ArrowFunctionExpressions).

How do we know this? It's simple: every explicit worklet will be transformed to a CallExpression. CallExpressions are not transformed within this scope, hence another run of plugin will not transform anything.

By saying scope I mean some limited transformation cases: plugin will not attempt explicit worklet transformation of already transformed explicit worklet. It will however try to transform a CallExpression if this CallExpression is for eg. named useAnimatedStyle and explicit worklets are transformed to CallExpressions. This transformation will probably still be idempotent though.

Therefore, the next step after checking idempotency within those scopes would be to analyze the situations when the result of a certain transformation crosses a boundary of two scopes.

Creation of a chart that would contain all of necessary information for the idempotency proof seems to be quite a lot of work but is definitely doable and would certainly be much more informative than some 'random' unit tests. The only question is if we actually need it in such detail.

Test plan

CI tests are sufficient.

@tjzel tjzel requested a review from tomekzaw May 9, 2023 14:08
@tomekzaw tomekzaw mentioned this pull request May 9, 2023
6 tasks
@tjzel tjzel added this pull request to the merge queue May 9, 2023
Merged via the queue into main with commit 7029f16 May 9, 2023
1 check passed
@tjzel tjzel deleted the @tjzel/plugin-idempotency branch May 9, 2023 16:44
fluiddot pushed a commit to wordpress-mobile/react-native-reanimated that referenced this pull request Jun 5, 2023
…e-mansion#4441)

<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect. -->

## Summary

For correct functioning of Reanimated idempotency of our Babel plugin is
important. This PR adds a few unit tests for plugin's triggers in
more-or-less complicated situations.

This obviously is not a confirmation of idempotency, that's arguably
unachievable with simple unit tests. There is however some additional
step that can be taken here.

In `plugin/` we have a development README with some simple chart of
plugin's logic included. This chart could be expanded to contain more
details about the results of code transformations thus lead to proof of
idempotency. For example:
- Plugin is idempotent within _explicit worklets scope_
(FunctionDeclarations, FunctionExpressions, ArrowFunctionExpressions).

How do we know this? It's simple: every explicit worklet will be
transformed to a CallExpression. CallExpressions are not transformed
within this scope, hence another run of plugin will not transform
anything.

By saying _scope_ I mean some limited transformation cases: plugin will
not attempt _explicit worklet_ transformation of already transformed
_explicit worklet_. It will however try to transform a CallExpression if
this CallExpression is for eg. named `useAnimatedStyle` and explicit
worklets are transformed to CallExpressions. This transformation will
probably still be idempotent though.

Therefore, the next step after checking idempotency within those scopes
would be to analyze the situations when the result of a certain
transformation crosses a boundary of two scopes.

Creation of a chart that would contain all of necessary information for
the idempotency proof seems to be quite a lot of work but is definitely
doable and would certainly be much more informative than some 'random'
unit tests. The only question is if we actually need it in such detail.

## Test plan

CI tests are sufficient.

<!-- Provide a minimal but complete code snippet that can be used to
test out this change along with instructions how to run it and a
description of the expected behavior. -->
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.

None yet

2 participants