Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Some questions: move, ctors, operator overloading #1685

Closed
MBkkt opened this issue Jul 25, 2022 · 4 comments
Closed

Some questions: move, ctors, operator overloading #1685

MBkkt opened this issue Jul 25, 2022 · 4 comments

Comments

@MBkkt
Copy link

MBkkt commented Jul 25, 2022

I think something like move ctor/assign should be in language. Will it be like rust, with destructive move? Or like c++?
I think both approaches have some pros and cons.

Also about constructors and operator overloading, if carbon will be without exceptions looks it looks like a bad idea to have them

So what your thoughts about that?

@geoffromer
Copy link
Contributor

geoffromer commented Jul 25, 2022

Yes, Carbon will support move semantics; see p0257. In particular, we are experimenting with a hybrid of destructive and non-destructive semantics that we are hoping will combine the advantages of both.

@MBkkt
Copy link
Author

MBkkt commented Jul 26, 2022

@geoffromer thanks, I checked that about other questions?

Also about move:

Disadvantages:
Doesn't compose with pointers and C++ idioms which involve moving out of non-local objects through a pointer.
Would require redesigning systems to model the lifetime in the type system.

I like destructive move more but Rust have other cons:

  • not to be able pointer to self (libstdc++ sso string (same for vector, etc, we can implement only flag implementation))
  • main issue from my point of view: runtime bool in some statements (need to call dtor or not), I don't think it's dramatic bad (in current state at least, but was really bad in early rust)
    Check this Static drop semantics rust-lang/rfcs#210 and maybe this https://rust-lang.github.io/rfcs/2094-nll.html
    It's about early drop, maybe with something like this it will be better.

@github-actions
Copy link

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please comment or remove the inactive label. The long term label can also be added for issues which are expected to take time.
This issue is labeled inactive because the last activity was over 90 days ago.

@github-actions github-actions bot added the inactive Issues and PRs which have been inactive for at least 90 days. label Oct 25, 2022
@chandlerc chandlerc removed the inactive Issues and PRs which have been inactive for at least 90 days. label Oct 26, 2022
@chandlerc
Copy link
Contributor

Sorry this fell off folks radar...

about other questions?

We expect to need something analogous to operator overloading to really retain the same kind of expressive library API capabilities as C++ provides, but we're using a pretty fundamentally different approach to get there that we think will address many problems with it.

Similarly, we are using a different approach to constructors somewhat fundamentally.

Both of these are covered in the design overview.

Also about move:

Disadvantages:
Doesn't compose with pointers and C++ idioms which involve moving out of non-local objects through a pointer.
Would require redesigning systems to model the lifetime in the type system.

I like destructive move more but Rust have other cons:

  • not to be able pointer to self (libstdc++ sso string (same for vector, etc, we can implement only flag implementation))
  • main issue from my point of view: runtime bool in some statements (need to call dtor or not), I don't think it's dramatic bad (in current state at least, but was really bad in early rust)
    Check this Static drop semantics rust-lang/rfcs#210 and maybe this rust-lang.github.io/rfcs/2094-nll.html
    It's about early drop, maybe with something like this it will be better.

We're definitely looking at all of these options. We also have some challenging constraints due to interoperating with C++. As mentioned, we have a plan involving a hybrid approach that so far looks promising.


I'm going to convert this to a GitHub discussion as this isn't really an issue BTW. We also have an active language questions channel on our Discord.

@carbon-language carbon-language locked and limited conversation to collaborators Oct 26, 2022
@chandlerc chandlerc converted this issue into discussion #2352 Oct 26, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants