From 60c2a1b4b86fe20601dd910a9699f1718838e7f0 Mon Sep 17 00:00:00 2001 From: Charlotte Date: Thu, 29 Jun 2023 11:15:31 +1000 Subject: [PATCH] sim._pyrtl: don't blow parser stack on older Pythons. Python pre-3.9 can't handle parentheses nested this deeply. * https://github.com/amaranth-lang/amaranth/pull/681 -- motivating example. * https://github.com/amaranth-lang/amaranth/pull/827 -- what added enough extra parentheses to make this only break now. * https://peps.python.org/pep-0617/ -- new parser as of 3.9. --- amaranth/sim/_pyrtl.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/amaranth/sim/_pyrtl.py b/amaranth/sim/_pyrtl.py index d9787ff..0fa23af 100644 --- a/amaranth/sim/_pyrtl.py +++ b/amaranth/sim/_pyrtl.py @@ -83,7 +83,11 @@ class _ValueCompiler(ValueVisitor, _Compiler): "simulate in reasonable time" .format(src, len(value))) - return super().on_value(value) + v = super().on_value(value) + if isinstance(v, str) and len(v) > 1000: + # Avoid parser stack overflow on older Pythons. + return self.emitter.def_var("intermediate", v) + return v def on_ClockSignal(self, value): raise NotImplementedError # :nocov: