From 1c7b8b23ef6659ff73bbac372130e9f4ac219c9d Mon Sep 17 00:00:00 2001
From: Tim Warburton <timwar@caam.rice.edu>
Date: Wed, 2 Nov 2011 00:04:37 -0500
Subject: [PATCH] Better error messages when (attempting to) duplicate inames
 that don't exist.

---
 loopy/__init__.py | 21 ++++++++++++++++++++-
 loopy/cse.py      |  9 ++++++---
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/loopy/__init__.py b/loopy/__init__.py
index 6a6874873..2a619adcc 100644
--- a/loopy/__init__.py
+++ b/loopy/__init__.py
@@ -108,12 +108,31 @@ def make_kernel(*args, **kwargs):
     # }}}
 
     for insn in knl.instructions:
+        # {{{ sanity checking
+
+        if not set(insn.forced_iname_deps) <= knl.all_inames():
+            raise ValueError("In instruction '%s': "
+                    "cannot force dependency on inames '%s'--"
+                    "they don't exist" % (
+                        insn.id,
+                        ",".join(
+                            set(insn.forced_iname_deps)-knl.all_inames())))
+
+        # }}}
+
         # {{{ iname duplication
 
         if insn.duplicate_inames_and_tags:
-
             insn_dup_iname_to_tag = dict(insn.duplicate_inames_and_tags)
 
+            if not set(insn_dup_iname_to_tag.keys()) <= knl.all_inames():
+                raise ValueError("In instruction '%s': "
+                        "cannot duplicate inames '%s'--"
+                        "they don't exist" % (
+                            insn.id,
+                            ",".join(
+                                set(insn_dup_iname_to_tag.keys())-knl.all_inames())))
+
             # {{{ duplicate non-reduction inames
 
             reduction_inames = insn.reduction_inames()
diff --git a/loopy/cse.py b/loopy/cse.py
index f0a0b0f3b..d6af30b42 100644
--- a/loopy/cse.py
+++ b/loopy/cse.py
@@ -341,9 +341,12 @@ def realize_cse(kernel, cse_tag, dtype, independent_inames=[],
     """
 
     if not set(independent_inames) <= kernel.all_inames():
-        raise ValueError("cannot make iname '%s' independent--"
-                "they don't already exist" % ",".join(
-                    set(independent_inames)-kernel.all_inames()))
+        raise ValueError("In CSE realization for '%s': "
+                "cannot make inames '%s' independent--"
+                "they don't already exist" % (
+                    cse_tag,
+                    ",".join(
+                        set(independent_inames)-kernel.all_inames())))
 
     # {{{ process parallel_inames and ind_iname_to_tag arguments
 
-- 
GitLab