Skip to content

Conversation

@MrGVSV
Copy link
Member

@MrGVSV MrGVSV commented Aug 19, 2024

Objective

One of the changes in #14704 made DynamicFunction effectively the same as DynamicClosure<'static>. This change meant that the de facto function type would likely be DynamicClosure<'static> instead of the intended DynamicFunction, since the former is much more flexible.

We could explore ways of making DynamicFunction implement Copy using some unsafe code, but it likely wouldn't be worth it. And users would likely still reach for the convenience of DynamicClosure<'static> over the copy-ability of DynamicFunction.

The goal of this PR is to fix this confusion between the two types.

Solution

Firstly, the DynamicFunction type was removed. Again, it was no different than DynamicClosure<'static> so it wasn't a huge deal to remove.

Secondly, DynamicClosure<'env> and DynamicClosureMut<'env> were renamed to DynamicFunction<'env> and DynamicFunctionMut<'env>, respectively.

Yes, we still ultimately kept the naming of DynamicFunction, but changed its behavior to that of DynamicClosure<'env>. We need a term to refer to both functions and closures, and "function" was the best option.

Originally, I was going to go with "callable" as the replacement term to encompass both functions and closures (e.g. DynamciCallable<'env>). However, it was suggested by @SkiFire13 that the simpler "function" term could be used instead.

While "callable" is perhaps the better umbrella term—being truly ambiguous over functions and closures— "function" is more familiar, used more often, easier to discover, and is subjectively just "better-sounding".

Testing

Most changes are purely swapping type names or updating documentation, but you can verify everything still works by running the following command:

cargo test --package bevy_reflect

@MrGVSV MrGVSV added C-Docs An addition or correction to our documentation C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Reflection Runtime information about types D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Aug 19, 2024
@MrGVSV MrGVSV added this to the 0.15 milestone Aug 19, 2024
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

I prefer the new naming! We should be sure to ship this in 0.15.

Copy link
Contributor

@soqb soqb left a comment

Choose a reason for hiding this comment

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

looks good!

@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Aug 19, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Aug 19, 2024
Merged via the queue into bevyengine:main with commit 2b4180c Aug 19, 2024
@MrGVSV MrGVSV deleted the mrgvsv/reflect/callable-refactor branch August 19, 2024 22:43
github-merge-queue bot pushed a commit that referenced this pull request Aug 22, 2024
# Objective

It looks like running `compile_fail_utils::test` on an invalid path just
skips the test. I'm not sure why `ui_test` doesn't fail the test, but it
seems pretty easy to accidentally cause a test to be skipped (I
experienced
[this](#14813 (comment))
while doing some refactoring on `bevy_reflect`).

## Solution

Check to make sure the given path exists before continuing on with the
tests.

Alternatively, we could look into seeing why this doesn't work properly
upstream. But I figured this solution was simple enough just to
implement directly without having to worry about updating `ui_test`.

## Testing

To verify that this works as expected `cd` into
`crates/bevy_reflect/compile_fail`. Then run the following:

```
cargo test --target-dir ../../../target
```

All compile fail tests should pass. Now edit the path used in
`crates/bevy_reflect/compile_fail/tests/derive.rs`. For example:

```diff
fn main() -> compile_fail_utils::ui_test::Result<()> {
-    compile_fail_utils::test("reflect_derive", "tests/reflect_derive")
+    compile_fail_utils::test("reflect_derive", "tests/does_not_exist")
}
```

Run the tests again:

```
cargo test --target-dir ../../../target
```

Verify the test fails with an error like:

```
Error: path does not exist: "tests/does_not_exist"
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Reflection Runtime information about types C-Docs An addition or correction to our documentation C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants