Skip to content

Add support for noinit remote variables. #27074

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

Merged
merged 9 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 13 additions & 4 deletions compiler/passes/convert-uast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2298,7 +2298,7 @@ struct Converter final : UastConverter {
// Field multi-decl desugaring happens later in build.cpp and produces
// different code; don't do redundant work here.
bool isField = parsing::idIsField(context, node->id());
if (!isField) {
if (isField) {
// post-parse checks should rule this out
CHPL_ASSERT(!node->destination());
}
Expand Down Expand Up @@ -3523,13 +3523,16 @@ struct Converter final : UastConverter {
if (auto prevInitExpr = multiState->prevInitExpr) {
Expr* replaceWith;
if (prevInitExpr->isNoInitExpr()) {
replaceWith = prevInitExpr->copy();
// for remote variables, don't bother trying to replace 'noinit',
// since we already threw it away and selected a different overload of
// buildRemoteWrapper.
replaceWith = isRemote ? nullptr : prevInitExpr->copy();
} else if (typeExpr) {
replaceWith = new CallExpr("chpl__readXX", new SymExpr(varSym));
} else {
replaceWith = new SymExpr(varSym);
}
multiState->replaceInitExpr(replaceWith);
if (replaceWith) multiState->replaceInitExpr(replaceWith);
initExpr = prevInitExpr;
}

Expand All @@ -3551,7 +3554,13 @@ struct Converter final : UastConverter {
wrapperCall->insertAtTail(destinationExpr ? destinationExpr : new SymExpr(multiState->localeTemp));

if (typeExpr) wrapperCall->insertAtTail(typeExpr);
if (initExpr) wrapperCall->insertAtTail(new CallExpr(PRIM_CREATE_THUNK, initExpr));
if (initExpr) {
if (initExpr->isNoInitExpr()) {
wrapperCall->insertAtTail(new SymExpr(dtVoid->symbol));
} else {
wrapperCall->insertAtTail(new CallExpr(PRIM_CREATE_THUNK, initExpr));
}
}
auto wrapperDef = new DefExpr(wrapper, wrapperCall);

auto wrapperGet = new CallExpr(".", new SymExpr(wrapper), new_CStringSymbol("get"));
Expand Down
15 changes: 15 additions & 0 deletions modules/internal/ChapelRemoteVars.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ module ChapelRemoteVars {

class _remoteVarContainer {
var containedValue;

proc type _noinit(type containedValueType) {
var tmp: containedValueType = noinit;
return new _remoteVarContainer(tmp);
}
}

record _remoteVarWrapper {
Expand Down Expand Up @@ -78,6 +83,16 @@ module ChapelRemoteVars {
return new _remoteVarWrapper(try! c : owned _remoteVarContainer(inType));
}

@unstable("remote variables are unstable")
inline proc chpl__buildRemoteWrapper(const ref loc, type inType, type noinitMarker) where noinitMarker == void {
// This is a special case to create a noinit remote variable.
// We use a specific overload of the _remoteVarContainer constructor
// which accepts a type and uses noinit.
var c: owned _remoteVarContainer(inType)?;
on loc do c = _remoteVarContainer._noinit(inType);
return new _remoteVarWrapper(try! c : owned _remoteVarContainer(inType));
}

@unstable("remote variables are unstable")
inline proc chpl__buildRemoteWrapper(const ref loc, type inType, in tr: _thunkRecord) {
var c: owned _remoteVarContainer(inType)?;
Expand Down
15 changes: 15 additions & 0 deletions test/variables/remote/noinit-vars.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
record R {
proc init() {
writeln("R.init");
}
}

writeln("yesinit");
on Locales[0] var A: [0..0] R;
writeln("noinit");
on Locales[0] var B: [0..0] R = noinit;

writeln("yesinit");
on Locales[0] var C, D: [0..0] R;
writeln("noinit");
on Locales[0] var E, F: [0..0] R = noinit;
7 changes: 7 additions & 0 deletions test/variables/remote/noinit-vars.good
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
yesinit
R.init
noinit
yesinit
R.init
R.init
noinit