From a54b2b0ec354e6265f6583a747ba907ee166af0d Mon Sep 17 00:00:00 2001
From: Kaushik Kulkarni <kaushikcfd@gmail.com>
Date: Sat, 22 May 2021 19:49:15 -0500
Subject: [PATCH] specialize_fortran_division: account that the type of
 num/denom may not be inferred

---
 loopy/frontend/fortran/translator.py | 9 +++++++--
 loopy/type_inference.py              | 3 +--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/loopy/frontend/fortran/translator.py b/loopy/frontend/fortran/translator.py
index f13f63098..e04e2cb78 100644
--- a/loopy/frontend/fortran/translator.py
+++ b/loopy/frontend/fortran/translator.py
@@ -273,8 +273,13 @@ class FortranDivisionSpecializer(RuleAwareIdentityMapper):
 
     def map_fortran_division(self, expr, *args):
         # We remove all these before type inference ever sees them.
-        num_dtype = self.infer_type(expr.numerator).numpy_dtype
-        den_dtype = self.infer_type(expr.denominator).numpy_dtype
+        from loopy.type_inference import TypeInferenceFailure
+
+        try:
+            num_dtype = self.infer_type(expr.numerator).numpy_dtype
+            den_dtype = self.infer_type(expr.denominator).numpy_dtype
+        except TypeInferenceFailure:
+            return super().map_fortran_division(expr, *args)
 
         from pymbolic.primitives import Quotient, FloorDiv
         if num_dtype.kind in "iub" and den_dtype.kind in "iub":
diff --git a/loopy/type_inference.py b/loopy/type_inference.py
index d168848db..8b9b47f00 100644
--- a/loopy/type_inference.py
+++ b/loopy/type_inference.py
@@ -578,8 +578,7 @@ class TypeInferenceMapper(CombineMapper):
     def map_sub_array_ref(self, expr):
         return self.rec(expr.subscript)
 
-    def map_fortran_division(self, expr):
-        return []
+    map_fortran_division = map_quotient
 
 # }}}
 
-- 
GitLab