Skip to content

Commit

Permalink
Merge branch 'main' into chapel-packages-comm
Browse files Browse the repository at this point in the history
Signed-off-by: Jade Abraham <jade.abraham@hpe.com>
  • Loading branch information
jabraham17 committed Jun 12, 2024
2 parents fb4e168 + 809efa4 commit c6ad8a2
Show file tree
Hide file tree
Showing 268 changed files with 29,025 additions and 18,148 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ lint-standard-modules: chplcheck FORCE
tools/chplcheck/chplcheck --skip-unstable \
--internal-prefix "_" \
--internal-prefix "chpl_" \
--disable-rule "RedundantParentheses" \
$(MODULES_TO_LINT)

compile-util-python: FORCE
Expand Down
2 changes: 2 additions & 0 deletions compiler/include/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ extern bool fDriverCompilationPhase;
extern bool fDriverMakeBinaryPhase;
extern char driverTmpDir[FILENAME_MAX];
// end compiler driver control flags
extern bool fExitLeaks;
extern bool fPrintAllCandidates;
extern bool fPrintCallGraph;
extern bool fPrintCallStackOnError;
Expand Down Expand Up @@ -322,6 +323,7 @@ extern bool fDynoScopeResolve;
extern bool fDynoScopeProduction;
extern bool fDynoScopeBundled;
extern bool fDynoDebugTrace;
extern bool fDynoDebugPrintParsedFiles;
extern bool fDynoVerifySerialization;
extern bool fDynoGenLib;
extern bool fDynoGenStdLib;
Expand Down
4 changes: 4 additions & 0 deletions compiler/main/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ bool fDriverDoMonolithic = false;
bool driverDebugPhaseSpecified = false;
// Tmp dir path managed by compiler driver
char driverTmpDir[FILENAME_MAX] = "";
bool fExitLeaks = false;
bool fLibraryCompile = false;
bool fLibraryFortran = false;
bool fLibraryMakefile = false;
Expand Down Expand Up @@ -375,6 +376,7 @@ bool fDynoScopeResolve = true;
bool fDynoScopeProduction = true;
bool fDynoScopeBundled = false;
bool fDynoDebugTrace = false;
bool fDynoDebugPrintParsedFiles = false;
bool fDynoVerifySerialization = false;
bool fDynoGenLib = false;
bool fDynoGenStdLib = false;
Expand Down Expand Up @@ -1439,6 +1441,7 @@ static ArgumentDescription arg_desc[] = {
{"driver-compilation-phase", ' ', NULL, "Run driver compilation phase (internal use flag)", "F", &fDriverCompilationPhase, NULL, setSubInvocation},
{"driver-makebinary-phase", ' ', NULL, "Run driver makeBinary phase (internal use flag)", "F", &fDriverMakeBinaryPhase, NULL, setSubInvocation},
{"driver-debug-phase", ' ', "<phase>", "Specify driver phase to run when debugging: compilation, makeBinary, all", "S", NULL, NULL, setDriverDebugPhase},
{"exit-leaks", ' ', NULL, "[Don't] leak memory on exit", "N", &fExitLeaks, NULL, NULL},
{"gdb", ' ', NULL, "Run compiler in gdb", "F", &fRungdb, NULL, NULL},
{"lldb", ' ', NULL, "Run compiler in lldb", "F", &fRunlldb, NULL, NULL},
{"interprocedural-alias-analysis", ' ', NULL, "Enable [disable] interprocedural alias analysis", "n", &fNoInterproceduralAliasAnalysis, NULL, NULL},
Expand Down Expand Up @@ -1508,6 +1511,7 @@ static ArgumentDescription arg_desc[] = {
{"dyno-scope-production", ' ', NULL, "Enable [disable] using both dyno and production scope resolution", "N", &fDynoScopeProduction, "CHPL_DYNO_SCOPE_PRODUCTION", NULL},
{"dyno-scope-bundled", ' ', NULL, "Enable [disable] using dyno to scope resolve bundled modules", "N", &fDynoScopeBundled, "CHPL_DYNO_SCOPE_BUNDLED", NULL},
{"dyno-debug-trace", ' ', NULL, "Enable [disable] debug-trace output when using dyno compiler library", "N", &fDynoDebugTrace, "CHPL_DYNO_DEBUG_TRACE", NULL},
{"dyno-debug-print-parsed-files", ' ', NULL, "Enable [disable] printing all files that were parsed by Dyno", "N", &fDynoDebugPrintParsedFiles, "CHPL_DYNO_DEBUG_PRINT_PARSED_FILES", NULL},
{"dyno-break-on-hash", ' ' , NULL, "Break when query with given hash value is executed when using dyno compiler library", "X", &fDynoBreakOnHash, "CHPL_DYNO_BREAK_ON_HASH", NULL},
{"dyno-gen-lib", ' ', "<path>", "Specify files named on the command line should be saved into a .dyno library", "P", NULL, NULL, addDynoGenLib},
{"dyno-gen-std", ' ', NULL, "Generate a .dyno library file for the standard library", "F", &fDynoGenStdLib, NULL, setDynoGenStdLib},
Expand Down
10 changes: 10 additions & 0 deletions compiler/passes/parseAndConvert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1439,5 +1439,15 @@ void parseAndConvertUast() {
// Revert to using the default error handler now.
gContext->installErrorHandler(nullptr);

if (fDynoDebugPrintParsedFiles) {
std::set<std::string> files;
auto filesUstr = chpl::parsing::introspectParsedFiles(gContext);
for (auto ustr : filesUstr) {
files.insert(ustr.str());
}
for (auto file : files) {
fprintf(stderr, "Parsed file: %s\n", file.c_str());
}
}
parsed = true;
}
17 changes: 16 additions & 1 deletion compiler/resolution/functionResolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4115,6 +4115,21 @@ static void reportHijackingError(CallExpr* call,
USR_STOP();
}

static void explainOne(ResolutionCandidate* best, ResolutionCandidate* cur,
const char* kind) {
if (cur != nullptr && cur != best)
USR_PRINT(cur->fn, "%10s overload: %s", kind, toString(cur->fn));
}
static void explainCallCandidates(ResolutionCandidate* best,
ResolutionCandidate* bestRef,
ResolutionCandidate* bestValue,
ResolutionCandidate* bestConstRef) {
USR_PRINT(best->fn, "best candidates are: %s", toString(best->fn));
explainOne(best, bestRef, "ref");
explainOne(best, bestValue, "value");
explainOne(best, bestConstRef, "const ref");
}

static bool overloadSetsOK(CallExpr* call,
BlockStmt* searchScope,
check_state_t checkState,
Expand Down Expand Up @@ -4396,7 +4411,7 @@ static FnSymbol* resolveNormalCall(CallInfo& info,
}

if (explainCallLine != 0 && explainCallMatch(call) == true) {
USR_PRINT(best->fn, "best candidate is: %s", toString(best->fn));
explainCallCandidates(best, bestRef, bestValue, bestConstRef);
}

if (call->partialTag == true &&
Expand Down
8 changes: 7 additions & 1 deletion compiler/util/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,13 @@ void clean_exit(int status) {

cleanup_for_exit();

delete gContext;
if (fExitLeaks) {
// The context's destructor takes a while, and we're about to exit anyway,
// so deliberately leak it. Still perform file-based cleanup, though.
gContext->cleanupTmpDirIfNeeded();
} else {
delete gContext;
}
gContext = nullptr;

if (gGenInfo) {
Expand Down
12 changes: 9 additions & 3 deletions doc/rst/technotes/gpu.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ The following are further requirements for GPU support:
* For targeting NVIDIA or AMD GPUs, ``LLVM`` must be used as Chapel's backend
compiler (i.e. ``CHPL_LLVM`` must be set to ``system`` or ``bundled``).

* The environment variable ``CHPL_LOCALE_MODEL`` must be set to ``gpu``.

* Specifically for targeting NVIDIA GPUs:

* CUDA toolkit version 11.x or 12.x must be installed.
Expand Down Expand Up @@ -152,9 +154,13 @@ The following are further requirements for GPU support:
GPU-Related Environment Variables
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To enable GPU support, set the environment variable ``CHPL_LOCALE_MODEL=gpu``
before building Chapel. Several other variables affect how Chapel generates
code for and interacts with GPUs. These variables include:

Several variables affect how Chapel generates code for and interacts with GPUs.
These variables include:

* ``CHPL_LOCALE_MODEL`` --- must be set to ``gpu`` to enable GPU support.
Chapel will need to be rebuilt if this value is changed. For more information,
see :ref:`readme-chplenv.CHPL_LOCALE_MODEL`.

* ``CHPL_GPU`` --- may be set to ``nvidia``, ``amd``, or ``cpu``. If unset, as
part of its build process, Chapel will attempt to automatically determine what
Expand Down
53 changes: 53 additions & 0 deletions doc/rst/tools/chpl-language-server/chpl-language-server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,40 @@ VSCode
Install the ``chapel`` extension from the `Visual Studio Code marketplace
<https://marketplace.visualstudio.com/items?itemName=chpl-hpe.chapel-vscode>`_.

.. _chpl-language-server-emacs:

Emacs
^^^^^

With Emacs 29.1, support has been added for language server protocols via `Eglot
<https://www.gnu.org/software/emacs/manual/html_mono/eglot.html>`_

To utilize the Chapel language server with Eglot, add the following to your
``.emacs`` file (note that this assumes you have already followed the
instructions in ``$CHPL_HOME/highlight/emacs/README.rst`` to install Chapel
syntax highlighting in Emacs):

.. code-block:: lisp

(with-eval-after-load 'eglot
(add-to-list 'eglot-server-programs
'(chpl-mode . ("chpl-language-server" "--chplcheck"))))

This will enable using the language server with a particular ``.chpl`` file by
calling ``M-x eglot``.

To automatically use Eglot and the language server with every ``.chpl`` file,
additionally add the following to your ``.emacs`` file:

.. code-block:: lisp

(add-hook 'chpl-mode-hook 'eglot-ensure)

.. note::

The above uses the ``--chplcheck`` flag to enable additional diagnostics from
``chplcheck``. If you do not want to use ``chplcheck``, you can remove this.

Supported Features
------------------

Expand Down Expand Up @@ -156,6 +190,25 @@ The following features are extra visual aids:
| Instantiations | instantiations of a generic function. | |
+----------------+--------------------------------------------+---------------------------------------+

Using ``chplcheck`` from ``CLS``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Although :ref:`chplcheck <readme-chplcheck>` is a separate tool from ``CLS``,
it can be used from ``CLS`` to provide additional diagnostics. This is done by
enabling the ``--chplcheck`` flag. This will incorporate the diagnostics and
fixits from ``chplcheck``.

You can also still pass many of the same ``chplcheck`` flags to ``CLS``, just
prefixed with ``--chplcheck-``. For example, the following command runs the
language server with linting enabled various ``chplcheck`` flags:

.. code-block:: bash

chpl-language-server --chplcheck \
--chplcheck-enable-rule UseExplicitModules \
--chplcheck-disable-rule UnusedLoopIndex \
--chplcheck-add-rules path/to/my/myrules.py

Configuring Chapel Projects
---------------------------

Expand Down
36 changes: 35 additions & 1 deletion doc/rst/tools/chplcheck/chplcheck.rst
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,44 @@ VSCode
Install the ``chapel`` extension from the `Visual Studio Code marketplace
<https://marketplace.visualstudio.com/items?itemName=chpl-hpe.chapel-vscode>`_.

Emacs
~~~~~

With Emacs 29.1, support has been added for language server protocols via `Eglot
<https://www.gnu.org/software/emacs/manual/html_mono/eglot.html>`_

To utilize the linter via Eglot, add the following to your ``.emacs`` file (note
that this assumes you have already followed the instructions in
``$CHPL_HOME/highlight/emacs/README.rst`` to install Chapel syntax highlighting
in Emacs):

.. code-block:: lisp

(with-eval-after-load 'eglot
(add-to-list 'eglot-server-programs
'(chpl-mode . ("chplcheck" "--lsp"))))

This will enable using the linter with a particular ``.chpl`` file by calling
``M-x eglot``.

To automatically use Eglot and the linter with every ``.chpl`` file,
additionally add the following to your ``.emacs`` file:

.. code-block:: lisp

(add-hook 'chpl-mode-hook 'eglot-ensure)

.. note::

There is currently a limitation with Eglot that only one language server can
be registered per language. To use ``chplcheck`` and ``chapel-language-server``
at the same time, see the
:ref:`Emacs documentation for chapel-language-server <chpl-language-server-emacs>`.

Writing New Rules
-----------------

Rules are written using the :ref:`Python bindings for Chapel's compiler frontend<readme-chapel-py>`. In
Rules are written using the :ref:`Python bindings for Chapel's compiler frontend <readme-chapel-py>`. In
essence, a rule is a Python function that is used to detect issues with the
AST. When registered with ``chplcheck``, the name of the function becomes the name
of the rule (which can be used to enable and disable the rule, as per the
Expand Down
5 changes: 5 additions & 0 deletions doc/rst/usingchapel/chplenv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,15 @@ CHPL_LOCALE_MODEL
flat top-level locales are not further subdivided
numa top-level locales are further subdivided into
sublocales, each one a NUMA domain
gpu enable gpu sublocales
======== =============================================

If unset, ``CHPL_LOCALE_MODEL`` defaults to ``flat``.

To enable GPU support, the value must be set to ``gpu``. See :ref:`readme-gpu` for more information.

.. warning:: GPU support is under active development and settings may change.

.. warning:: The NUMA locale model is deprecated and will be removed
in a future release.

Expand Down
8 changes: 7 additions & 1 deletion frontend/include/chpl/framework/query-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@
#include "chpl/framework/stringify-functions.h"

#ifndef CHPL_QUERY_TIMING_AND_TRACE_ENABLED
#ifdef NDEBUG
// release mode
#define CHPL_QUERY_TIMING_AND_TRACE_ENABLED 0
#else
// debug mode
#define CHPL_QUERY_TIMING_AND_TRACE_ENABLED 1
#endif
#endif

/**
This file should be included by .cpp files implementing queries.
Expand Down Expand Up @@ -617,7 +623,7 @@ Context::querySetterUpdateResult(

#else

#define QUERY_BEGIN_TIMING()
#define QUERY_BEGIN_TIMING(context__)

#endif

Expand Down
10 changes: 10 additions & 0 deletions frontend/include/chpl/parsing/parsing-queries.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,16 @@ filePathIsInBundledModule(Context* context, UniqueString filePath);
*/
const uast::Module* getToplevelModule(Context* context, UniqueString name);

/**
Given a particular (presumably standard) module, return the ID of a symbol
with the given name in that module. Beyond creating the ID, this also ensures
that the standard module is parsed, and thus, that 'idToAst' on the returned
ID will return a non-null value.
*/
ID getSymbolFromTopLevelModule(Context* context,
const char* modName,
const char* symName);

/**
This query parses a submodule for 'include submodule'.
Returns nullptr if no such file can be found.
Expand Down
5 changes: 4 additions & 1 deletion frontend/include/chpl/resolution/scope-queries.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,12 @@ namespace resolution {

/**
Resolve the uses and imports in a given scope.

If 'skipPrivate' is set, avoids resolving visibility statements that
only expose scope-private symbols. This helps avoid unnecessary work.
*/
const ResolvedVisibilityScope*
resolveVisibilityStmts(Context* context, const Scope* scope);
resolveVisibilityStmts(Context* context, const Scope* scope, bool skipPrivate = false);

/**
Return the scope for the automatically included 'ChapelStandard' module,
Expand Down
6 changes: 5 additions & 1 deletion frontend/include/chpl/uast/Builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ class Builder final {

void noteAdditionalLocation(AstLocMap& m, AstNode* ast, Location loc);
void tryNoteAdditionalLocation(AstLocMap& m, AstNode* ast, Location loc);
void copyAdditionalLocation(AstLocMap& m, const AstNode* from, const AstNode* to);
void deleteAdditionalLocation(AstLocMap& m, const AstNode* ast);

public:
/** Construct a Builder for parsing a top-level module */
Expand Down Expand Up @@ -143,7 +145,9 @@ class Builder final {
For a list of all locations see "./all-location-maps.h". */
#define LOCATION_MAP(ast__, location__) \
void note##location__##Location(ast__* ast, Location loc); \
void tryNote##location__##Location(ast__* ast, Location loc);
void tryNote##location__##Location(ast__* ast, Location loc); \
void copy##location__##Location(const ast__* from, const ast__* to); \
void delete##location__##Location(const ast__* ast);
#include "all-location-maps.h"
#undef LOCATION_MAP

Expand Down
26 changes: 19 additions & 7 deletions frontend/lib/parsing/ParserContextImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1736,6 +1736,14 @@ owned<Decl> ParserContext::buildLoopIndexDecl(YYLTYPE location,
/*typeExpression*/ nullptr,
/*initExpression*/ nullptr);
builder->noteDeclNameLocation(var.get(), convLoc);
builder->copyExprParenthLocation(e, var.get());
builder->deleteExprParenthLocation(e);
// Delete the location of 'e' because it's about to be deallocated;
// we don't want a new allocation of an AST node to have the same pointer
// and still be in the map, since that would pollute location information.
//
// This is more of a workaround; a more general solution is necessary
// to handle pointer-based maps in the presence of AST node deallocation.
return var;

} else if (const uast::Tuple* tup = e->toTuple()) {
Expand All @@ -1751,13 +1759,17 @@ owned<Decl> ParserContext::buildLoopIndexDecl(YYLTYPE location,
}
}

return TupleDecl::build(builder, convLoc, /*attributeGroup*/ nullptr,
Decl::DEFAULT_VISIBILITY,
Decl::DEFAULT_LINKAGE,
(TupleDecl::IntentOrKind) Variable::INDEX,
std::move(elements),
/*typeExpression*/ nullptr,
/*initExpression*/ nullptr);
auto td = TupleDecl::build(builder, convLoc, /*attributeGroup*/ nullptr,
Decl::DEFAULT_VISIBILITY,
Decl::DEFAULT_LINKAGE,
(TupleDecl::IntentOrKind) Variable::INDEX,
std::move(elements),
/*typeExpression*/ nullptr,
/*initExpression*/ nullptr);
builder->copyExprParenthLocation(e, td.get());
builder->deleteExprParenthLocation(e);
// See the comment above for why we delete the location of 'e'.
return td;
} else {
CHPL_PARSER_REPORT(this, InvalidIndexExpr, location);
return nullptr;
Expand Down
Loading

0 comments on commit c6ad8a2

Please sign in to comment.