Skip to content

Commit

Permalink
Mark some Reflection procedures as unstable (#22799)
Browse files Browse the repository at this point in the history
Mark some `Reflection` procedures as unstable after module review.
One routine `numFields` has been deprecated in favor of a
replacement named `getNumFields()`.

Refer to: Cray/chapel-private#5022

The `Reflection` procedures marked unstable by this PR are:

- `isFieldBound`
- `getFieldRef`
- `canResolve`
- `canResolveMethod`
- `canResolveTypeMethod`

While here, I adjusted the prediff for `TestWarnUnstableSuppression`
so that any symbols mentioned besides the special symbols used
for this test are filtered out of the output.

TESTING

- [x] `linux64`, `standard`

Reviewed by @vasslitvinov. Thanks!
  • Loading branch information
dlongnecke-cray authored Jul 28, 2023
2 parents ab3354c + 65bb01d commit 2dcdd4b
Show file tree
Hide file tree
Showing 31 changed files with 137 additions and 542 deletions.
2 changes: 1 addition & 1 deletion modules/packages/RecordParser.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class RecordReader {
/* The regular expression to read (using match on the channel) */
var matchRegex: regex(string);
@chpldoc.nodoc
param num_fields = numFields(t); // Number of fields in record
param num_fields = getNumFields(t); // Number of fields in record

/* Create a RecordReader to match an auto-generated regular expression
for a record created by the :proc:`createRegex` routine.
Expand Down
4 changes: 2 additions & 2 deletions modules/packages/ZMQ.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ module ZMQ {
(!isBytes(T))) {
on classRef.home {
var copy = data;
param N = numFields(T);
param N = getNumFields(T);
for param i in 0..<(N-1) do
try send(getField(copy,i), ZMQ_SNDMORE | flags);

Expand Down Expand Up @@ -1045,7 +1045,7 @@ module ZMQ {
var ret: T;
on classRef.home {
var data: T;
for param i in 0..<numFields(T) do
for param i in 0..<getNumFields(T) do
getFieldRef(data,i) = try recv(getField(data,i).type);
ret = data;
}
Expand Down
4 changes: 2 additions & 2 deletions modules/standard/CommDiagnostics.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ module CommDiagnostics

var first = true;
c.write("(");
for param i in 0..<numFields(chpl_commDiagnostics) {
for param i in 0..<getNumFields(chpl_commDiagnostics) {
param name = getFieldName(chpl_commDiagnostics, i);
const val = getField(this, i);
if val != 0 {
Expand Down Expand Up @@ -474,7 +474,7 @@ module CommDiagnostics
var CommDiags = getCommDiagnostics();

// cache number of fields and store vector of whether field is active
param nFields = numFields(chpl_commDiagnostics);
param nFields = getNumFields(chpl_commDiagnostics);

// How wide should the column be for this field? A negative value
// indicates an unstable field. 0 indicates that the field should
Expand Down
49 changes: 27 additions & 22 deletions modules/standard/Reflection.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,8 @@
Functions for reflecting about language elements, such as fields,
functions, and methods.
.. note ::
There are several ways in which this module could be improved:
* the methods here might be better as type methods,
so you could use `R.numFields()` instead of `numFields(R)`.
* :proc:`getField` does not yet return a mutable value.
.. note ::
For reflecting about aspects of the compilation process, see
:mod:`ChplConfig`.
For reflecting about aspects of the compilation process, see
:mod:`ChplConfig`.
*/
module Reflection {

Expand All @@ -58,11 +48,17 @@ private proc checkQueryT(type t) type {
/* Return the number of fields in a class or record as a param.
The count of fields includes types and param fields.
*/
proc numFields(type t) param : int do
proc getNumFields(type t) param : int do
return __primitive("num fields", checkQueryT(t));

/* Return the number of fields in a class or record as a param.
The count of fields includes types and param fields.
*/
@deprecated(notes="'numFields' is deprecated - please use 'getNumFields' instead")
proc numFields(type t) param : int do return getNumFields(t);

/* Get the name of the field at `idx` in a class or record.
Causes a compilation error if `idx` is not in 0..<numFields(t).
Causes a compilation error if `idx` is not in 0..<getNumFields(t).
:arg t: a class or record type
:arg idx: which field to get the name of
Expand All @@ -75,14 +71,14 @@ proc getFieldName(type t, param idx:int) param : string do
// over the const ref one.
/* Get the field at `idx` in a class or record. When the field at `idx`
is a `param`, this overload will be chosen to return a `param`.
Causes a compilation error if `idx` is not in 0..<numFields(t).
Causes a compilation error if `idx` is not in 0..<getNumFields(t).
:arg obj: a class or record
:arg idx: which field to get
:returns: the `param` that field represents
*/
proc getField(const ref obj:?t, param idx: int) param
where idx >= 0 && idx < numFields(t) &&
where idx >= 0 && idx < getNumFields(t) &&
isParam(__primitive("field by num", obj, idx+1)) {

return __primitive("field by num", obj, idx+1);
Expand All @@ -92,20 +88,20 @@ proc getField(const ref obj:?t, param idx: int) param
// over the const ref one.
/* Get the field at `idx` in a class or record. When the field at `idx`
is a `type` variable, this overload will be chosen to return a type.
Causes a compilation error if `idx` is not in 0..<numFields(t).
Causes a compilation error if `idx` is not in 0..<getNumFields(t).
:arg obj: a class or record
:arg idx: which field to get
:returns: the type that field represents
*/
proc getField(const ref obj:?t, param idx: int) type
where idx >= 0 && idx < numFields(t) &&
where idx >= 0 && idx < getNumFields(t) &&
isType(__primitive("field by num", obj, idx+1)) {
return __primitive("field by num", obj, idx+1);
}

/* Get the field at `idx` in a class or record.
Causes a compilation error if `idx` is not in 0..<numFields(t).
Causes a compilation error if `idx` is not in 0..<getNumFields(t).
:arg obj: a class or record
:arg idx: which field to get
Expand Down Expand Up @@ -200,16 +196,16 @@ proc getImplementationField(const ref x:?t, param i:int) const ref {
}

/* Get a mutable ref to the ith field in a class or record.
Causes a compilation error if `i` is not in 0..<numFields(t)
Causes a compilation error if `i` is not in 0..<getNumFields(t)
or if the argument is not mutable.
:arg x: a class or record
:arg i: which field to get
:returns: an rvalue referring to that field.
*/
pragma "unsafe"
inline
proc getFieldRef(ref x:?t, param i:int) ref do
@unstable(reason="'getFieldRef' is unstable")
inline proc getFieldRef(ref x:?t, param i:int) ref do
return __primitive("field by num", x, i+1);

/* Get a mutable ref to a field in a class or record by name.
Expand All @@ -221,6 +217,7 @@ proc getFieldRef(ref x:?t, param i:int) ref do
:returns: an rvalue referring to that field.
*/
pragma "unsafe"
@unstable(reason="'getFieldRef' is unstable")
proc getFieldRef(ref x:?t, param s:string) ref {
param i = __primitive("field name to num", t, s);
if i == 0 then
Expand Down Expand Up @@ -256,6 +253,7 @@ proc hasField(type t, param name:string) param : bool do
:arg idx: which field to query
:returns: ``true`` if the field is instantiated
*/
@unstable(reason="'isFieldBound' is unstable - consider using 'T.fieldName != ?' syntax instead")
proc isFieldBound(type t, param idx: int) param : bool {
return __primitive("is bound", checkQueryT(t),
getFieldName(checkQueryT(t), idx));
Expand All @@ -268,19 +266,22 @@ proc isFieldBound(type t, param idx: int) param : bool {
:arg name: the name of a field
:returns: ``true`` if the field is instantiated
*/
@unstable(reason="'isFieldBound' is unstable - consider using 'T.fieldName != ?' syntax instead")
proc isFieldBound(type t, param name : string) param : bool {
return __primitive("is bound", checkQueryT(t), name);
}

/* Returns ``true`` if a function named `fname` taking no arguments
could be called in the current scope.
*/
@unstable(reason="The 'canResolve...' family of procedures are unstable")
proc canResolve(param fname : string) param : bool do
return __primitive("call and fn resolves", fname);

/* Returns ``true`` if a function named `fname` taking the arguments in
`args` could be called in the current scope.
*/
@unstable(reason="The 'canResolve...' family of procedures are unstable")
proc canResolve(param fname : string, args ...) param : bool do
return __primitive("call and fn resolves", fname, (...args));

Expand All @@ -289,24 +290,28 @@ proc canResolve(param fname : string, args ...) param : bool do
/* Returns ``true`` if a method named `fname` taking no arguments
could be called on `obj` in the current scope.
*/
@unstable(reason="The 'canResolve...' family of procedures are unstable")
proc canResolveMethod(obj, param fname : string) param : bool do
return __primitive("method call and fn resolves", obj, fname);

/* Returns ``true`` if a method named `fname` taking the arguments in
`args` could be called on `obj` in the current scope.
*/
@unstable(reason="The 'canResolve...' family of procedures are unstable")
proc canResolveMethod(obj, param fname : string, args ...) param : bool do
return __primitive("method call and fn resolves", obj, fname, (...args));

/* Returns ``true`` if a type method named `fname` taking no
arguments could be called on type `t` in the current scope.
*/
@unstable(reason="The 'canResolve...' family of procedures are unstable")
proc canResolveTypeMethod(type t, param fname : string) param : bool do
return __primitive("method call and fn resolves", t, fname);

/* Returns ``true`` if a type method named `fname` taking the
arguments in `args` could be called on type `t` in the current scope.
*/
@unstable(reason="The 'canResolve...' family of procedures are unstable")
proc canResolveTypeMethod(type t, param fname : string, args ...) param : bool do
return __primitive("method call and fn resolves", t, fname, (...args));

Expand Down
36 changes: 0 additions & 36 deletions test/compflags/TestWarnUnstableSuppression.2.good
Original file line number Diff line number Diff line change
@@ -1,37 +1 @@
$CHPL_HOME/modules/internal/ChapelArray.chpl:nnnn: In function 'chpl__distributed':
$CHPL_HOME/modules/internal/ChapelArray.chpl:nnnn: warning: 'dmapped' keyword is unstable, instead please use factory functions when available
$CHPL_HOME/modules/internal/ChapelArray.chpl:nnnn: warning: 'dmapped' keyword is unstable, instead please use factory functions when available
$CHPL_HOME/modules/internal/ChapelArray.chpl:nnnn: warning: 'dmapped' keyword is unstable, instead please use factory functions when available
$CHPL_HOME/modules/internal/ChapelArray.chpl:nnnn: warning: 'dmapped' keyword is unstable, instead please use factory functions when available
$CHPL_HOME/modules/internal/ChapelBase.chpl:nnnn: warning: chpl_unstableInternalSymbolForTesting is unstable
$CHPL_HOME/modules/internal/ChapelBase.chpl:nnnn: warning: 'ChplConfig.CHPL_GPU_MEM_STRATEGY' is unstable and may be replaced with a different way to access this information in the future
$CHPL_HOME/modules/internal/ChapelBase.chpl:nnnn: warning: 'ChplConfig.CHPL_LOCALE_MODEL' is unstable and may be replaced with a different way to access this information in the future
$CHPL_HOME/modules/internal/Atomics.chpl:nnnn: warning: 'ChplConfig.CHPL_NETWORK_ATOMICS' is unstable and may be replaced with a different way to access this information in the future
$CHPL_HOME/modules/internal/ChapelSyncvar.chpl:nnnn: In function 'supportsNativeSyncVar':
$CHPL_HOME/modules/internal/ChapelSyncvar.chpl:nnnn: warning: 'ChplConfig.CHPL_TASKS' is unstable and may be replaced with a different way to access this information in the future
$CHPL_HOME/modules/internal/ChapelSyncvar.chpl:nnnn: warning: 'ChplConfig.CHPL_TARGET_ARCH' is unstable and may be replaced with a different way to access this information in the future
$CHPL_HOME/modules/internal/DefaultRectangular.chpl:nnnn: warning: the type 'dmap' is unstable, instead please use distribution factory functions when available
$CHPL_HOME/modules/internal/DefaultRectangular.chpl:nnnn: warning: the type 'dmap' is unstable, instead please use distribution factory functions when available
$CHPL_HOME/modules/internal/DefaultRectangular.chpl:nnnn: In function '_simpleTransfer':
$CHPL_HOME/modules/internal/DefaultRectangular.chpl:nnnn: warning: 'ChplConfig.CHPL_LOCALE_MODEL' is unstable and may be replaced with a different way to access this information in the future
$CHPL_HOME/modules/internal/DefaultRectangular.chpl:nnnn: warning: 'ChplConfig.CHPL_LOCALE_MODEL' is unstable and may be replaced with a different way to access this information in the future
$CHPL_HOME/modules/internal/ChapelGpuSupport.chpl:nnnn: warning: 'ChplConfig.CHPL_LOCALE_MODEL' is unstable and may be replaced with a different way to access this information in the future
$CHPL_HOME/modules/internal/ChapelHashtable.chpl:nnnn: In function '_allocateData':
$CHPL_HOME/modules/internal/ChapelHashtable.chpl:nnnn: warning: 'ChplConfig.CHPL_LOCALE_MODEL' is unstable and may be replaced with a different way to access this information in the future
$CHPL_HOME/modules/internal/LocaleModelHelpSetup.chpl:nnnn: In function 'localSpawn':
$CHPL_HOME/modules/internal/LocaleModelHelpSetup.chpl:nnnn: warning: 'ChplConfig.CHPL_COMM_SUBSTRATE' is unstable and may be replaced with a different way to access this information in the future
$CHPL_HOME/modules/internal/LocaleModelHelpSetup.chpl:nnnn: warning: 'ChplConfig.CHPL_COMM_SUBSTRATE' is unstable and may be replaced with a different way to access this information in the future
$CHPL_HOME/modules/internal/LocaleModelHelpSetup.chpl:nnnn: warning: 'ChplConfig.CHPL_COMM' is unstable and may be replaced with a different way to access this information in the future
$CHPL_HOME/modules/internal/BytesStringCommon.chpl:nnnn: In function 'doSearchNoEnc':
$CHPL_HOME/modules/internal/BytesStringCommon.chpl:nnnn: warning: range.orderToIndex() is unstable and its behavior may change in the future
$CHPL_HOME/modules/internal/BytesStringCommon.chpl:nnnn: warning: range.orderToIndex() is unstable and its behavior may change in the future
$CHPL_HOME/modules/internal/String.chpl:nnnn: called as doSearchNoEnc(x: string, needle: string, region: range(byteIndex,low,one), param count = false, param fromLeft = true)
within internal functions (use --print-callstack-on-error to see)
$CHPL_HOME/modules/internal/String.chpl:nnnn: In method 'doSearchUTF8':
$CHPL_HOME/modules/internal/String.chpl:nnnn: warning: range.orderToIndex() is unstable and its behavior may change in the future
$CHPL_HOME/modules/internal/String.chpl:nnnn: warning: range.orderToIndex() is unstable and its behavior may change in the future
$CHPL_HOME/modules/internal/String.chpl:nnnn: called as string.doSearchUTF8(pattern: string, indices: range(byteIndex,low,one), param count = false, param fromLeft = true)
within internal functions (use --print-callstack-on-error to see)
$CHPL_HOME/modules/internal/ChapelLocale.chpl:nnnn: In function 'warmupRuntime':
$CHPL_HOME/modules/internal/ChapelLocale.chpl:nnnn: warning: 'allocate' is unstable, and may be renamed or moved
$CHPL_HOME/modules/internal/ChapelLocale.chpl:nnnn: warning: 'deallocate' is unstable, and may be renamed or moved
Loading

0 comments on commit 2dcdd4b

Please sign in to comment.