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

Prevent infinite loops #344

Open
Phrancis opened this issue Mar 26, 2015 · 11 comments
Open

Prevent infinite loops #344

Phrancis opened this issue Mar 26, 2015 · 11 comments
Labels
code-path-analysis Involves simulating execution paths / interpreting the user code ..to an extent. enhancement Feature requests, or enhancements to existing features. Ideas. Anything within the project's scope. feature-inspections

Comments

@Phrancis
Copy link

It can be easy to make a small error that causes an infinite loop, which can mess up things and crash the VBE. It would be nice if Rubberduck could catch an infinite loop at compile time (or at another time besides run time, whichever is most ideal).

@rubberduck203
Copy link
Member

👍

@retailcoder, shall we see how far we can push the parser? =;)-

@retailcoder
Copy link
Member

I read somewhere that ANTLR can evaluate conditions. I need to read up on it.

@retailcoder
Copy link
Member

If this inspection happens, expect a bunch of other ones too, like ConditionIsConstantInspection ("condition always evaluates to 'true'" or "condition always evaluates to 'false'"), and other things I can't think of at the moment.

@AndrewM-
Copy link

AndrewM- commented Oct 9, 2015

I mostly get this kind of error from setting up a do until .EOF loop for a recordset and forgetting to put in a .movenext.

@Vogel612
Copy link
Member

Vogel612 commented Oct 9, 2015

So there's separate kinds of infinite loops:

  • loops that have a constant end condition, that is never true (e.g. while true)
  • loops that have an end-condition that never becomes true (e.g. never advancing a recordset)

The earlier kind can be rather simply found by the Parser. In case of more complex expressions you could try to evaluate the loopcondition down.

The latter kind requires more intrinsic knowledge of the context. What's necessary here is a more in-depth analysis (think path-analysis)

@retailcoder
Copy link
Member

@Vogel612 even constant condition is trickier than it looks, mostly because VBA's lowest scope level is at the procedure level - it would be simpler if a For loop defined a scope.. we might have to simulate that to achieve proper inspection of variable references, by adding some ParserRuleContext ParentLoopContext constructor parameter to the IdentifierReference type.

@rubberduck203
Copy link
Member

We're getting into semantic analysis at this point. Are we in a position to really do that?

@retailcoder
Copy link
Member

@ckuhn203 not reliably. But we can try and pick up the obvious ...although usefulness (of picking up blatantly infinite loops) vs. effort required makes this a not very much appealing feature to build.

@retailcoder retailcoder added the code-path-analysis Involves simulating execution paths / interpreting the user code ..to an extent. label Jan 13, 2017
@Vogel612 Vogel612 added enhancement Feature requests, or enhancements to existing features. Ideas. Anything within the project's scope. and removed feature-request labels Aug 11, 2017
@zspitz
Copy link

zspitz commented Jul 11, 2018

I've just lost 2 hours of work because of a forgotten .MoveNext while iterating over a recordset.

@bclothier
Copy link
Contributor

I'm sorry to hear that, but are you aware that you don't need Rubberduck to bail you out -- just use Ctrl + Break to break the infinite loop. That would let you get into the code, and either stop or move the execution to some other line and resume or even add MoveNext while in the break mode.

@zspitz
Copy link

zspitz commented Jul 11, 2018

@bclothier Except that without DoEvents the VBE apparently no longer responds to Ctrl+Break in an infinite loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code-path-analysis Involves simulating execution paths / interpreting the user code ..to an extent. enhancement Feature requests, or enhancements to existing features. Ideas. Anything within the project's scope. feature-inspections
Projects
None yet
Development

No branches or pull requests

7 participants