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

#132 Change C++ port public API #146

Merged
merged 6 commits into from
Aug 8, 2024

Conversation

vityaman
Copy link
Contributor

@vityaman vityaman commented Aug 5, 2024

  • Introduced an optional parameters pack for collectCandidates. Because current API is not so convenient for usage of only a part of arguments.

  • Did hide preferredRules and ignoredTokens under setters. This will provide us an ability to change internal data structures to improve performance (I'm thinking about using BitSet, because it is more cache friendly while there are not, so many token types in average generated parser).

  • Renamed some variables.

  • Raised port version to 2.0.0 because of API breaking changes.

@vityaman vityaman force-pushed the 132-port-cpp-change-api branch from 92776de to de54895 Compare August 5, 2024 06:36
@vityaman vityaman marked this pull request as ready for review August 5, 2024 06:42
Copy link
Owner

@mike-lischke mike-lischke left a comment

Choose a reason for hiding this comment

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

While I like the new struct parameter for the main collection call, I don't agree with the new setters.

Comment on lines 92 to 102
void CodeCompletionCore::setIgnoredTokens(std::unordered_set<size_t>&& ignoredTokens) {
this->ignoredTokens = std::move(ignoredTokens);
}

void CodeCompletionCore::setPreferredRules(std::unordered_set<size_t>&& preferredRules) {
this->preferredRules = std::move(preferredRules);
}

void CodeCompletionCore::setTranslateRulesTopDown(bool isEnabled) {
this->translateRulesTopDown = isEnabled;
}
Copy link
Owner

Choose a reason for hiding this comment

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

What's the purpose of these setters? Since there's no side processing when setting a value, there's no need to use a setter.


if (showResult) {
if (candidates.cancelled) {
if (show.result) {
Copy link
Owner

Choose a reason for hiding this comment

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

show.result? This is a single flag named showResult. Why splitting it to an extent that becomes no longer easy to understand?

@@ -267,7 +279,7 @@ bool CodeCompletionCore::translateToRuleIndex(
.startTokenIndex = rwst.startTokenIndex,
.ruleList = path,
};
if (showDebugOutput) {
if (show.debugOutput) {
Copy link
Owner

Choose a reason for hiding this comment

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

similar here

@@ -110,44 +129,49 @@ class CodeCompletionCore {
* Tailoring of the result:
* Tokens which should not appear in the candidates set.
*/
std::unordered_set<size_t> ignoredTokens; // NOLINT: public field
void setIgnoredTokens(std::unordered_set<size_t>&& ignoredTokens);
Copy link
Owner

Choose a reason for hiding this comment

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

I see no reason why a public field could be harmful in any way, if it has no side effect when setting it. Additionally, it's a result field, so it is supposed to be a simple public field!

* Enables call stack printing for each rule recursion.
*/
bool ruleStack = false;
} show; // NOLINT: public field, only for debugging
Copy link
Owner

Choose a reason for hiding this comment

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

Putting all debug options in an own struct is ok, just don't name it show. Additionally type names have to be in PascalCase, so a natural choice here would be: DebugOptions instead of show and it would be passed in as parameter like (..., DebugOptions const& debugOptions)...

@@ -38,7 +38,7 @@ TEST(CPP14Parser, SimpleExample) { // NOLINT: complexity
CodeCompletionCore completion(&pipeline.parser);

// Ignore operators and the generic ID token.
completion.ignoredTokens = {
completion.setIgnoredTokens({
Copy link
Owner

@mike-lischke mike-lischke Aug 6, 2024

Choose a reason for hiding this comment

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

Using a name like set<anything> without a get<anything> makes this look as if it were write only. Again, I see no need to make this a setter. It's a simple configuration step, why make it complicated? One could pass that in as a parameter to the main collection call, but since this is something configured once for a specific parser, the simple assignment is more appropriate.

@mike-lischke
Copy link
Owner

mike-lischke commented Aug 6, 2024

  • Introduced an optional parameters pack for collectCandidates. Because current API is not so convenient for usage of only a part of arguments.

I believe the term "parameter pack" is used in the context of type parameters, but I know what you mean.

  • Did hide preferredRules and ignoredTokens under setters. This will provide us an ability to change internal data structures to improve performance (I'm thinking about using BitSet, because it is more cache friendly while there are not, so many token types in average generated parser).

Unnecessary. If you change the storage type (which is really uncritical, both in time and space) let the user know and they can adapt.

@vityaman vityaman force-pushed the 132-port-cpp-change-api branch from de54895 to 7a6c202 Compare August 7, 2024 06:48
@vityaman vityaman force-pushed the 132-port-cpp-change-api branch from 7a6c202 to 5b276d5 Compare August 7, 2024 06:56
@vityaman
Copy link
Contributor Author

vityaman commented Aug 7, 2024

@mike-lischke,

  • removed setters
  • made debug options to be a public field with struct type
  • did tiny refactorings

Copy link
Owner

@mike-lischke mike-lischke left a comment

Choose a reason for hiding this comment

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

Not sure why you prefer pointers over references (ATN* versus ATN&) and why a public field is a linter problem so that you have to mark it to not lint, but otherwise the code looks ok.

@mike-lischke mike-lischke merged commit 531f0b4 into mike-lischke:main Aug 8, 2024
3 checks passed
@vityaman vityaman deleted the 132-port-cpp-change-api branch December 5, 2024 05:06
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.

2 participants