Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chpldoc/next - now with queries #18956

Merged
merged 4 commits into from Jan 12, 2022
Merged

chpldoc/next - now with queries #18956

merged 4 commits into from Jan 12, 2022

Conversation

aconsroe-hpe
Copy link
Contributor

@aconsroe-hpe aconsroe-hpe commented Jan 10, 2022

Squash of progress on chpldoc/next overhaul to use queries.

Note this "requires" C++17 only as a convenience step in prototyping to get the fileystem functionality. Future work can remove this.

Adds an temporary env var CHPL_CHPLDOC_NEXT so that we can force sub_test to use that binary when doing chpldoc tests.

Passes 15 tests in test/chpldoc currently

Squash of progress on chpldoc/next overhaul to use queries. That was
an easy step.

Adds an initial implementation of actually converting the AST into
the appropriate RST format. This uses the visitor and traverse
pattern.

Added a hack environment variable to sub_test.py so that
CHPL_CHPLDOC_NEXT can be specified to use it instead of today's
chpldoc. This was because PATH get's messed with by fixpath.py

Note this "requires" C++17 only as a convenience step in prototyping
to get the fileystem functionality.

Today we only pass 1 test case. Many are whitespace only which is a
good sign, just ran out of time to address them.

Signed-off-by: Andrew Consroe <andrew.consroe@hpe.com>
/*
To test this today, you can force sub_test to use this version by doing:
> CHPL_CHPLDOC_NEXT=$(find $(pwd) -name chpldoc -type f) ./util/test/start_test.py test/chpldoc/enum.doc.chpl
You'll want to make sure that the find command finds a single chpldoc executable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative would be to adjust compiler/main/driver to run this alternative chpldoc implementation.

@mppf
Copy link
Member

mppf commented Jan 10, 2022

Today we only pass 1 test case. Many are whitespace only which is a
good sign, just ran out of time to address them.

I think you are saying there are whitespace differences? Which is the 1 test that passes?

@aconsroe-hpe
Copy link
Contributor Author

Yes whitespace only differences is what I meant.
The 1 test is chpldoc/enum/docConstants, nothing to write home about.

Copy link
Member

@mppf mppf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would it take to only use C++14?

Also this version doesn't implement parts of chpldoc with queries the way I was expecting. It does use a visitor, which is good. I was expecting it to define a one or more queries, e.g. a query (with QUERY_BEGIN) for going from a uAST node for a module or function to a string containing the .rst snippet produced by chpldoc. If there is a reason that you don't want to do that, we should discuss.

util/test/sub_test.py Show resolved Hide resolved
return lines[0];
}

static const char* kindToRstString(bool isMethod, Function::Kind kind) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe name it FunctionKindToRstString ?

" /* comment 3 */\n"
"}\n"
"/* comment 4 */";
static const char* kindToString(Function::Visibility kind) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe name it visibilityToString ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the overload is appropriate here

int main(int argc, char **argv) {
Context context;
Context *ctx = &context;
static const char* kindToString(Function::Kind kind) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

functionKindToString?


auto parser = Parser::build(ctx);
Parser *p = parser.get();
static const char* kindToString(Function::ReturnIntent kind) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

returnIntentToString ?


auto parseResult = argc == 2 ? parser->parseFile(argv[1])
: parser->parseString("test1a.chpl", testString);
static const char* kindToString(Formal::Intent kind) {
Copy link
Member

@mppf mppf Jan 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

intentToString ?

return "";
}

static const char* kindToString(Variable::Kind kind) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variableKindToString?

return "";
}

static const char* kindToString(New::Management kind) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newManagementToString?

struct PrettyPrintVisitor {
std::ostream& os_;

template<typename It>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a comment about what this method is for

compiler/next/tools/chpldoc/CMakeLists.txt Show resolved Hide resolved
@aconsroe-hpe
Copy link
Contributor Author

What would it take to only use C++14?

Removing the call to std::filesystem::create_directories

Heard on the queries part. Seems like the biggest obstacle is knowing what your last comment is. I know we maintain the parent mapping so it should be possible to check your previous sibling but maybe there's a nicer way I'm not thinking of?

@aconsroe-hpe

This comment was marked as outdated.

This extends the previous work of adding queries to next/chpldoc by
converting the one-shot visitor approach with a qury rstDoc to compute
the docs for a given node. These results form a tree with the goal
being that the query framework will re-use subtrees that have not
changed. This avoids a small blow-up in eagerly concatenating a tree
of strings but the main motivation was to kick the tires more on
queries.

This now passes a whopping 15 chpldoc tests! 138 Failures still :)

Also fixes a small bug in mark-functions.h

Signed-off-by: Andrew Consroe <andrew.consroe@hpe.com>
Signed-off-by: Andrew Consroe <andrew.consroe@hpe.com>
@aconsroe-hpe
Copy link
Contributor Author

I implemented the approach we had discussed yesterday, ready for another pass at your leisure @mppf

Copy link
Member

@mppf mppf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the impromevents! I think this is looking good, structurally. Please make yourself a few issues to track future work:

  • get more chpldoc tests passing with this
  • add regular testing of it, somewhere
  • remove the C++17 dependency (or migrate our compiler sources to C++17) since we will need to do that before this code can be used in production

compiler/next/tools/chpldoc/chpldoc.cpp Show resolved Hide resolved
compiler/next/tools/chpldoc/chpldoc.cpp Outdated Show resolved Hide resolved
Signed-off-by: Andrew Consroe <andrew.consroe@hpe.com>
@aconsroe-hpe aconsroe-hpe merged commit f9c86a9 into chapel-lang:main Jan 12, 2022
@aconsroe-hpe aconsroe-hpe deleted the next/chpldoc-2 branch January 12, 2022 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants