Skip to content

499 avoid exponential loop handling clean#501

Open
hiker wants to merge 7 commits intomasterfrom
499_avoid_exponential_loop_handling_clean
Open

499 avoid exponential loop handling clean#501
hiker wants to merge 7 commits intomasterfrom
499_avoid_exponential_loop_handling_clean

Conversation

@hiker
Copy link
Copy Markdown
Collaborator

@hiker hiker commented Apr 21, 2026

Fixes the exponential behaviour with number of non-blocked loops in one Fortran unit. This is done by detecting when searching for a blocked loop in e.g.:

      do 10 i=1, 10
 10     a(i) = i

That the statement with label 10 indicates that there is no matching 10 enddo (or continue) statement coming, and therefore abooting earlier.

It cuts down parse time for a socrates file that was not parsed in 40 minutes(!!) down to 7 seconds.

Problem: I don't know how to test this patch. During development, the existing tests have flagged some issues I had, so the code is definitely used, and would trigger a failed test if it is really broken. But I don't really know how to test if it triggers as expected (since the function itself would return None without this patch as well ... just later)

Suggestions welcome

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.21%. Comparing base (a197a85) to head (869c01c).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #501   +/-   ##
=======================================
  Coverage   92.21%   92.21%           
=======================================
  Files          87       87           
  Lines       13832    13843   +11     
=======================================
+ Hits        12755    12766   +11     
  Misses       1077     1077           

☔ View full report in Codecov by Sentry.
📢 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.

@hiker
Copy link
Copy Markdown
Collaborator Author

hiker commented Apr 21, 2026

While this indeed fixes the issue, it is only fixed for the 2003 standard. Fab uses (by default) F2008, and F2008 still runs forever 😢

@hiker
Copy link
Copy Markdown
Collaborator Author

hiker commented Apr 21, 2026

Ah, fixing F2008 was actually trivial :)

Ready for a first review.

@hiker
Copy link
Copy Markdown
Collaborator Author

hiker commented Apr 21, 2026

I actually got an idea for testing: adding an invalid/not-parsable Fortran statement after a loop - if a do loop is parsed without error, it means that the error wasn't reached, and therefore it stopped early. Marking this as 'in progress' again :)

@hiker
Copy link
Copy Markdown
Collaborator Author

hiker commented Apr 21, 2026

An incorrect statement didn't really work, but I could just check the error message when blocking doesn't parse. If it points at the labeled statement that finished a non-blocked loop, the shortcut works. If it points at the end of the file, it doesn't - hooray ;)

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.

1 participant