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

[DO-NOT-MERGE][incubator-kie-drools-6220] Slim down DRL syntax with New Antlr4 Parser #6225

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

tkobayas
Copy link
Contributor

@tkobayas tkobayas force-pushed the incubator-kie-drools-6220-slimdown branch 3 times, most recently from 9fcc046 to 76f8c98 Compare January 23, 2025 08:36
@kie-ci3
Copy link

kie-ci3 commented Jan 23, 2025

PR job #6 was: UNSTABLE
Possible explanation: This should be test failures

Reproducer

build-chain build full_downstream -f 'https://raw.githubusercontent.com/${AUTHOR:apache}/incubator-kie-kogito-pipelines/${BRANCH:main}/.ci/buildchain-config-pr-cdb.yaml' -o 'bc' -p apache/incubator-kie-drools -u #6225 --skipParallelCheckout

NOTE: To install the build-chain tool, please refer to https://github.com/kiegroup/github-action-build-chain#local-execution

Please look here: https://ci-builds.apache.org/job/KIE/job/drools/job/main/job/pullrequest_jobs/job/drools-pr/job/PR-6225/6/display/redirect

Test results:

  • PASSED: 15528
  • FAILED: 1

Those are the test failures:

PR check / Build projects / maven.invoker.it.drools-test-coverage-jars-with-invoker.drools-test-coverage-jars-with-invoker The build exited with code 143. See /home/jenkins/workspace/llrequest_jobs_drools-pr_PR-6225/kogito-pipelines/bc/apache_incubator-kie-drools/drools-test-coverage/test-compiler-integration/../drools-test-coverage-jars/drools-test-coverage-jars-with-invoker/build.log for details.

@tkobayas tkobayas force-pushed the incubator-kie-drools-6220-slimdown branch from 1457c6f to e59ed36 Compare January 24, 2025 03:35
@tkobayas tkobayas force-pushed the incubator-kie-drools-6220-slimdown branch 2 times, most recently from fcf232c to 37a218d Compare January 30, 2025 09:09
@tkobayas tkobayas force-pushed the incubator-kie-drools-6220-slimdown branch 2 times, most recently from 2559994 to 428a1e6 Compare February 3, 2025 09:51
@kie-ci3
Copy link

kie-ci3 commented Feb 3, 2025

PR job #14 was: UNSTABLE
Possible explanation: This should be test failures

Reproducer

build-chain build full_downstream -f 'https://raw.githubusercontent.com/${AUTHOR:apache}/incubator-kie-kogito-pipelines/${BRANCH:main}/.ci/buildchain-config-pr-cdb.yaml' -o 'bc' -p apache/incubator-kie-drools -u #6225 --skipParallelCheckout

NOTE: To install the build-chain tool, please refer to https://github.com/kiegroup/github-action-build-chain#local-execution

Please look here: https://ci-builds.apache.org/job/KIE/job/drools/job/main/job/pullrequest_jobs/job/drools-pr/job/PR-6225/14/display/redirect

Test results:

  • PASSED: 14920
  • FAILED: 3

Those are the test failures:

org.drools.model.codegen.execmodel.generator.drlxparse.ConstraintParserTest.testImplicitCastExpressionWithOr Cannot invoke "org.drools.drl.ast.descr.RuleDescr.getName()" because "this.ruleDescr" is null
org.drools.model.codegen.execmodel.generator.drlxparse.ConstraintParserTest.testNullSafeExpressionsWithOr Cannot invoke "org.drools.drl.ast.descr.RuleDescr.getName()" because "this.ruleDescr" is null
org.kie.maven.plugin.it.kie-maven-plugin-test-kjar-15-yaml.kie-maven-plugin-test-kjar-15-yaml The build exited with code 143. See /home/jenkins/workspace/llrequest_jobs_drools-pr_PR-6225/kogito-pipelines/bc/apache_incubator-kie-drools/kie-maven-plugin/target/it/kie-maven-plugin-test-kjar-15-yaml/build.log for details.

@tkobayas
Copy link
Contributor Author

tkobayas commented Feb 5, 2025

After review, revert GHA changes. So this is still "Draft"

@tkobayas tkobayas force-pushed the incubator-kie-drools-6220-slimdown branch from 8a9bbff to b7c1b54 Compare February 5, 2025 05:54
@@ -61,7 +61,7 @@ jobs:
- name: Build Chain
uses: apache/incubator-kie-kogito-pipelines/.ci/actions/build-chain@main
env:
BUILD_MVN_OPTS_CURRENT: '-Dfull -Dreproducible'
BUILD_MVN_OPTS_CURRENT: '-Dfull -Dreproducible -DenableNewParser'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a temporal change to test the new parser (= DRL10). I'll revert this after review.

Comment on lines +119 to +124
private static int logCounterHalfConstraint = 0;
private static int logCounterCustomOperator = 0;
private static int logCounterInfixAnd = 0;
private static int logCounterInfixOr = 0;
private static int logCounterAnnotationInLhsPattern = 0;
private static int logCounterAgendaGroup = 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A counter to suppress log flooding. Using static int is a bit rough way, but ParserHelper instance is short-living, so we cannot use instance fields. Managing the counter in an external class seems to be too much for logging.

Comment on lines +692 to +702
public static void logHalfConstraintWarn(String message) {
if (logCounterHalfConstraint > 10) {
return; // suppress further warnings
}

logCounterHalfConstraint++;
LOG.warn(message);
if (logCounterHalfConstraint == 10) {
LOG.warn("Further warnings about half constraints will be suppressed.");
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The counter usage is repetitive in the log methods. I may be able to refactor them, but I guess it cannot be improved much. If you want me to refactor, I can try and share.

@@ -1558,6 +1558,7 @@ public AttributeDescr attribute(AttributeSupportBuilder<?> as) {
DroolsSoftKeywords.GROUP)) {
attribute = stringAttribute(as,
new String[]{DroolsSoftKeywords.AGENDA, "-", DroolsSoftKeywords.GROUP});
helper.logAgendaGroupWarn(attribute);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that DRL6Parser.java was generated from .g file in the past, and then has been maintained by hard-coding in the java file. So I add the logging directly, not modifying .g file.

Comment on lines +146 to +152
public static String replaceAgendaGroupIfRequired(String drl) {
if (DrlParser.ANTLR4_PARSER_ENABLED) {
// new parser (DRL10) supports only ruleflow-group, dropping agenda-group
return drl.replaceAll("agenda-group", "ruleflow-group");
}
return drl;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

replaceAgendaGroupIfRequired is defined in 3 places in this PR, because we don't have a common test util module which can access drools-drl-parser.

  • kie-test-util doesn't depend on any drools modules
  • drools-legacy-test-util is meant be 'legacy' (to be removed)

I think this topic should be separated from this PR and I will consult @pibizza .

fileSystem.write(resource);
}
fileSystem.writeKModuleXML(kieModuleModel.toXML());
return fileSystem;
}

private static Resource newResourceForNewParserIfRequired(Resource resource) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method is used for the new parser testing (not enabled by default). Actually, only to convert agenda-group to ruleflow-group because agenda-group is not allowed in DRL10, but it's widely used in the test cases (cannot manage with @DisabledIfSystemProperty). When we drop DRL6 in the future, we will be able to fully replace agenda-group in test cases and remove this conversion.

<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- drools-verifier doesn't support DRL10 -->
<skipTests>true</skipTests>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

DRLs in drools-verifier hit the dropped syntax in DRL10 (e.g. half constraint). I can fix them, but probably we want to discuss whether will keep maintaining drools-verifier or not. So I delay the fix for now.

@tkobayas tkobayas changed the title [DO-NOT-MERGE][WIP][incubator-kie-drools-6220] Slim down DRL syntax with New Antlr4 Parser [DO-NOT-MERGE][incubator-kie-drools-6220] Slim down DRL syntax with New Antlr4 Parser Feb 5, 2025
@tkobayas
Copy link
Contributor Author

tkobayas commented Feb 5, 2025

Hi @mariofusco @porcelli @gitgabrio @baldimir @mdproctor @pibizza ,

Here is the DRL10 syntax slim down.

As written in https://docs.google.com/document/d/1Ibmj-koAMbeaungHuFeQtw2zD03YJcNJkJ-kdN8ugks/edit?tab=t.0 ,

This PR does:

  • Introduce Language Level DRL10 (default is still DRL6)
  • Changes in DRL10 are
    • Drop half constraint
    • Custom operator requires a prefix ##
    • Drop || / && as alternatives to infix or / and (|| / && in constraint remain supported)
    • Drop annotation inside LHS Pattern (annotation in other places e.g. @watch remain supported)
    • Consolidate agenda-group to ruleflow-group
  • Log warnings when the deprecated syntax is used in DRL6
  • Log warnings when the deprecated Language Level DRL5 and DRL6_STRICT is used

The DRL10 introduction plan is #6221

Please review, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants