forked from chapel-lang/chapel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable split init for sync blocks (chapel-lang#23314)
Closes Cray/chapel-private#5375 Closes chapel-lang#20974 This PR enables split init of a variable across a `sync` block. (Note: sync blocks are typically used with `begin` and split init is still not allowed across a `begin`). Copy elision was already allowed across `sync` blocks. Additionally, this PR * adjusts the language specification to indicate split init and copy elision are allowed across `sync` blocks themselves * adds two tests to lock in split init and copy elision with `sync` blocks Reviewed by @DanilaFe - thanks! - [x] full comm=none testing
- Loading branch information
Showing
6 changed files
with
137 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
class C { } | ||
record R { | ||
var x: int = 0; | ||
var ptr: owned C = new owned C(); | ||
proc init() { | ||
this.x = 0; | ||
writeln("init"); | ||
} | ||
proc init(arg:int) { | ||
this.x = arg; | ||
writeln("init ", arg); | ||
} | ||
proc init=(other: R) { | ||
this.x = other.x; | ||
writeln("init= ", other.x); | ||
} | ||
} | ||
operator R.=(ref lhs:R, rhs:R) { | ||
writeln("= ", lhs.x, " ", rhs.x); | ||
lhs.x = rhs.x; | ||
} | ||
|
||
|
||
proc syncSplitInit() { | ||
writeln("syncSplitInit"); | ||
var x: R; | ||
|
||
sync { | ||
x = new R(1); // split init applies to sync blocks | ||
} | ||
} | ||
syncSplitInit(); | ||
|
||
proc fOut(out arg: R) { | ||
arg = new R(2); | ||
} | ||
|
||
proc syncSplitInitOut() { | ||
writeln("syncSplitInitOut"); | ||
var x: R; | ||
|
||
sync { | ||
fOut(x); | ||
} | ||
} | ||
syncSplitInitOut(); | ||
|
||
|
||
proc syncCopyElide() { | ||
writeln("syncCopyElide"); | ||
var x = new R(1); | ||
|
||
sync { | ||
var y = x; // copy elision applies to sync blocks | ||
} | ||
} | ||
syncCopyElide(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
syncSplitInit | ||
init 1 | ||
syncSplitInitOut | ||
init 2 | ||
syncCopyElide | ||
init 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
config const cond = false; | ||
config const otherCond = true; | ||
|
||
class C { } | ||
record R { | ||
var x: int = 0; | ||
var ptr: owned C = new owned C(); | ||
proc init() { | ||
this.x = 0; | ||
writeln("init"); | ||
} | ||
proc init(arg:int) { | ||
this.x = arg; | ||
writeln("init ", arg); | ||
} | ||
proc init=(other: R) { | ||
this.x = other.x; | ||
writeln("init= ", other.x); | ||
} | ||
} | ||
operator R.=(ref lhs:R, rhs:R) { | ||
writeln("= ", lhs.x, " ", rhs.x); | ||
lhs.x = rhs.x; | ||
} | ||
|
||
proc test100() { | ||
writeln("test100"); | ||
var b; | ||
sync { | ||
b = new R(1); | ||
} | ||
writeln(b); | ||
} | ||
test100(); | ||
|
||
proc test101() { | ||
writeln("test101"); | ||
var b: R; | ||
sync { | ||
b = new R(1); | ||
} | ||
writeln(b); | ||
} | ||
test101(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
test100 | ||
init 1 | ||
(x = 1, ptr = {}) | ||
test101 | ||
init 1 | ||
(x = 1, ptr = {}) |