Skip to content

@value decorator generates constructors whose arguments are owned #392

Closed Locked Answered by lattner
armgabrielyan asked this question in Q&A
Discussion options

You must be logged in to vote

Sure, no problem. It passes /all/ of the arguments as owned. The reason Int isn't passed as owned is just because it doesn't matter either way - Int is a register_passable(trivial) type, and trivial types have no ownership. I added this statement to clarify, thanks!

The arguments to__init__ are all passed as owned arguments since the struct
takes ownership and stores the value. This is a useful micro-optimization and
enables the use of move-only types. Trivial types like Int are also passed
as owned values, but since that doesn't mean anything for them, we elide the
marker and the transfer operator (^) for clarity.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@armgabrielyan
Comment options

Answer selected by armgabrielyan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants