From ab780f66ef67ea0333278d75e4af064bcae71c57 Mon Sep 17 00:00:00 2001 From: Saem Ghani Date: Tue, 2 Mar 2021 01:32:43 -0800 Subject: [PATCH] fixes #17198, DFA failure on large case stmts (#17210) This alters the DFA control flow graph generation for case statments. Gotos are now generated as a chained link, this ensures that evaluation of variant branches collapses as early as possible, without hitting the 2k call limit. --- compiler/dfa.nim | 11 ++++++++--- tests/destructor/t17198.nim | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 tests/destructor/t17198.nim diff --git a/compiler/dfa.nim b/compiler/dfa.nim index 517d138317..c7a9d46944 100644 --- a/compiler/dfa.nim +++ b/compiler/dfa.nim @@ -455,6 +455,10 @@ proc genCase(c: var Con; n: PNode) = let isExhaustive = skipTypes(n[0].typ, abstractVarRange-{tyTypeDesc}).kind notin {tyFloat..tyFloat128, tyString} + # we generate endings as a set of chained gotos, this is a bit awkward but it + # ensures when recursively traversing the CFG for various analysis, we don't + # artificially extended the life of each branch (for the purposes of DFA) + # beyond the minimum amount. var endings: seq[TPosition] = @[] c.gen(n[0]) for i in 1..