[Feature Request] Replace __copyinit__
(a constructor) with an ordinary instance method named __copy__
. (And do the same for move constructors.)
#3914
Labels
Review Mojo's priorities
What is your request?
Following a discussion on Discord #nightly, I propose that we turn
__copyinit__
and__moveinit__
into instance methods, and update their names to reflect this change.In today's Mojo,
__copyinit__
is modelled as a special kind of constructor. More precisely, the following program:Desugars to:
In my opinion, this is not a very intuitive model for copy operations. It would be simpler if
y = x
desugared to a method call onx
:A similar issue occurs with
__moveinit__
. Ideally, the following program:Would desugar to:
CC @lattner.
What is your motivation for this change?
To make it easier for Mojo learners to understand what happens when you write
y = x
ory = x^
.Any other details?
__copy__
and__move__
would still need to be "constructor-like" in that they can initialize their return value field-by-field. In the short term, we can make this happen though compiler magic, as happens for constructors. In the long term, maybe we should try to find a general way to designate a method as being a constructor.If we agree to adopt this proposal, we should probably first let the design for explicit copyability settle, since this might affect the name that we give the
__copy__
method.The text was updated successfully, but these errors were encountered: