Skip to content

Feature: Implement Rebindable for non-class/non-array types.#8722

Merged
RazvanN7 merged 1 commit intodlang:masterfrom
FeepingCreature:feature/rebindable-for-structs
Apr 18, 2023
Merged

Feature: Implement Rebindable for non-class/non-array types.#8722
RazvanN7 merged 1 commit intodlang:masterfrom
FeepingCreature:feature/rebindable-for-structs

Conversation

@FeepingCreature
Copy link
Copy Markdown
Contributor

@FeepingCreature FeepingCreature commented Mar 16, 2023

Implement Rebindable!T where T is any type, including const and immutable.

Arrays, objects and interfaces are still handled by the old Rebindable implementation.

Note that you cannot access a reference to the contained value in Rebindable. This is unavoidable; otherwise you could violate constness. For this and related information, see my 2022 DConf talk https://www.youtube.com/watch?v=eGX_fxlig8I

As opposed to the previous PR, this implementation deliberately contains the least amount of code to do something useful. As per review feedback, this PR is a simplified version of #8674 , which was a rewrite of #6136, which was itself a revival of #4363. This time for sure!

@dlang-bot
Copy link
Copy Markdown
Contributor

Thanks for your pull request and interest in making D better, @FeepingCreature! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + phobos#8722"

@thewilsonator
Copy link
Copy Markdown
Contributor

Please add either a changelog or an issue this closes.

@FeepingCreature FeepingCreature force-pushed the feature/rebindable-for-structs branch from 4624a54 to 3c2ecf3 Compare March 16, 2023 12:42
@FeepingCreature
Copy link
Copy Markdown
Contributor Author

Added a changelog entry.

@FeepingCreature FeepingCreature force-pushed the feature/rebindable-for-structs branch 2 times, most recently from 8e543c4 to 41dc73c Compare March 17, 2023 07:24
@FeepingCreature
Copy link
Copy Markdown
Contributor Author

Ping @RazvanN7 @atilaneves since you reviewed the predecessor, @wilzbach @ntrel as fyi (predecessor PRs)

@safe unittest
/// ditto
struct Rebindable(T)
if (!is(T == class) && !is(T == interface) && !isDynamicArray!T && !isAssociativeArray!T)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Are we really targeting all types? Or is this another way to say T == struct || T == basic type ? T could also be an AliasSeq, is that supposed to be supported?

Copy link
Copy Markdown
Contributor Author

@FeepingCreature FeepingCreature Mar 21, 2023

Choose a reason for hiding this comment

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

T cannot be an AliasSeq because AliasSeq (except with one member) doesn't match to T. Everything else is targeted, sure. What wouldn't be?

It should work with anything that can be copied and returned from a function.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Isn't the condition cleaner and more expressive if it states the targeted types rather than negating the ones that are not?

Copy link
Copy Markdown
Contributor Author

@FeepingCreature FeepingCreature Mar 21, 2023

Choose a reason for hiding this comment

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

Right, but I genuinely don't know which types it wouldn't work for (void, I guess?), so the condition would just be a list of "every type in D except those handled by the other Rebindable implementation." Which is better expressed by inverting the condition from that type.

Enumerating types makes sense if something in the implementation is specific to those types. It isn't - sizeof, alignof and pointer casts work with everything.

@FeepingCreature FeepingCreature force-pushed the feature/rebindable-for-structs branch from 41dc73c to e3d7e76 Compare March 21, 2023 09:24
@FeepingCreature
Copy link
Copy Markdown
Contributor Author

ping

@dkorpel
Copy link
Copy Markdown
Contributor

dkorpel commented Mar 29, 2023

@atilaneves

Copy link
Copy Markdown
Contributor

@dkorpel dkorpel left a comment

Choose a reason for hiding this comment

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

@atilaneves Do you approve this feature?

///
@system unittest
{
class CustomOpEq
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why are the tests for a rebindable class removed?

@FeepingCreature FeepingCreature force-pushed the feature/rebindable-for-structs branch from 6fbea55 to 46a04b0 Compare April 5, 2023 10:24
/**
* Constructs a `Rebindable` from a given value.
*/
this(T value) @trusted
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What if the type can't be copied?

@atilaneves
Copy link
Copy Markdown
Contributor

Nice. Given that there are two implementations, how do we ensure that they both act the same way? Is there any difference in the API?

@FeepingCreature
Copy link
Copy Markdown
Contributor Author

FeepingCreature commented Apr 7, 2023

Yes, there are critical API differences: non-class Rebindable cannot offer refaccess. (Or it would be unusable for immutable, or it would violate the const system). If the value can only be accessed by copying, that's why we are justified in ignoring constness for the store location. I think ref access is not load bearing for the things that Rebindableis usually used for, which is why I think that's fine.

@atilaneves
Copy link
Copy Markdown
Contributor

I think it's ok to not offer some functionality depending on type.

@FeepingCreature
Copy link
Copy Markdown
Contributor Author

Yeah my hope is that non-copyable types and immutable types will basically be non-overlapping categories.

@FeepingCreature
Copy link
Copy Markdown
Contributor Author

ping

@FeepingCreature
Copy link
Copy Markdown
Contributor Author

FeepingCreature commented Apr 17, 2023

Rebased in hopes the tests pass now.

edit: Cannot reproduce the buildkite failure locally.

Note that you cannot access a reference to the contained value in struct Rebindable.
@FeepingCreature FeepingCreature force-pushed the feature/rebindable-for-structs branch from c7ca5d0 to d6f0f70 Compare April 17, 2023 14:52
@FeepingCreature
Copy link
Copy Markdown
Contributor Author

Pushed bogus change to hopefully rerun the buildkite.

@FeepingCreature
Copy link
Copy Markdown
Contributor Author

Okay, ddox failed again. Two times is enemy action. What's going on there?

It doesn't happen if I run locally, and there's no error in the build output, only "exit code 1". Any ideas?

@dkorpel
Copy link
Copy Markdown
Contributor

dkorpel commented Apr 17, 2023

Looks unrelated, other PRs have it as well. Perhaps @RazvanN7 can force merge this

@RazvanN7 RazvanN7 merged commit c26d25e into dlang:master Apr 18, 2023
@FeepingCreature FeepingCreature deleted the feature/rebindable-for-structs branch April 18, 2023 08:36
@FeepingCreature
Copy link
Copy Markdown
Contributor Author

FeepingCreature commented Apr 18, 2023

OMG it actually happened!!

starts prepping follow-up PRs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants