Skip to content

Commit

Permalink
Require setupModuleSearchPaths be called before any other queries (#…
Browse files Browse the repository at this point in the history
…25315)

Require that setting the module search path occurs before any other
queries in the Context revision, if at all. This is to prevent
unexpected results from its default empty value being used before it is
set, as many queries rely on it. Implemented as an assertion that it is
the first query run in the revision.

Also change `testInteractive` to setup module search path earlier to be
in line with this requirement. This fixes buggy behavior with
`testInteractive --std`, in which we might not find standard module
types, that was incidentally introduced in
#25190.

Depends on #25326 which should
be merged first.

[reviewed by @mppf and @DanilaFe , thanks!]

Testing:
- [x] paratest
- [x] dyno tests
- [x] `testInteractive` with basic program
- [x] `chpl --dyno` with basic program
  • Loading branch information
riftEmber authored Jun 27, 2024
2 parents 97a0948 + fa1cd8a commit bc34538
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
3 changes: 3 additions & 0 deletions frontend/lib/parsing/parsing-queries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,9 @@ void setupModuleSearchPaths(
const std::vector<std::string>& prependStandardModulePaths,
const std::vector<std::string>& cmdLinePaths,
const std::vector<std::string>& inputFilenames) {
CHPL_ASSERT(
context->numQueriesRunThisRevision() == 0 &&
"setupModuleSearchPaths should be called before any queries are run");

std::string modRoot;
if (!minimalModules) {
Expand Down
3 changes: 1 addition & 2 deletions frontend/test/resolution/testInteractive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ int main(int argc, char** argv) {

// Run this query first to make the other output more understandable
ctx->setDebugTraceFlag(false);
setupSearchPaths(ctx, enableStdLib, cmdLinePaths, files);
typeForBuiltin(ctx, UniqueString::get(ctx, "int"));
ctx->setDebugTraceFlag(trace);
if (timing) ctx->beginQueryTimingTrace(timing);
Expand All @@ -298,8 +299,6 @@ int main(int argc, char** argv) {
flags.set(CompilerFlags::WARN_UNSTABLE, warnUnstable);
setCompilerFlags(ctx, std::move(flags));

setupSearchPaths(ctx, enableStdLib, cmdLinePaths, files);

std::set<const ResolvedFunction*> calledFns;

for (auto p: files) {
Expand Down
25 changes: 24 additions & 1 deletion tools/chapel-py/src/chapel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,17 @@ def each_matching(node, pattern, iterator=preorder):
yield (child, variables)


def files_with_contexts(files):
def files_with_contexts(
files, setup: Optional[typing.Callable[[Context], None]] = None
):
"""
Some files might have the same name, which Dyno really doesn't like.
Stratify files into "buckets"; within each bucket, all filenames are
unique. Between each bucket, re-create the Dyno context to avoid giving
it conflicting files.
For each newly-created context, call the setup function with it.
Yields files from the argument, as well as the context created for them.
"""

Expand All @@ -354,10 +358,29 @@ def files_with_contexts(files):
ctx = Context()
to_yield = buckets[bucket]

if setup:
setup(ctx)

for filename in to_yield:
yield (filename, ctx)


def files_with_stdlib_contexts(
files, setup: Optional[typing.Callable[[Context], None]] = None
):
"""
Like files_with_contexts, but also includes the standard library in the
context.
"""

def setup_with_stdlib(ctx):
ctx.set_module_paths([], [])
if setup:
setup(ctx)

yield from files_with_contexts(files, setup_with_stdlib)


def range_to_tokens(
rng: Location, lines: List[str]
) -> List[typing.Tuple[int, int, int]]:
Expand Down
4 changes: 1 addition & 3 deletions tools/chplcheck/src/chplcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,7 @@ def main():

printed_warning = False

for filename, context in chapel.files_with_contexts(args.filenames):
context.set_module_paths([], [])

for filename, context in chapel.files_with_stdlib_contexts(args.filenames):
# Silence errors, warnings etc. -- we're just linting.
with context.track_errors() as _:
asts = context.parse(filename)
Expand Down

0 comments on commit bc34538

Please sign in to comment.