Skip to content

Fix start&top implementation in typechecker - #2551

Open
DavyLandman wants to merge 18 commits into
mainfrom
fix/start-symbol-issue-2496
Open

DavyLandman wants to merge 18 commits into
mainfrom
fix/start-symbol-issue-2496

Conversation

@DavyLandman

@DavyLandman DavyLandman commented Dec 3, 2025 •

Copy link
Copy Markdown
Member

This PR continues the work in #2499 (that was merged to main a bit too soon) to fix #2496

  • removes subtype relation between start[X] and X (in asubtype, alub, aglb)
  • removes subtype relation between start symbols and regular symbols (lists)
  • removes special cases for field selection and field update on .top
  • removes special cases for \start non-terminal whereever the contextFreeSyntax role is expected by adding a role field to the start AType
  • adds an implicit/automatic declaration, for every syntax rule for X that has a start modifier:
    • start production rule start[X] = X;
    • top field start[X] = X top;
    • layout wrapping start[X] = L X L;
  • removes more special cases in the back-end
  • removes missed special cases in the collector for pattern matching
  • removed API functions isStart* and getStart* that were used for detecting the old special cases

Together these changes solve a small number of known issues with start symbols, and a larger number of previously undetected issues.

@codecov

codecov Bot commented Dec 3, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 46%. Comparing base (b9b8b45) to head (8634417).

Additional details and impacted files
@@           Coverage Diff           @@
##              main   #2551   +/-   ##
=======================================
- Coverage       46%     46%   -1%     
- Complexity    6933    6937    +4     
=======================================
  Files          852     852           
  Lines        69363   69363           
  Branches     10112   10112           
=======================================
- Hits         32173   32171    -2     
- Misses       34756   34760    +4     
+ Partials      2434    2432    -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sonarqubecloud

sonarqubecloud Bot commented Feb 6, 2026

Copy link
Copy Markdown

@jurgenvinju jurgenvinju left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good. Needs an integration test.

@jurgenvinju jurgenvinju self-assigned this Apr 7, 2026
@jurgenvinju jurgenvinju added the bug label Apr 7, 2026
@jurgenvinju
jurgenvinju requested a review from PaulKlint April 17, 2026 08:22
@jurgenvinju
jurgenvinju marked this pull request as ready for review April 17, 2026 08:22
@sonarqubecloud

Copy link
Copy Markdown

@DavyLandman

Copy link
Copy Markdown
Member Author

@jurgenvinju this is your own code ;) I merely did some git cooking to extract it from a different PR.

@jurgenvinju

Copy link
Copy Markdown
Member

@PaulKlint should we use typepal's "predefine" functionality instead of constructing an artificial field location for "top"?

Same for the entire start rule. Should we use predefine for that as well?

@DavyLandman
DavyLandman force-pushed the fix/start-symbol-issue-2496 branch 2 times, most recently from 70579b4 to 1a8c413 Compare June 26, 2026 12:02
@sonarqubecloud

Copy link
Copy Markdown

DavyLandman pushed a commit to SWAT-engineering/bird that referenced this pull request Nov 13, 2026
This is a false negative by the current Rascal type-checker. The `.top` field only exists on implicitly generated start non-terminals like `start[Program]`. 

Refactored with semantic equivalence. But the rule for `start[Program]` is probably superfluous due to the recursive nature (automatic recursion) of `collect`.

Doing this fix now because the PR ( usethesource/rascal#2551 ) that fixes many false positives and false negatives with respect to start symbols will trigger a true positive here soon.

@PaulKlint PaulKlint left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall looks good ans simplifies things. I have a few comments:

  • There was code duplication introduced in CollectSyntaxDeclaration. Moved this to ComputeType
  • A test in ChangeAndHashScenarios was changed. I disagree. It is also related to errors in integration tests (see below)
  • In some places the indentation was namgled (immature formatter?), I have restored it manually.

The following errors in the integration tests should be fixed first:

[ERROR] src/org/rascalmpl/library/lang/rascal/tests/concrete/Syntax1.rsc:0010:000: Duplicate declaration of nonterminal `start(aadt("A",[],contextFreeSyntax()),contextFreeSyntax())`
    * src/org/rascalmpl/library/lang/rascal/tests/concrete/Syntax1.rsc:0009:000: First declaration of nonterminal `start(aadt("A",[],contextFreeSyntax()),contextFreeSyntax())`
    * src/org/rascalmpl/library/lang/rascal/tests/concrete/Syntax1.rsc:0010:000: Second declaration of nonterminal `start(aadt("A",[],contextFreeSyntax()),contextFreeSyntax())`
[ERROR] src/org/rascalmpl/library/lang/rascal/tests/concrete/Syntax1.rsc: Duplicate declaration of production ``
    * src/org/rascalmpl/library/lang/rascal/tests/concrete/Syntax1.rsc: First declaration of production ``
    * src/org/rascalmpl/library/lang/rascal/tests/concrete/Syntax1.rsc: Second declaration of production ``
[ERROR] src/org/rascalmpl/library/lang/rascal/tests/concrete/Syntax1.rsc: Duplicate declaration of field `top`
    * src/org/rascalmpl/library/lang/rascal/tests/concrete/Syntax1.rsc: First declaration of field `top`
    * src/org/rascalmpl/library/lang/rascal/tests/concrete/Syntax1.rsc: Second declaration of field `top`
[ERROR] src/org/rascalmpl/library/lang/rascal/tests/concrete/Syntax1.rsc:0013:000: Duplicate declaration of nonterminal `start(aadt("B",[],contextFreeSyntax()),contextFreeSyntax())`
    * src/org/rascalmpl/library/lang/rascal/tests/concrete/Syntax1.rsc:0012:000: First declaration of nonterminal `start(aadt("B",[],contextFreeSyntax()),contextFreeSyntax())`
    * src/org/rascalmpl/library/lang/rascal/tests/concrete/Syntax1.rsc:0013:000: Second declaration of nonterminal `start(aadt("B",[],contextFreeSyntax()),contextFreeSyntax())`
[ERROR] src/org/rascalmpl/library/lang/rascal/tests/concrete/Syntax1.rsc: Duplicate declaration of production ``
    * src/org/rascalmpl/library/lang/rascal/tests/concrete/Syntax1.rsc: First declaration of production ``
    * src/org/rascalmpl/library/lang/rascal/tests/concrete/Syntax1.rsc: Second declaration of production ``
[ERROR] src/org/rascalmpl/library/lang/rascal/tests/concrete/Syntax1.rsc: Duplicate declaration of field `top`
    * src/org/rascalmpl/library/lang/rascal/tests/concrete/Syntax1.rsc: First declaration of field `top`
    * src/org/rascalmpl/library/lang/rascal/tests/concrete/Syntax1.rsc: Second declaration of field `top`

@sonarqubecloud

sonarqubecloud Bot commented Dec 5, 2026

Copy link
Copy Markdown

@PaulKlint

Copy link
Copy Markdown
Member

Progress ... down to two errors in integration tests:

[ERROR] src/org/rascalmpl/tutor/lang/rascal/tutor/conversions/TrimDoc.rsc:0015:031: Cannot call `editModule` with arguments of types `Module`, given definitions `void(loc) or void(start[Module])`
[ERROR] rascal-lsp/src/main/rascal/lsp/lang/rascal/lsp/refactor/rename/Modules.rsc:082:029: No definition found for field or keywordfield `top` in type `Tree`

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tree of start[A] declared as A

3 participants