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

Impl ImplicitClone for arrays and ref arrays #42

Merged
merged 12 commits into from
Nov 9, 2023

Conversation

cecton
Copy link
Member

@cecton cecton commented Nov 5, 2023

@ranile
Copy link
Member

ranile commented Nov 5, 2023

I don't think this clone should be implicit. [0; 1024] would implement ImplcitClone end up closing a kilobyte of data without the user explicitly instructing to do so

@cecton
Copy link
Member Author

cecton commented Nov 5, 2023

Yeah but [u8; 1024] is Copy already...

fn main() {
    fn copy<T: Copy>(x: T) -> T { x }
    let x: [u8; 1024] = todo!();
    copy(x);
}

It does compile.

@kirillsemyonkin
Copy link
Collaborator

fn copy<T: Copy>(x: T) -> T { x }

Tip for this example lol, look at std::mem::copy, it does &T and *x

src/lib.rs Outdated
@@ -138,7 +138,7 @@ macro_rules! imap_deconstruct {
mod test {
use super::*;

fn host_library<T: ImplicitClone>(value: &T) -> T {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why? the point of the test wasn't just testing, it was an example of the "host library" term used in documentation

Copy link
Member Author

Choose a reason for hiding this comment

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

well if it's in test, the point is to test, and right now I need the test to show to the developer I am actually adding impls on types that are actually Copy

Copy link
Member Author

Choose a reason for hiding this comment

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

oh wait, the function is called "host_library" hahaha you're right

Copy link
Collaborator

Choose a reason for hiding this comment

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

well if it's in test, the point is to test

wrong, the point of a test is to document code in a way that has stronger guarantees (always actual info) than a comment or some sort of a separate wiki

Copy link
Member Author

Choose a reason for hiding this comment

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

I fixed it but you won't like it xD if you want doc you put it in doc though. I think that makes more sense. Who's gonna check the crate's test to see how a crate is used anyway 🤦‍♀️

Copy link
Member Author

Choose a reason for hiding this comment

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

If its possible, find a spot where to show to the user that they don't get implicit cloning in their code unless they make a host library (a macro)

I'm trying to find an example but the only thing I can think of is Yew's html itself. Maybe I can write an example with a simplified html! macro. what do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

wrong, the point of a test is to document code in a way that has stronger guarantees (always actual info) than a comment or some sort of a separate wiki

I mean the word itself is "test", at no point it's mentioning "document code". It's a single word and it's basic meaning is to test. It's true that I also sometimes consult the tests of a library to see how to use it but that's more because the thing is poorly documented. That never happened to me with crates in Rust, I never read Yew's tests to understand how to use the thing.

Copy link
Collaborator

Choose a reason for hiding this comment

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

all you need to show is that you no longer require clones

let a = SomeImmovableType;

host_library(a);
host_library(a); // fails, previous line moved the value

host_library!(a);
host_library!(a); // works, previous line cloned implicitly

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe I should go with something simpler like you show here. My example isn't super good :(

Copy link
Member Author

Choose a reason for hiding this comment

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

As you can see here and here it seems that people are still not understanding the point this crate despite our efforts to clarify it in #28.

What's interesting here is that you are right, people are definitely looking at the tests to see how it works! Though, I'm still in favor of providing a better and more sensical example within the documentation directly (crate doc + README).

Besides, I still would like the test to assert that we don't implement ImplicitClone on types that are not Copy.

(@kirillsemyonkin please bear with me as I really want to get to the bottom of this. As long as people are opening issues because they misunderstand or don't see how to use the crate, it means that there is work to do there and we should try our best to clarify things out.)

@kirillsemyonkin
Copy link
Collaborator

I don't think this clone should be implicit

Like @cecton mentioned, all Copy types should ideally be ImplicitClone (#32)

@cecton
Copy link
Member Author

cecton commented Nov 5, 2023

fn copy<T: Copy>(x: T) -> T { x }

Tip for this example lol, look at std::mem::copy, it does &T and *x

good to know! I checked but it's on nightly at the moment... so I'll keep the small function for now I guess

src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated
@@ -213,7 +213,6 @@ mod test {
#[test]
fn option() {
assert_implicit_clone!(Some("foo"));
// `assert_implicit_clone!(Some(NonImplicitCloneType));` doesn't compile
Copy link
Collaborator

Choose a reason for hiding this comment

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

-fail test would cover this lol

Copy link
Member Author

Choose a reason for hiding this comment

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

what do you mean? I don't understand

Copy link
Collaborator

Choose a reason for hiding this comment

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

if there were -fail tests like for macros, then this "doesn't compile" example would be put there

@cecton
Copy link
Member Author

cecton commented Nov 9, 2023

I didn't want to push changes we don't all agree on so I reverted the changes on the tests and documentation and make a separate PR for those so we can merge already the small change of this PR which is adding arrays to the ImplicitClone family.

@hamza1311 are you okay with the argument provided for implementing ImplicitClone on arrays?

@ranile
Copy link
Member

ranile commented Nov 9, 2023

Yeah, I understand that argument. Feel free to merge it when you want to

@cecton cecton merged commit 2606c0f into yewstack:main Nov 9, 2023
12 checks passed
@cecton cecton deleted the implicit-clone-for-arrays branch November 9, 2023 12:04
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