Skip to content

Commit

Permalink
Merge pull request chapel-lang#5328 from vasslitvinov/switch-to-deinit()
Browse files Browse the repository at this point in the history
Switched to using deinit()

This is a follow-up to chapel-lang#5299.

* Added a compiler warning that "~classname" names for deinitializers
  are deprecated.

  The warning is currently commented out. As before this change,
  users can use either name ("deinit" or "~classname") without warnings.

  We will enact the "~classname" warning for deinitializers when we do
  the same for "classname"-named initializers.

* Switched from ~classname() to deinit() in our Chapel code base:
  modules, tests, spec.
  Left "~R" naming in printouts, to reduce the volume of changes.

* Added a test that specifically tests ~classname() naming.

* Renamed "destructors" to "deinitializers" throughout the spec.

These changes are trivial, except for these non-trivial pieces:

* Changed the spec text in that the destructor is called "deinit",
not "~classname".

* In learnChapelInYMinutes(), I also adjusted the comments on the constructor
and destructor. Switched to "initializer" and "deinitializer" words
proactively. Promised compiler-generated initializer according to the current
world for constructors, and warned that it is going away soon.
There is still "constructor" usage there that we need to change.

* Left the old "~classname" naming in these tests:

    // to test "destructor name must match class/record name" warning
    classes/figueroa/BogusDestructors5
    classes/figueroa/BogusDestructors7

    // these test scanning or pasing "~"
    classes/diten/deleteDollar
    classes/diten/test_destroy2

    // tests both new and old syntax
    classes/deinitializers/deinitAndDestruct

r: @lydia-duncan
  • Loading branch information
vasslitvinov authored Feb 9, 2017
2 parents 87f0957 + b9bd9aa commit 73eed64
Show file tree
Hide file tree
Showing 134 changed files with 268 additions and 218 deletions.
6 changes: 6 additions & 0 deletions compiler/passes/checkParsed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ checkFunction(FnSymbol* fn) {
USR_FATAL_CONT(fn, "'this' intents can only be applied to methods");
}

#if 0 // Do not issue the warning yet.
if (fn->hasFlag(FLAG_DESTRUCTOR) && (fn->name[0] == '~')) {
USR_WARN(fn, "\"~classname\" naming of deinitializers is deprecated");
}
#endif

std::vector<CallExpr*> calls;
collectMyCallExprs(fn, calls, fn);
bool isIterator = fn->isIterator();
Expand Down
22 changes: 11 additions & 11 deletions modules/internal/Atomics.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ module Atomics {
var _v:atomic_bool = create_atomic_bool();

pragma "no doc"
inline proc ~atomicbool() {
inline proc deinit() {
atomic_destroy_bool(_v);
}

Expand Down Expand Up @@ -428,7 +428,7 @@ module Atomics {
pragma "no doc"
record atomic_uint8 {
var _v:atomic_uint_least8_t = create_atomic_uint_least8();
inline proc ~atomic_uint8() {
inline proc deinit() {
atomic_destroy_uint_least8_t(_v);
}
inline proc read(order:memory_order = memory_order_seq_cst):uint(8) {
Expand Down Expand Up @@ -531,7 +531,7 @@ module Atomics {
pragma "no doc"
record atomic_uint16 {
var _v:atomic_uint_least16_t = create_atomic_uint_least16();
inline proc ~atomic_uint16() {
inline proc deinit() {
atomic_destroy_uint_least16_t(_v);
}
inline proc read(order:memory_order = memory_order_seq_cst):uint(16) {
Expand Down Expand Up @@ -634,7 +634,7 @@ module Atomics {
pragma "no doc"
record atomic_uint32 {
var _v:atomic_uint_least32_t = create_atomic_uint_least32();
inline proc ~atomic_uint32() {
inline proc deinit() {
atomic_destroy_uint_least32_t(_v);
}
inline proc read(order:memory_order = memory_order_seq_cst):uint(32) {
Expand Down Expand Up @@ -737,7 +737,7 @@ module Atomics {
pragma "no doc"
record atomic_uint64 {
var _v:atomic_uint_least64_t = create_atomic_uint_least64();
inline proc ~atomic_uint64() {
inline proc deinit() {
atomic_destroy_uint_least64_t(_v);
}
inline proc read(order:memory_order = memory_order_seq_cst):uint(64) {
Expand Down Expand Up @@ -840,7 +840,7 @@ module Atomics {
pragma "no doc"
record atomic_int8 {
var _v:atomic_int_least8_t = create_atomic_int_least8();
inline proc ~atomic_int8() {
inline proc deinit() {
atomic_destroy_int_least8_t(_v);
}
inline proc read(order:memory_order = memory_order_seq_cst):int(8) {
Expand Down Expand Up @@ -943,7 +943,7 @@ module Atomics {
pragma "no doc"
record atomic_int16 {
var _v:atomic_int_least16_t = create_atomic_int_least16();
inline proc ~atomic_int16() {
inline proc deinit() {
atomic_destroy_int_least16_t(_v);
}
inline proc read(order:memory_order = memory_order_seq_cst):int(16) {
Expand Down Expand Up @@ -1046,7 +1046,7 @@ module Atomics {
pragma "no doc"
record atomic_int32 {
var _v:atomic_int_least32_t = create_atomic_int_least32();
inline proc ~atomic_int32() {
inline proc deinit() {
atomic_destroy_int_least32_t(_v);
}
inline proc read(order:memory_order = memory_order_seq_cst):int(32) {
Expand Down Expand Up @@ -1150,7 +1150,7 @@ module Atomics {
var _v:atomic_int_least64_t = create_atomic_int_least64();

pragma "no doc"
inline proc ~atomic_int64() {
inline proc deinit() {
atomic_destroy_int_least64_t(_v);
}

Expand Down Expand Up @@ -1363,7 +1363,7 @@ module Atomics {
pragma "no doc"
record atomic_real64 {
var _v:atomic__real64 = create_atomic__real64();
inline proc ~atomic_real64() {
inline proc deinit() {
atomic_destroy__real64(_v);
}
inline proc read(order:memory_order = memory_order_seq_cst):real(64) {
Expand Down Expand Up @@ -1443,7 +1443,7 @@ module Atomics {
pragma "no doc"
record atomic_real32 {
var _v:atomic__real32 = create_atomic__real32();
inline proc ~atomic_real32() {
inline proc deinit() {
atomic_destroy__real32(_v);
}
inline proc read(order:memory_order = memory_order_seq_cst):real(32) {
Expand Down
6 changes: 3 additions & 3 deletions modules/internal/ChapelArray.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ module ChapelArray {
}
}

proc ~_distribution() {
proc deinit() {
_do_destroy();
}

Expand Down Expand Up @@ -927,7 +927,7 @@ module ChapelArray {
}
}
}
proc ~_domain () {
proc deinit () {
_do_destroy();
}

Expand Down Expand Up @@ -1889,7 +1889,7 @@ module ChapelArray {
}
}

proc ~_array() {
proc deinit() {
_do_destroy();
}

Expand Down
20 changes: 10 additions & 10 deletions modules/internal/ChapelDistribution.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module ChapelDistribution {
// has been destroyed
var pid:int = nullPid; // privatized ID, if privatization is supported

proc ~BaseDist() {
proc deinit() {
}

// Returns a distribution that should be freed or nil.
Expand Down Expand Up @@ -167,7 +167,7 @@ module ChapelDistribution {
var _free_when_no_arrs: bool;
var pid:int = nullPid; // privatized ID, if privatization is supported

proc ~BaseDom() {
proc deinit() {
}

proc dsiMyDist(): BaseDist {
Expand Down Expand Up @@ -313,7 +313,7 @@ module ChapelDistribution {
}

class BaseRectangularDom : BaseDom {
proc ~BaseRectangularDom() {
proc deinit() {
// this is a bug workaround
}

Expand All @@ -336,7 +336,7 @@ module ChapelDistribution {

var nnzDom = {1..nnz};

proc ~BaseSparseDomImpl() {
proc deinit() {
// this is a bug workaround
}

Expand Down Expand Up @@ -465,7 +465,7 @@ module ChapelDistribution {

var nnz = 0; //: int;

proc ~BaseSparseDom() {
proc deinit() {
// this is a bug workaround
}

Expand Down Expand Up @@ -545,7 +545,7 @@ module ChapelDistribution {
// end BaseSparseDom operators

class BaseAssociativeDom : BaseDom {
proc ~BaseAssociativeDom() {
proc deinit() {
// this is a bug workaround
}

Expand All @@ -561,7 +561,7 @@ module ChapelDistribution {
}

class BaseOpaqueDom : BaseDom {
proc ~BaseOpaqueDom() {
proc deinit() {
// this is a bug workaround
}

Expand All @@ -582,7 +582,7 @@ module ChapelDistribution {
var _arrAlias: BaseArr; // reference to base array if an alias
var pid:int = nullPid; // privatized ID, if privatization is supported

proc ~BaseArr() {
proc deinit() {
}

proc dsiStaticFastFollowCheck(type leadType) param return false;
Expand Down Expand Up @@ -703,7 +703,7 @@ module ChapelDistribution {

proc dsiGetBaseDom() return dom;

proc ~BaseSparseArr() {
proc deinit() {
// this is a bug workaround
}
}
Expand All @@ -714,7 +714,7 @@ module ChapelDistribution {
*/
class BaseSparseArrImpl: BaseSparseArr {

proc ~BaseSparseArrImpl() {
proc deinit() {
// this is a bug workaround
}

Expand Down
10 changes: 5 additions & 5 deletions modules/internal/ChapelSyncvar.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ module ChapelSyncvar {
isOwned = false;
}

proc ~_syncvar() {
proc deinit() {
if isOwned == true then
delete wrapped;
}
Expand Down Expand Up @@ -347,7 +347,7 @@ module ChapelSyncvar {
chpl_sync_initAux(syncAux);
}

proc ~_synccls() {
proc deinit() {
chpl_sync_destroyAux(syncAux);
}

Expand Down Expand Up @@ -484,7 +484,7 @@ module ChapelSyncvar {
qthread_purge_to(alignedValue, defaultOfAlignedT(valType));
}

proc ~_qthreads_synccls() {
proc deinit() {
// There's no explicit destroy function, but qthreads reclaims memory
// for full variables that have no pending operations
qthread_fill(alignedValue);
Expand Down Expand Up @@ -625,7 +625,7 @@ module ChapelSyncvar {
isOwned = false;
}

proc ~_singlevar() {
proc deinit() {
if isOwned == true then
delete wrapped;
}
Expand Down Expand Up @@ -748,7 +748,7 @@ module ChapelSyncvar {
chpl_single_initAux(singleAux);
}

proc ~_singlecls() {
proc deinit() {
chpl_single_destroyAux(singleAux);
}

Expand Down
4 changes: 2 additions & 2 deletions modules/internal/DefaultOpaque.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ module DefaultOpaque {
adomain = new DefaultAssociativeDom(_OpaqueIndex, dist, parSafe=parSafe);
}

proc ~DefaultOpaqueDom() {
proc deinit() {
delete adomain;
}

Expand Down Expand Up @@ -151,7 +151,7 @@ module DefaultOpaque {
var anarray = new DefaultAssociativeArr(eltType=eltType, idxType=idxType,
parSafeDom=parSafe, dom=dom.adomain);

proc ~DefaultOpaqueArr() {
proc deinit() {
delete anarray;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/internal/DefaultRectangular.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ module DefaultRectangular {
targetLocDom=newTargetLocDom;
}

proc ~LocRADCache() {
proc deinit() {
if !defRectSimpleDData {
for rad in RAD {
if rad.mData != nil then
Expand Down
2 changes: 1 addition & 1 deletion modules/internal/String.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ module String {
}

pragma "no doc"
proc ref ~string() {
proc ref deinit() {
if owned && !this.isEmptyString() {
on __primitive("chpl_on_locale_num",
chpl_buildLocaleID(this.locale_id, c_sublocid_any)) {
Expand Down
2 changes: 1 addition & 1 deletion modules/packages/Futures.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ module Futures {
}

pragma "no doc"
proc ~Future() {
proc deinit() {
release();
}

Expand Down
2 changes: 1 addition & 1 deletion modules/packages/MPI.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ module MPI {
var freeChplComm : bool = false;

pragma "no doc"
proc ~_initMPI() {
proc deinit() {
if freeChplComm {
if numLocales > 1 {
coforall loc in Locales do on loc {
Expand Down
4 changes: 2 additions & 2 deletions modules/packages/MatrixMarket.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ module MatrixMarket {
}

proc close() { fout.close(); fd.close(); }
proc ~MMWriter() { this.close(); }
proc deinit() { this.close(); }
}

proc mmwrite(const fname:string, mat:[?Dmat] ?T) where mat.domain.rank == 2 {
Expand Down Expand Up @@ -385,7 +385,7 @@ class MMReader {
fd.close();
}

proc ~MMReader() { this.close(); }
proc deinit() { this.close(); }
}

/* Read a dense Matrix Market file
Expand Down
8 changes: 4 additions & 4 deletions modules/packages/ZMQ.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ module ZMQ {
}
}

proc ~ContextClass() {
proc deinit() {
on this.home {
var ret = zmq_ctx_term(this.ctx):int;
if ret == -1 {
Expand Down Expand Up @@ -450,7 +450,7 @@ module ZMQ {
}

pragma "no doc"
proc ~Context() {
proc deinit() {
release();
}

Expand Down Expand Up @@ -523,7 +523,7 @@ module ZMQ {
}
}

proc ~SocketClass() {
proc deinit() {
on this.home {
var ret = zmq_close(socket):int;
if ret == -1 {
Expand Down Expand Up @@ -559,7 +559,7 @@ module ZMQ {
}

pragma "no doc"
proc ~Socket() {
proc deinit() {
release();
}

Expand Down
2 changes: 1 addition & 1 deletion modules/standard/Barrier.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ module Barrier {
}

pragma "no doc"
proc ~Barrier() {
proc deinit() {
if owned && bar != nil {
delete bar;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/standard/BigInteger.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ module BigInteger {
// copy. The localeId points back the correct locale but the mpz field
// is meaningless.
pragma "no doc"
proc ~bigint() {
proc deinit() {
if _local || this.localeId == chpl_nodeID {
mpz_clear(this.mpz);
}
Expand Down
Loading

0 comments on commit 73eed64

Please sign in to comment.