Skip to content

Commit

Permalink
Disable where-clauses in chpldoc with a pragma (chapel-lang#23460)
Browse files Browse the repository at this point in the history
This PR enables hiding the where-clause from the chpldoc of a function
by annotating the function with a pragma `"no where doc"` . It applies
this pragma to `range.tryCast`, whose where-clause is not intended for
user-facing documentation.

The same result could be achieved as easily with `@chpldoc.noWhere`,
however that would be a "feature" and we are past feature freeze.

r: @DanilaFe
  • Loading branch information
vasslitvinov authored Sep 20, 2023
2 parents 9819dfe + 6dffc55 commit 161445e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions frontend/include/chpl/uast/PragmaList.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ PRAGMA(NO_COPY_RETURN, ypr, "no copy return", ncm)
PRAGMA(NO_COPY_RETURNS_OWNED, ypr, "no copy returns owned", ncm)
PRAGMA(NO_DEFAULT_FUNCTIONS, ypr, "no default functions", ncm)
PRAGMA(NO_DOC, ypr, "no doc", "do not generate chpldoc documentation for this symbol")
PRAGMA(NO_WHERE_DOC, ypr, "no where doc", "do not include the where clause in chpldoc documentation for this symbol")
PRAGMA(NO_IMPLICIT_COPY, ypr, "no implicit copy", "function does not require autoCopy/autoDestroy")

// This flag disables initialization entirely. In contrast, `= noinit`
Expand Down
1 change: 1 addition & 0 deletions modules/internal/ChapelRange.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -1843,6 +1843,7 @@ proc range.safeCast(type t: range(?)) {
the original bounds and/or stride do not fit in the new idxType
or when the original stride is not legal for the new `strides` parameter.
*/
pragma "no where doc"
proc range.tryCast(type t: range(?)) where chpl_tryCastIsSafe(this, t) {
const r = this;
checkBounds(t, r);
Expand Down
5 changes: 5 additions & 0 deletions test/chpldoc/functions/WhereClause.doc.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ module M {
writeln("processRange 2");
}

pragma "no where doc"
proc processRangeNW(r: range) where r.low > 1 {
writeln("processRange no where");
}

// From borrowed-in-where.chpl
proc foo(type t) where isSubtype(t, int) {
writeln("In foo where");
Expand Down
2 changes: 2 additions & 0 deletions test/chpldoc/functions/WhereClause.doc.good
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ or

.. function:: proc processRange(r: range) where r.low > 1

.. function:: proc processRangeNW(r: range)

.. function:: proc foo(type t) where isSubtype(t, int)

.. function:: operator +(a: int, b: int) where a > 0
Expand Down
9 changes: 9 additions & 0 deletions tools/chpldoc/chpldoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,13 @@ static bool isNoDoc(const Decl* e) {
return false;
}

static bool isNoWhereDoc(const Function* f) {
if (auto attrs = f->attributeGroup())
if (attrs->hasPragma(pragmatags::PRAGMA_NO_WHERE_DOC))
return true;
return false;
}

static std::vector<std::string> splitLines(const std::string& s) {
std::stringstream ss(s);
std::string line;
Expand Down Expand Up @@ -1145,8 +1152,10 @@ struct RstSignatureVisitor {

// Where Clause
if (const AstNode* wc = f->whereClause()) {
if (!isNoWhereDoc(f)) {
os_ << " where ";
wc->traverse(*this);
}
}

return false;
Expand Down

0 comments on commit 161445e

Please sign in to comment.