Skip to content

Commit

Permalink
Merge branch 'main' into runtime-no-filename-max
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Rift <[email protected]>
  • Loading branch information
riftEmber committed Dec 21, 2024
2 parents 2ed21a3 + 2cfd1a2 commit aa5b506
Show file tree
Hide file tree
Showing 77 changed files with 547 additions and 108 deletions.
9 changes: 9 additions & 0 deletions compiler/AST/AggregateType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ AggregateType::AggregateType(AggregateTag initTag) :
mIsGenericWithDefaults = false;
mIsGenericWithSomeDefaults = false;
foundGenericFields = false;
postinit = nullptr;

typeSignature = NULL;


Expand Down Expand Up @@ -132,6 +134,7 @@ AggregateType* AggregateType::copyInner(SymbolMap* map) {
}

copy_type->genericField = genericField;
copy_type->postinit = postinit;

return copy_type;
}
Expand Down Expand Up @@ -234,6 +237,12 @@ void AggregateType::verify() {
INT_FATAL(this, "Substitution value not in tree");
}
}

// Should we just change all checks of this flag to a check against
// postinit being non-nullptr? Or a nice method query?
if ((postinit != nullptr) != this->symbol->hasFlag(FLAG_HAS_POSTINIT)) {
INT_FATAL(this, "postinit state is inconsistent");
}
}

int AggregateType::numFields() const {
Expand Down
3 changes: 3 additions & 0 deletions compiler/include/AggregateType.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ class AggregateType final : public Type {
// A list of the generic fields in this type.
std::vector<Symbol*> genericFields;

// pointer to postinit() method, if defined
FnSymbol* postinit;

private:

// Only used for LLVM.
Expand Down
26 changes: 21 additions & 5 deletions compiler/passes/initializerRules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1186,8 +1186,13 @@ static bool findPostinitAndMark(AggregateType* at) {
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();
FnSymbol* methodi = at->methods.v[i];
if (methodi != nullptr && methodi->isPostInitializer()) {
// capture the post-initializer upon finding it
at->postinit = methodi;
retval = true;
break;
}
}

} else {
Expand Down Expand Up @@ -1443,10 +1448,23 @@ static void buildPostInit(AggregateType* at) {
fn->addFlag(FLAG_METHOD_PRIMARY);

if (at->isClass()) {
// If our parent class's postinit() is throwing, ours needs to be as well
forv_Vec(AggregateType, pt, at->dispatchParents) {
if (pt->hasPostInitializer()) {
if (pt->postinit->throwsError()) {
fn->throwsErrorInit();
break;
}
}
}

// Insert call to parent class postinit()
insertSuperPostInit(fn);
}

at->methods.add(fn);

at->postinit = fn;
}

//
Expand All @@ -1465,11 +1483,9 @@ static int insertPostInit(AggregateType* at, bool insertSuper) {
if (method == nullptr) continue;

if (method->isPostInitializer()) {
if (method->throwsError() == true) {
USR_FATAL_CONT(method, "postinit cannot be declared as throws yet");
}
if (method->where == NULL) {
found = true;
at->postinit = method;
}
if (method->formals.length > 2) {
// Only accept method token and 'this'
Expand Down
5 changes: 4 additions & 1 deletion compiler/resolution/initializerResolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ static FnSymbol* buildNewWrapper(FnSymbol* initFn, Expr* allocator = nullptr) {
}
}

if (initFn->throwsError()) {
// If either the initializer throws, or the postinit throws, make
// this function representing the 'new' throw as well
if (initFn->throwsError() ||
(type->hasPostInitializer() && type->postinit->throwsError())) {
fn->throwsErrorInit();
BlockStmt* tryBody = new BlockStmt(innerInit);

Expand Down
3 changes: 2 additions & 1 deletion compiler/resolution/virtualDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,8 @@ static void resolveOverrideAndAdjustMaps(FnSymbol* pfn, FnSymbol* cfn) {

if (signaturesMatch(pfn, cfn) &&
evaluateWhereClause(cfn) &&
evaluateWhereClause(pfn)) {
evaluateWhereClause(pfn) &&
!pfn->isPostInitializer()) { // postinits don't override

resolveSpecifiedReturnType(cfn);
resolveFunction(cfn);
Expand Down
14 changes: 7 additions & 7 deletions doc/rst/technotes/throwingInit.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ before the error is thrown back to the caller.
proc init(xVal: int) throws {
x = xVal;
this.complete();
init this;
validate(this);
}
}
Expand All @@ -115,17 +115,17 @@ Calling Throwing Functions
~~~~~~~~~~~~~~~~~~~~~~~~~~

When an initializer is declared with the ``throws`` keyword, calls to throwing
functions may be made in the body of the initializer after ``this.complete()``
functions may be made in the body of the initializer after ``init this``
(see :ref:`Limitations_on_Instance_Usage_in_Initializers` for information on
``this.complete()`` and the example in :ref:`init_declaring_init_as_throws`).
``init this`` and the example in :ref:`init_declaring_init_as_throws`).
As a result, thrown errors will be propagated outside of the initializer. The
memory that would have been used to store the instance created by the
initializer will be cleaned up prior to propagating the error.

.. note::

Calls to throwing functions are not currently allowed prior to
``this.complete()``.
``init this``.

When an initializer is not declared with the ``throws`` keyword, calls to
throwing functions may be made anywhere in the body of the initializer. Such
Expand All @@ -141,7 +141,7 @@ include:
- being able to ``throw`` from anywhere in the body of an initializer
- being able to write ``try`` / ``try!`` with ``catch`` blocks anywhere in the
body of an initializer
- being able to call functions that ``throw`` prior to ``this.complete()``
- being able to call functions that ``throw`` prior to ``init this``
(see :ref:`Limitations_on_Instance_Usage_in_Initializers` for a description)
- including ``super.init`` calls when the parent initializer throws, e.g.,

Expand All @@ -152,7 +152,7 @@ include:
proc init(xVal: int) throws {
x = xVal;
this.complete();
init this;
someThrowingFunc(this);
}
}
Expand All @@ -163,6 +163,6 @@ include:
proc init(xVal: int, yVal: bool) throws {
super.init(xVal); // This call is not valid today
y = yVal;
this.complete();
init this;
}
}
1 change: 1 addition & 0 deletions doc/rst/usingchapel/multilocale.rst
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ smp fast
other everything
=================== ====================

.. _readme-colocale:

Co-locales
++++++++++
Expand Down
19 changes: 19 additions & 0 deletions modules/internal/ChapelLocale.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,23 @@ module ChapelLocale {
*/
inline proc locale.maxTaskPar: int { return this._value.maxTaskPar; }

/*
Get the number of co-locales on the locale's node, inclusive.
Note that this may not be equal to the number of locales on the node due
to oversubscription. The value is one in the typical case in which there
is only one locale per node. For example, if a job is launched with ``-nl
2`` then ``numColocales`` will be one, and if it is launched with ``-nl
1x2`` ``numColocales`` will be two.
More information about co-locales can be found here: :ref:`readme-colocale`
:returns: the number of co-locales on the locale's node
:rtype: int
*/
@unstable("'locale.numColocales' is unstable")
inline proc locale.numColocales: int { return this._value.numColocales; }

// the following are normally taken care of by `forwarding`. However, they
// don't work if they are called in a promoted expression. See 15148

Expand Down Expand Up @@ -326,6 +343,8 @@ module ChapelLocale {

var maxTaskPar: int;

var numColocales: int;

proc id : int do return chpl_nodeFromLocaleID(__primitive("_wide_get_locale", this));

@chpldoc.nodoc
Expand Down
6 changes: 6 additions & 0 deletions modules/internal/LocaleModelHelpSetup.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ module LocaleModelHelpSetup {

extern proc chpl_task_getMaxPar(): uint(32);
dst.maxTaskPar = chpl_task_getMaxPar();

extern proc chpl_get_num_colocales_on_node(): c_int;
dst.numColocales = chpl_get_num_colocales_on_node();
}

proc helpSetupLocaleNUMA(dst:borrowed LocaleModel, out local_name:string, numSublocales, type NumaDomain) {
Expand Down Expand Up @@ -219,6 +222,9 @@ module LocaleModelHelpSetup {
extern proc chpl_task_getMaxPar(): uint(32);
dst.maxTaskPar = chpl_task_getMaxPar();

extern proc chpl_get_num_colocales_on_node(): c_int;
dst.numColocales = chpl_get_num_colocales_on_node();

var childSpace = {0..#numSublocales};

const origSubloc = chpl_task_getRequestedSubloc();
Expand Down
1 change: 1 addition & 0 deletions modules/internal/localeModels/flat/LocaleModel.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ module LocaleModel {
nPUsLogAcc = 0;
nPUsLogAll = 0;
maxTaskPar = 0;
numColocales = 0;
}

// The setup() function must use chpl_initOnLocales() to iterate (in
Expand Down
1 change: 1 addition & 0 deletions modules/internal/localeModels/gpu/LocaleModel.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ module LocaleModel {
nPUsLogAcc = 0;
nPUsLogAll = 0;
maxTaskPar = 0;
numColocales = 0;
}

// The setup() function must use chpl_initOnLocales() to iterate (in
Expand Down
2 changes: 1 addition & 1 deletion modules/packages/DistributedBag.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ module DistributedBag
{
this.eltType = eltType;
this.parentHandle = parentHandle;
// KNOWN ISSUE: 'this.complete' produces an error when 'eltType' is a Chapel
// KNOWN ISSUE: 'init this' produces an error when 'eltType' is a Chapel
// array (see Github issue #19859).
}

Expand Down
6 changes: 6 additions & 0 deletions runtime/include/chpl-comm.h
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,12 @@ void chpl_set_local_rank(int32_t rank);
// not been called.
int32_t chpl_get_local_rank(void);

// Sets the number of colocales on the local node.
void chpl_set_num_colocales_on_node(int32_t count);

// Returns the number of colocales on the local node.
int32_t chpl_get_num_colocales_on_node(void);

#ifdef __cplusplus
}
#endif
Expand Down
12 changes: 12 additions & 0 deletions runtime/src/chpl-comm.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ int32_t chpl_nodeID = -1;
int32_t chpl_numNodes = -1;
static int32_t numLocalesOnNode = -1;
static int32_t localRank = -1;
static int32_t numColocalesOnNode = 1;


//
Expand Down Expand Up @@ -269,3 +270,14 @@ int32_t chpl_get_local_rank(void) {
return localRank;
}

void chpl_set_num_colocales_on_node(int32_t count) {
if (count <= 0) {
chpl_internal_error_v("count (%d) must be > 0", count);
}
numColocalesOnNode = count;
}

int32_t chpl_get_num_colocales_on_node(void) {
return numColocalesOnNode;
}

13 changes: 11 additions & 2 deletions runtime/src/topo/hwloc/topo-hwloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,17 @@ static void partitionResources(void) {
if (numLocalesOnNode > 1) {
oversubscribed = true;
}
if ((numColocales > 0) && (numLocalesOnNode <= numColocales)){
numPartitions = numColocales;
if (numColocales > 0) {
if (numLocalesOnNode <= numColocales) {
// There are fewer colocales than there should be, probably because the
// number of locales isn't evenly divisable by the number of nodes.
// Partition resources as if there are the full complement of
// colocales, but set the number of colocales to the actual number.
numPartitions = numColocales;
chpl_set_num_colocales_on_node(numLocalesOnNode);
} else {
chpl_set_num_colocales_on_node(numColocales);
}
}
logAccSets = sys_calloc(numPartitions, sizeof(hwloc_cpuset_t));
if ((numColocales > 0) && (numLocalesOnNode > numColocales)) {
Expand Down
4 changes: 4 additions & 0 deletions test/ANNOTATIONS.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,8 @@ listBenchmark1:
- Reduce uses of Math by automatically included modules (#19885)
06/07/22:
- Fix performance of list benchmark by making these helpers inlined (#19947)
12/12/24:
- Remove check on 'log' input with --no-checks (#26368)

lulesh:
03/15/14:
Expand Down Expand Up @@ -1941,6 +1943,8 @@ revcomp: &revcomp-base
- Deprecate 'iokind' type and 'kind' field (#23007)
08/30/23:
- Improve performance of readBinary and writeBinary for dense arrays (#23162)
12/12/24:
- Remove check on 'log' input with --no-checks (#26368)

revcomp-submitted:
06/07/22:
Expand Down
2 changes: 2 additions & 0 deletions test/chplenv/printchplbuilds/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
These tests check that `$CHPL_HOME/util/chplenv/printchplbuilds.py` continues
to work properly.
5 changes: 5 additions & 0 deletions test/chplenv/printchplbuilds/printchplbuilds-check.prediff
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/usr/bin/env python3

"""
Ensure that `printchplbuilds --check` works as expected and has a return code of 0.
`--check` makes sure the current config matches a built runtime.
"""

import sys
import os
import subprocess as sp
Expand Down
8 changes: 7 additions & 1 deletion test/chplenv/printchplbuilds/printchplbuilds-print1.prediff
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/usr/bin/env python3

"""
Ensure that `printchplbuilds` reports the current build the same as `printchplenv`.
This test defines what variables should be in the `printchplbuilds` output
and then runs `printchplenv` to get the values.
"""

import sys
import os
import subprocess as sp
Expand Down Expand Up @@ -43,7 +49,7 @@ chpl_vars = [
("CHPL_TASKS", None),
("CHPL_TIMERS", None),
("CHPL_UNWIND", None),
("CHPL_MEM", None),
("CHPL_TARGET_MEM", None),
("CHPL_ATOMICS", None),
("CHPL_HWLOC", None),
("CHPL_HWLOC_PCI", None, lambda env: env["CHPL_HWLOC"] == "bundled"),
Expand Down
4 changes: 4 additions & 0 deletions test/chplenv/printchplbuilds/printchplbuilds.prediff
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env python3

"""
Ensure that a plain invocation of `printchplbuilds` works as expected and has a return code of 0.
"""

import sys
import os
import subprocess as sp
Expand Down
4 changes: 4 additions & 0 deletions test/classes/initializers/errors/errHandling/deinitFields.bad
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
In C's init
In R's init
Caught error
Past creation of myC
Loading

0 comments on commit aa5b506

Please sign in to comment.