bfc icon indicating copy to clipboard operation
bfc copied to clipboard

bfc hangs due to compile-time evaluation

Open BambooL opened this issue 6 years ago • 4 comments

I am trying to compile the following code with bfc -O2: . + [[ [[ >. [+ [<>]]] >]<>+ .]>< ,-.,,+++[]---]

But it shows warning:

24852.bf:1:26 warning: This instruction moves the pointer after the last cell (99999), to cell 100000.
  . + [[ [[ >. [+ [<>]]] >]<>+ .]>< ,-.,,+++[]---]
                         ^

But no exit. It should fall into some infinite loop or similar things.

BambooL avatar Jun 24 '19 15:06 BambooL

Another similar problem is also found when compiling:

-[+ >>>.><-[--<]-->.+.--],[><--[.]-]- [] >>- <-,>,

it shows the warning but the compilation is not stopping.

BambooL avatar Jun 25 '19 21:06 BambooL

This looks like an issue where we aggressively unroll the loop due to compile-time evaluation, send a huge amount of IR to LLVM, and then it spends ages trying to optimise the IR.

I've added an undocumented BFC_MAX_STEPS which limits the execution steps and thus the LLVM IR size. Nonetheless, execution steps are still fast, it's the IR munging afterwards that's taking the time.

Possibly related: #26.

Wilfred avatar Jun 26 '19 00:06 Wilfred

Since the issue is addressed by the owner. I will close this thread.

BambooL avatar Jun 26 '19 22:06 BambooL

I think this a genuine bug worth fixing, so I'm going to reopen this :)

Wilfred avatar Jun 30 '19 11:06 Wilfred