-
Notifications
You must be signed in to change notification settings - Fork 413
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
Implementation for init= #12387
Implementation for init= #12387
Conversation
The 'resolveInitVar' function has been updated to try to resolve 'init=' if the old-style 'init' copy initializer cannot be resolved. Miscellaneous branches have been simplified. The 'findCopyInit' and 'fixupDefaultInitCopy' functions have been similarly updated.
…om mismatched boundedType parameter
This PR updates the "records.chpl" primer to use init=, but would pass if we used the old-style copy initializer. Do we want to make this change where users would see it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good to me. I had some questions and relatively minor feedback. Thanks!
Also do you know if we have any tests/futures of init=
than use the in
intent? Arguably that creates an infinite loop in compilation (since the in
intent would normally mean copy-initializing, right?) but if somebody is confused it'd be nice if we gave a reasonable error.
@@ -3551,7 +3551,7 @@ GenRet CallExpr::codegen() { | |||
|
|||
// Handle setting LLVM invariant on const records after | |||
// they are initialized | |||
if (fn->isInitializer()) { | |||
if (fn->isInitializer() || fn->isCopyInit()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These adjustments seem strange to me since I consider init=
a kind of initializer. Maybe there's a way to rename isInitializer
to make it less confusing. That would be reasonable to create a future work issue about.
@@ -155,7 +155,7 @@ void normalize() { | |||
} | |||
USR_FATAL_CONT(fn, "Type '%s' defines a constructor here", ct->symbol->name); | |||
|
|||
} else if (fn->isInitializer() == true) { | |||
} else if (fn->isInitializer() || fn->isCopyInit()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change occurs enough in this PR that I'm starting to think it'd be worth adding FnSymbol::isCopyOrRegularInit
or something like that...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like something like this too, and something that would handle the strcmp cases too. Do you want that to be done for this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only if you think it'll help you get the code correct. If you choose to put it off, let's make an issue and put it to get worked on soon.
This PR implements support for the new kind of copy initializer, named "init=". This copy initializer will follow similar rules as a regular initializer (e.g. initialize fields in order). The init= method will be invoked for compiler-inserted copies of records, and for initialization of variables from an expression. A simple case is initializing from the same type:
A more interesting case is when initializing from a different type:
Generic types require an additional type formal that represents the intended instantiation:
As a result of this functionality, atomic variables can be initialized from values:
This PR allows for the old-style copy initializers to still be invoked, unless the user has implemented their own init= methods.
Testing: