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

Adjust array copy initialization to avoid default-init/assign #15239

Merged
merged 124 commits into from
May 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
124 commits
Select commit Hold shift + click to select a range
d02a6a5
Add chpl__coerce and use it for array PRIM_COERCE
mppf Mar 16, 2020
5462e36
Get basic array init patterns working for default rectangular
mppf Mar 17, 2020
de255bd
Adjust DefaultAssociative for new buildArray
mppf Mar 17, 2020
8573ef0
Fix mis-merge
mppf Apr 24, 2020
8e44077
Do dsiBuildArray / dsiDestroyArray API adjustments
mppf Apr 24, 2020
efb911e
Fix up more cases
mppf Apr 26, 2020
0e83e8a
Add ability to copy initialize in transfer array
mppf Apr 26, 2020
a1d5482
Update test
mppf Apr 26, 2020
c63d8e5
Fix lvalue checking errors now that arrays can be expr-temps
mppf Apr 26, 2020
ade8b85
Fix bugs to get primers passing
mppf Apr 26, 2020
4377be3
Switching to two functions instead of param arg
mppf Apr 26, 2020
8d6e410
Fix bug and test
mppf Apr 27, 2020
4f5c0b5
Getting BlockDist case working, and testC1/testR1
mppf Apr 29, 2020
7761f82
Fix CyclicDist (and bug with chpl__uncheckedArrayTransfer)
mppf Apr 29, 2020
6f76dd5
Fix same-runtime-type case, add more testing
mppf Apr 29, 2020
a0b9303
Fix more distributions
mppf Apr 29, 2020
690b4f1
Fix block cyclic distribution
mppf Apr 29, 2020
a7b1ddb
Use typed copy initialization to work with sync/single
mppf Apr 30, 2020
7c0d5f2
Move array initialization patterns to own subdir
mppf Apr 30, 2020
48e645e
Enable copy elision for typed array init-copies
mppf Apr 30, 2020
d0fdc10
Add complex array intent interactions test & fix a bug
mppf May 1, 2020
2f1fd41
Adjust default/in/coerce/ intent handling
mppf May 1, 2020
f9e286b
Use init= in arrays/ferguson/semantic-examples/myrecord.chpl
mppf May 1, 2020
b0dd442
Tidy PRIM_STEAL handling
mppf May 1, 2020
f1a70a6
Disable replaceRecordWrappedRefs for now
mppf May 1, 2020
deec2a0
Use typed copy initialization in one more place
mppf May 2, 2020
b76e988
Fix array-of-array inited from tuple-of-tuple
mppf May 2, 2020
26009a6
Improve array initialization type mismatch error
mppf May 2, 2020
5582750
Pull init_elts_method out of init_elts
mppf May 2, 2020
1e11024
DefaultAssociative arrays - empty slots use uninited elts
mppf May 2, 2020
00b556d
Fix error for arrays of non-nilable
mppf May 2, 2020
db90ff1
Adjust insertCasts to handle PRIM_ASSIGN in addition to PRIM_MOVE
mppf May 4, 2020
affae6b
Add a comment in hack_resolve_types
mppf May 4, 2020
ad8e454
Add writelns to show different calls in this test
mppf May 4, 2020
bd3411c
Keep current behavior of default-init/assign for untyped in array args
mppf May 4, 2020
9fe8efb
Update two .goods for improvements in array init
mppf May 4, 2020
4172359
Fix test/arrays/shapes/field-defaults.chpl
mppf May 4, 2020
6407438
Fix bug in helpInitArrFromTuple
mppf May 4, 2020
cd332a0
Add domain initialization from array
mppf May 4, 2020
5871ada
Use PRIM_COERCE for domain assignment too in defaultedFormalApplyDefa…
mppf May 5, 2020
df177e9
Fix insertCasts for PRIM_ASSIGN
mppf May 5, 2020
333798c
Fix typed default args and improve error messages
mppf May 5, 2020
8c32b15
Fix error messages in nilability-init-field-dflt tests
mppf May 6, 2020
0b2ee82
Accept improvements in array initialization behavior
mppf May 6, 2020
d5da17d
Allow array/assoc domain init from any iterable type
mppf May 6, 2020
c7a10fc
Ignore transfer errors in bulk-copy fixup
mppf May 6, 2020
cec9430
Add astr for postinit, use astr for init
mppf May 6, 2020
fbfa50a
Change hasPostInitializer to use a flag
mppf May 6, 2020
e6b4da4
Fix copy elision to avoid leaving extra postinit calls
mppf May 6, 2020
c69e20d
Tidy up test new-promoted
mppf May 6, 2020
d90563d
Fix externFreeFunc arg to DefaultRectangularArr init
mppf May 6, 2020
933adc7
Accept difference in array init for promotion
mppf May 6, 2020
f85cc98
NOTEST users/engin/partial_reduction_support/template_tests/
mppf May 6, 2020
7a3ebc4
Fix problems in typeExprReturnsType
mppf May 6, 2020
6c7ac49
Always init/deinit the fluff in StencilDist
mppf May 6, 2020
48b15e3
InsertionSort called from QuickSort uses shallow copies
mppf May 6, 2020
2d45d3d
Add a test of ChapelDebugPrint.chpl_debug_writeln
mppf May 6, 2020
1346ffc
Accept change in module init order
mppf May 6, 2020
205999f
Put back old error message
mppf May 7, 2020
852b2d2
Improve illegal assignment from nil error
mppf May 7, 2020
e93cba2
Accept error message improvement nn default arg mismatch
mppf May 7, 2020
142947f
Include error for assignment to local domain from distributed
mppf May 7, 2020
ce23912
Accept change in deinit order for inThenOut test
mppf May 7, 2020
ed5c41c
Update DR dsiReallocate to move elements always
mppf May 7, 2020
935f4e2
Factor _ddata_allocate into two routines
mppf May 8, 2020
4988130
Adjust DefaultAssociative for init idx/elt when added
mppf May 8, 2020
b0f0791
Fix a memory leak and better factor deinit code
mppf May 9, 2020
616e4fa
Leave array elt deinits serial, add _deinitElementsIsParallel to toggle
mppf May 9, 2020
70d95df
Apply workaround for c_ptrTo for assoc-of-array
mppf May 9, 2020
1c9287a
Accept improvement in error message
mppf May 9, 2020
94227a1
Use _deinitElementsIsParallel in two more places
mppf May 9, 2020
5f16041
Make this test output slightly easier to follow
mppf May 9, 2020
d01508c
Fix memory error in associative domains
mppf May 9, 2020
b6bc5cf
Fix race condition in _rehash
mppf May 9, 2020
5deaedc
Fix problem with _add finding deleted slots with later value
mppf May 9, 2020
60944d8
Fix bug with resize new size
mppf May 9, 2020
7e0881d
Remove findEmptySlot, rename findFilledSlot to findSlot
mppf May 9, 2020
3845564
Fix map
mppf May 9, 2020
542027c
Fix error message in two .good files
mppf May 10, 2020
c46946a
Leave some assoc debug prints to debugAssocDataPar
mppf May 10, 2020
5a24fda
Fix initialization/deinitialization for sparse arrays
mppf May 10, 2020
7fff3f7
Fix unordered forall opt for PRIM_ASSIGN
mppf May 11, 2020
baef342
Fix line number reporting for chpl__coerceMove etc
mppf May 11, 2020
1d3635f
Add missing cast from numeric to longdouble
mppf May 11, 2020
b50eb31
Adjust map this() returning to use ref intent for this
mppf May 11, 2020
37aed18
Fix borrowed array initialization from owned
mppf May 11, 2020
a558a2e
Don't deinit fluff twice
mppf May 11, 2020
504c4e0
Update AccumStencilDist similarly to StencilDist
mppf May 11, 2020
43d9378
Garbage collect deleted entries if no slot found when adding
mppf May 11, 2020
0864880
Add a new test showing previous bug in associative arrays
mppf May 11, 2020
b8e8798
Fix unordered forall opt for PRIM_ASSIGN - take 2
mppf May 11, 2020
c966bf8
Fix typed in intent array initialization, add testing
mppf May 12, 2020
3cf80b5
Rename defaultedFormalApplyDefaultForType -> defaultedFormalApplyDefa…
mppf May 12, 2020
eda36cf
Adjust chpl__initCopy(ir: _iteratorRecord) to use new ddata allocate …
mppf May 12, 2020
3c139d0
Wire post-alloc calls through DSI interface
mppf May 12, 2020
f59c74c
Un-future some futures that now pass
mppf May 13, 2020
a674059
Fix changes to HashedDist
mppf May 13, 2020
37dbf41
Tighten workaround in replaceRecordWrappedRefs
mppf May 13, 2020
9406f41
Call chpl__coerceCopy from array initCopy
mppf May 13, 2020
5edff8b
Move --memLeaks to per-test setting
mppf May 13, 2020
bbeda7d
Fix PrivateDist array init behavior, add tests
mppf May 13, 2020
544b203
Fix array of owned copy-init error
mppf May 13, 2020
698b13e
Accept change from default init/= in inout array handling
mppf May 13, 2020
37603ca
Use a different workaround for replaceRecordWrappedRefs
mppf May 14, 2020
651740c
Reduce comms in DefaultRectangularArr.isDataContiguous
mppf May 14, 2020
1ccbd99
Accept increase in comm for remote domain local DR array
mppf May 14, 2020
bb333bb
Put coforall+on back syntactically next to each other
mppf May 15, 2020
31b662d
Accept comm count improvements for block
mppf May 15, 2020
4027d4e
Accept minor comm count increase for cyclic
mppf May 15, 2020
80aa475
Accept one more Block improvement in comm counts
mppf May 15, 2020
a7d19bd
Accept replicated comm count improvements
mppf May 15, 2020
095b670
Don't bulk transfer for copy init from owned C?
mppf May 15, 2020
16f566e
Fix compilation error in AccumStencilDist.chpl which is used by CoMD
mppf May 15, 2020
5900f94
Fix problem with PrivateDist by allowing pragma no init on fields
mppf May 15, 2020
158c3aa
Apply replaceRecordWrappedRefs init workaround also to chpl__initCopy…
mppf May 16, 2020
5b29cba
Notest submitted knucleotide3
mppf May 17, 2020
6bb1042
Always use = in this array perf test instead of init
mppf May 17, 2020
443d3cb
Fix problem with PrivateDist
mppf May 17, 2020
01fa4e7
Accept comm count improvement for sliceBlockWithRanges
mppf May 17, 2020
e2f0382
Fix problems with errors for array-of-owned
mppf May 17, 2020
a7a8734
Accept .good change - only showing domain warning once
mppf May 18, 2020
96084bf
Fix bug with numElts free getting zero size
mppf May 18, 2020
ede7fa5
Remove comment-out code
mppf May 18, 2020
42dcf18
Use astrs for chpl__ initCopy/autoCopy/coerceCopy/coerceMove
mppf May 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 9 additions & 28 deletions compiler/AST/AggregateType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,22 +653,7 @@ bool AggregateType::hasInitializers() const {
}

bool AggregateType::hasPostInitializer() const {
bool retval = false;

// If there is postinit() it is defined on the defining type
if (instantiatedFrom == NULL) {
int size = methods.n;

for (int i = 0; i < size && retval == false; i++) {
if (methods.v[i] != NULL)
retval = methods.v[i]->isPostInitializer();
}

} else {
retval = instantiatedFrom->hasPostInitializer();
}

return retval;
return symbol->hasFlag(FLAG_HAS_POSTINIT);
}

bool AggregateType::hasUserDefinedInitEquals() const {
Expand Down Expand Up @@ -2312,9 +2297,11 @@ void AggregateType::fieldToArg(FnSymbol* fn,

if (LoopExpr* fe = toLoopExpr(defPoint->init)) {
if (field->isType() == false) {
CallExpr* copy = new CallExpr("chpl__initCopy");
defPoint->init->replace(copy);
copy->insertAtTail(fe);
if (defPoint->exprType == NULL) {
CallExpr* copy = new CallExpr(astr_initCopy);
defPoint->init->replace(copy);
copy->insertAtTail(fe);
}
}
}

Expand Down Expand Up @@ -2366,19 +2353,13 @@ void AggregateType::fieldToArg(FnSymbol* fn,
fieldToArgType(defPoint, arg);

arg->defaultExpr = new BlockStmt(defPoint->init->copy());
arg->typeExpr = new BlockStmt(defPoint->exprType->copy());

} else {
fieldToArgType(defPoint, arg);

CallExpr* def = new CallExpr(PRIM_DEFAULT_INIT_FIELD,
// It would be easiest to just put 'field' here, however
// it is replaced with 'arg' in buildDefaultInitializer().
new_StringSymbol(field->defPoint->parentSymbol->name),
new_StringSymbol(field->name),
defPoint->exprType->copy(),
defPoint->init->copy());

arg->defaultExpr = new BlockStmt(def);
arg->defaultExpr = new BlockStmt(defPoint->init->copy());
arg->typeExpr = new BlockStmt(defPoint->exprType->copy());
}
}

Expand Down
1 change: 0 additions & 1 deletion compiler/AST/CallExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,6 @@ bool isInitOrReturn(CallExpr* call, SymExpr*& lhsSe, CallExpr*& initOrCtor)
call->isPrimitive(PRIM_INIT_VAR_SPLIT_DECL) ||
call->isPrimitive(PRIM_INIT_VAR) ||
call->isPrimitive(PRIM_INIT_VAR_SPLIT_INIT) ||
call->isPrimitive(PRIM_DEFAULT_INIT_FIELD) ||
call->isPrimitive(PRIM_INIT_FIELD)) {
lhsSe = toSymExpr(call->get(1));
initOrCtor = NULL;
Expand Down
4 changes: 2 additions & 2 deletions compiler/AST/FnSymbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -907,11 +907,11 @@ bool FnSymbol::isCompilerGenerated() const {
}

bool FnSymbol::isInitializer() const {
return isMethod() == true && strcmp(name, "init") == 0;
return isMethod() == true && name == astrInit;
}

bool FnSymbol::isPostInitializer() const {
return isMethod() == true && strcmp(name, "postinit") == 0;
return isMethod() == true && name == astrPostinit;
}

bool FnSymbol::isDefaultInit() const {
Expand Down
7 changes: 4 additions & 3 deletions compiler/AST/primitive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,9 +654,6 @@ initPrimitive() {
// dst, src. PRIM_MOVE can set a reference.
prim_def(PRIM_MOVE, "move", returnInfoVoid, false);

// dst, aggregate name, field name, type to default-init, value to init from
prim_def(PRIM_DEFAULT_INIT_FIELD, "default init field", returnInfoVoid);

// dst, type to default-init
prim_def(PRIM_DEFAULT_INIT_VAR, "default init var", returnInfoVoid);

Expand Down Expand Up @@ -1081,6 +1078,10 @@ initPrimitive() {

prim_def(PRIM_NEEDS_AUTO_DESTROY, "needs auto destroy", returnInfoBool, false, false);

// if the argument is a value, mark it with "no auto destroy"
// (no effect on a reference)
prim_def(PRIM_STEAL, "steal", returnInfoFirst, false, false);

// Indicates the end of a statement. This is important for the
// deinitialization location for some variables.
// Any arguments are SymExprs to user variables that should be alive until
Expand Down
11 changes: 11 additions & 0 deletions compiler/AST/symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1985,6 +1985,7 @@ const char* astrInit = NULL;
const char* astrInitEquals = NULL;
const char* astrNew = NULL;
const char* astrDeinit = NULL;
const char* astrPostinit = NULL;
const char* astrTag = NULL;
const char* astrThis = NULL;
const char* astrSuper = NULL;
Expand All @@ -1999,6 +2000,10 @@ const char* astr_loopexpr_iter = NULL;
const char* astrPostfixBang = NULL;
const char* astrBorrow = NULL;
const char* astr_init_coerce_tmp = NULL;
const char* astr_autoCopy = NULL;
const char* astr_initCopy = NULL;
const char* astr_coerceCopy = NULL;
const char* astr_coerceMove = NULL;

void initAstrConsts() {
astrSassign = astr("=");
Expand All @@ -2016,6 +2021,7 @@ void initAstrConsts() {
astrInitEquals = astr("init=");
astrNew = astr("_new");
astrDeinit = astr("deinit");
astrPostinit = astr("postinit");
astrTag = astr("tag");
astrThis = astr("this");
astrSuper = astr("super");
Expand All @@ -2033,6 +2039,11 @@ void initAstrConsts() {

astrBorrow = astr("borrow");
astr_init_coerce_tmp = astr("init_coerce_tmp");

astr_autoCopy = astr("chpl__autoCopy");
astr_initCopy = astr("chpl__initCopy");
astr_coerceCopy = astr("chpl__coerceCopy");
astr_coerceMove = astr("chpl__coerceMove");
}

/************************************* | **************************************
Expand Down
3 changes: 3 additions & 0 deletions compiler/include/flags_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ symbolFlag( FLAG_CHPL__ITER_NEWSTYLE , npr, "chpl__iter_newstyle", ncm )
symbolFlag( FLAG_COBEGIN_OR_COFORALL , npr, "cobegin or coforall" , ncm )
symbolFlag( FLAG_COBEGIN_OR_COFORALL_BLOCK , npr, "cobegin or coforall block" , ncm )
symbolFlag( FLAG_COERCE_TEMP , npr, "coerce temp" , "a temporary that was stores the result of a coercion" )
symbolFlag( FLAG_COERCE_FN, ypr, "coerce fn" , "coerce copy/move function" )
symbolFlag( FLAG_CODEGENNED , npr, "codegenned" , "code has been generated for this type" )
symbolFlag( FLAG_COFORALL_INDEX_VAR , npr, "coforall index var" , ncm )
symbolFlag( FLAG_COMMAND_LINE_SETTING , ypr, "command line setting" , ncm )
Expand Down Expand Up @@ -162,6 +163,7 @@ symbolFlag( FLAG_GET_FUNCTION_NAME, ypr, "get function name", "replace calls to
symbolFlag( FLAG_GET_MODULE_NAME, ypr, "get module name", "replace calls to this function with the name of the module the call was in" )

symbolFlag( FLAG_GLOBAL_TYPE_SYMBOL, ypr, "global type symbol", "is accessible through a global type variable")
symbolFlag( FLAG_HAS_POSTINIT , ypr, "has postinit" , "type that has a postinit method" )
symbolFlag( FLAG_HAS_RUNTIME_TYPE , ypr, "has runtime type" , "type that has an associated runtime type" )
symbolFlag( FLAG_RVV, npr, "RVV", "variable is the return value variable" )
symbolFlag( FLAG_YVV, npr, "YVV", "variable is a yield value variable" )
Expand Down Expand Up @@ -406,6 +408,7 @@ symbolFlag( FLAG_UNCHECKED_THROWS, ypr, "unchecked throws" , "function throws b
symbolFlag( FLAG_UNREF_FN, ypr, "unref fn" , "function to remove reference fields from tuples or copy array slices when returning")
symbolFlag( FLAG_UNSAFE, ypr, "unsafe" , "unsafe (disable lifetime and nilability checking)")
symbolFlag( FLAG_IGNORE_TRANSFER_ERRORS, ypr, "ignore transfer errors" , "ignore errors for ownership transfer from non-nilable owned" )
symbolFlag( FLAG_FIND_USER_LINE, ypr, "find user line" , "report errors with user line number")
symbolFlag( FLAG_USER_VARIABLE_NAME, npr, "user variable name" , "temporary uses name of user variable")
symbolFlag( FLAG_VECTORIZE_YIELDING_LOOPS, ypr, "vectorize yielding loops", "used to explicitly vectorize yielding loops in iterators" )
symbolFlag( FLAG_VIRTUAL , npr, "virtual" , ncm )
Expand Down
2 changes: 1 addition & 1 deletion compiler/include/primitive_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
PRIMITIVE_G(PRIM_NOOP)
PRIMITIVE_G(PRIM_MOVE)

PRIMITIVE_R(PRIM_DEFAULT_INIT_FIELD)
PRIMITIVE_R(PRIM_DEFAULT_INIT_VAR)
PRIMITIVE_R(PRIM_INIT_FIELD)
PRIMITIVE_R(PRIM_INIT_VAR)
Expand Down Expand Up @@ -270,6 +269,7 @@
PRIMITIVE_R(PRIM_HAS_DEFAULT_VALUE)
PRIMITIVE_R(PRIM_NEEDS_AUTO_DESTROY)
PRIMITIVE_R(PRIM_END_OF_STATEMENT)
PRIMITIVE_R(PRIM_STEAL)
PRIMITIVE_R(PRIM_AUTO_DESTROY_RUNTIME_TYPE)

PRIMITIVE_R(PRIM_GET_RUNTIME_TYPE_FIELD)
Expand Down
5 changes: 5 additions & 0 deletions compiler/include/resolution.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ void getAutoCopyTypeKeys(Vec<Type*>& keys);
FnSymbol* getAutoCopy(Type* t); // returns NULL if there are none
FnSymbol* getAutoDestroy(Type* t); // "
FnSymbol* getUnalias(Type* t);
FnSymbol* getCoerceMoveFromCoerceCopy(FnSymbol* coerceCopyFn);
const char* getErroneousCopyError(FnSymbol* fn);
void markCopyErroneous(FnSymbol* fn, const char* err);

Expand Down Expand Up @@ -328,4 +329,8 @@ void startGenerousResolutionForErrors();
bool inGenerousResolutionForErrors();
void stopGenerousResolutionForErrors();


// Return the array element type, or NULL if not an array
Type* arrayElementType(Type* arrayType);

#endif
6 changes: 6 additions & 0 deletions compiler/include/symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ extern const char* astrInit;
extern const char* astrInitEquals;
extern const char* astrNew;
extern const char* astrDeinit;
extern const char* astrPostinit;
extern const char* astrTag;
extern const char* astrThis;
extern const char* astrSuper;
Expand All @@ -708,6 +709,11 @@ extern const char* astr_loopexpr_iter;
extern const char* astrPostfixBang;
extern const char* astrBorrow;
extern const char* astr_init_coerce_tmp;
extern const char* astr_autoCopy;
extern const char* astr_initCopy;
extern const char* astr_coerceCopy;
extern const char* astr_coerceCopy;
extern const char* astr_coerceMove;

void initAstrConsts();

Expand Down
22 changes: 14 additions & 8 deletions compiler/optimizations/optimizeForallUnorderedOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,12 @@ static
bool exprIsOptimizable(BlockStmt* loop, Expr* lastStmt,
LifetimeInformation* lifetimeInfo) {
if (CallExpr* call = toCallExpr(lastStmt)) {
if (call->isNamed("=")) {
if (call->isPrimitive(PRIM_ASSIGN)) {
Symbol* lhs = toSymExpr(call->get(1))->symbol();
Expr* rhs = call->get(2);
if (lhs->getValType() == rhs->getValType()) // same type
return true;
} else if (call->isNamed("=")) {
Symbol* lhs = toSymExpr(call->get(1))->symbol();
Symbol* rhs = toSymExpr(call->get(2))->symbol();
if (lhs->getValType() == rhs->getValType()) // same type
Expand Down Expand Up @@ -872,16 +877,17 @@ static bool isOptimizableAssignStmt(Expr* stmt, BlockStmt* loop) {


static void transformAssignStmt(Expr* stmt) {
SET_LINENO(stmt);

CallExpr* call = toCallExpr(stmt);

INT_ASSERT(call->isPrimitive(PRIM_ASSIGN));

Symbol* lhs = toSymExpr(call->get(1))->symbol();
Symbol* rhs = toSymExpr(call->get(2))->symbol();

Expr* rhs = call->get(2);
CallExpr* callToRemove = NULL;

if (rhs->isRef() == false) {
if (isSymExpr(rhs) && rhs->isRef() == false) {
// Find a pattern like
//
// move rhs PRIM_DEREF rhsRef
Expand All @@ -892,13 +898,14 @@ static void transformAssignStmt(Expr* stmt) {
//
// PRIM_ASSIGN lhs rhsRef
//
Symbol* rhsSym = toSymExpr(rhs)->symbol();
Symbol* rhsRef = NULL;
CallExpr* prevCall = toCallExpr(call->prev);
if (prevCall != NULL) {
if (prevCall->isPrimitive(PRIM_MOVE) ||
prevCall->isPrimitive(PRIM_ASSIGN)) {
Symbol* prevLhs = toSymExpr(prevCall->get(1))->symbol();
if (prevLhs == rhs) {
if (prevLhs == rhsSym) {
if (CallExpr* rhsCall = toCallExpr(prevCall->get(2))) {
if (rhsCall->isPrimitive(PRIM_DEREF))
rhsRef = toSymExpr(rhsCall->get(1))->symbol();
Expand All @@ -912,20 +919,19 @@ static void transformAssignStmt(Expr* stmt) {

if (rhsRef != NULL && prevCall != NULL) {
callToRemove = prevCall;
rhs = rhsRef;
rhs = new SymExpr(rhsRef);
}
}

if (lhs->isRef() && rhs->isRef()) {
SET_LINENO(call);
// add the call to getput
if (fReportOptimizeForallUnordered) {
if (developer || printsUserLocation(call)) {
USR_PRINT(call, "Optimized assign to be unordered");
}
}

call->insertBefore(new CallExpr(PRIM_UNORDERED_ASSIGN, lhs, rhs));
call->insertBefore(new CallExpr(PRIM_UNORDERED_ASSIGN, lhs, rhs->copy()));
call->remove();
if (callToRemove)
callToRemove->remove();
Expand Down
3 changes: 3 additions & 0 deletions compiler/passes/InitNormalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,9 @@ Expr* InitNormalize::genericFieldInitTypeInference(Expr* insertBefore,
Expr* InitNormalize::fieldInitTypeWoutInit(Expr* insertBefore,
DefExpr* field) const {

if (field->sym->hasFlag(FLAG_NO_INIT))
return NULL;

SET_LINENO(insertBefore);

Type* type = field->sym->type;
Expand Down
2 changes: 1 addition & 1 deletion compiler/passes/buildDefaultFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1516,7 +1516,7 @@ static void buildUnionAssignmentFunction(AggregateType* ct) {
************************************** | *************************************/

static void checkNotPod(AggregateType* at) {
if (functionExists("chpl__initCopy", at) == NULL) {
if (functionExists(astr_initCopy, at) == NULL) {

if (at->hasUserDefinedInitEquals()) {
at->symbol->addFlag(FLAG_NOT_POD);
Expand Down
7 changes: 5 additions & 2 deletions compiler/passes/checkResolved.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,10 @@ checkBadAddrOf(CallExpr* call)

bool rhsType = rhs->symbol()->hasFlag(FLAG_TYPE_VARIABLE);
bool rhsParam = rhs->symbol()->isParameter();

bool rhsExprTemp = rhs->symbol()->hasFlag(FLAG_EXPR_TEMP) &&
!rhs->symbol()->type->symbol->hasFlag(FLAG_ARRAY);

// Also detect runtime type variables
if (rhs->symbol()->type->symbol->hasFlag(FLAG_RUNTIME_TYPE_VALUE))
rhsType = true;
Expand All @@ -521,8 +525,7 @@ checkBadAddrOf(CallExpr* call)
} else if (lhsRef && rhsParam) {
USR_FATAL_CONT(call, "Cannot set a reference to a param variable.");
} else if (lhsRef && !lhsConst) {
if (rhs->symbol()->hasFlag(FLAG_EXPR_TEMP) ||
rhs->symbol()->isConstant()) {
if (rhsExprTemp || rhs->symbol()->isConstant()) {
USR_FATAL_CONT(call, "Cannot set a non-const reference to a const variable.");
}
}
Expand Down
30 changes: 28 additions & 2 deletions compiler/passes/initializerRules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,30 @@ static bool isSymbolThis(Expr* expr) {
return retval;
}

// returns true if there is a postinit defined on the type
// and in that event adds FLAG_HAS_POSTINIT to the type symbol
static bool findPostinitAndMark(AggregateType* at) {
bool retval = false;

// If there is postinit() it is defined on the defining type
if (at->instantiatedFrom == NULL) {
int size = at->methods.n;

for (int i = 0; i < size && retval == false; i++) {
if (at->methods.v[i] != NULL)
retval = at->methods.v[i]->isPostInitializer();
}

} else {
retval = findPostinitAndMark(at->instantiatedFrom);
}

if (retval)
at->symbol->addFlag(FLAG_HAS_POSTINIT);

return retval;
}

//
// Builds the list of AggregateTypes in the hierarchy of `at` that have or
// require a postinit.
Expand All @@ -1156,14 +1180,14 @@ static bool buildPostInitChain(AggregateType* at,
if (at == dtObject) {
ret = false;
} else if (at->isRecord()) {
if (at->hasPostInitializer()) {
if (findPostinitAndMark(at)) {
chain.push_back(at);
ret = true;
}
} else if (parent != NULL && buildPostInitChain(parent, chain) == true) {
ret = true;
chain.push_back(at);
} else if (at->hasPostInitializer()) {
} else if (findPostinitAndMark(at)) {
ret = true;
chain.push_back(at);
}
Expand Down Expand Up @@ -1415,6 +1439,8 @@ static int insertPostInit(AggregateType* at, bool insertSuper) {
buildPostInit(at);
}

at->symbol->addFlag(FLAG_HAS_POSTINIT);

return ret;
}

Expand Down
Loading