From 919a49b6bc5d731b09d08a6aba26442c8834df0d Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 25 Feb 2016 19:43:52 +0000 Subject: [PATCH] compiler: quell excessively detailed diagnostics. --- artiq/compiler/types.py | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/artiq/compiler/types.py b/artiq/compiler/types.py index f5adf79e5..460c07ae7 100644 --- a/artiq/compiler/types.py +++ b/artiq/compiler/types.py @@ -694,42 +694,45 @@ class TypePrinter(object): self.map = {} self.recurse_guard = set() - def name(self, typ): + def name(self, typ, depth=0, max_depth=1): typ = typ.find() if isinstance(typ, TVar): if typ not in self.map: self.map[typ] = "'%s" % next(self.gen) return self.map[typ] elif isinstance(typ, TInstance): - if typ in self.recurse_guard: + if typ in self.recurse_guard or depth >= max_depth: return "".format(typ.name) else: self.recurse_guard.add(typ) - attrs = ", ".join(["{}: {}".format(attr, self.name(typ.attributes[attr])) - for attr in typ.attributes]) - return "".format(typ.name, attrs) + attrs = ",\n\t\t".join(["{}: {}".format(attr, self.name(typ.attributes[attr], + depth + 1)) + for attr in typ.attributes]) + return "".format(typ.name, attrs) elif isinstance(typ, TMono): if typ.params == {}: return typ.name else: return "%s(%s)" % (typ.name, ", ".join( - ["%s=%s" % (k, self.name(typ.params[k])) for k in typ.params])) + ["%s=%s" % (k, self.name(typ.params[k], depth + 1)) for k in typ.params])) elif isinstance(typ, TTuple): if len(typ.elts) == 1: - return "(%s,)" % self.name(typ.elts[0]) + return "(%s,)" % self.name(typ.elts[0], depth + 1) else: - return "(%s)" % ", ".join(list(map(self.name, typ.elts))) + return "(%s)" % ", ".join([self.name(typ, depth + 1) for typ in typ.elts]) elif isinstance(typ, (TFunction, TRPCFunction, TCFunction)): args = [] - args += [ "%s:%s" % (arg, self.name(typ.args[arg])) for arg in typ.args] - args += ["?%s:%s" % (arg, self.name(typ.optargs[arg])) for arg in typ.optargs] - signature = "(%s)->%s" % (", ".join(args), self.name(typ.ret)) + args += [ "%s:%s" % (arg, self.name(typ.args[arg], depth + 1)) + for arg in typ.args] + args += ["?%s:%s" % (arg, self.name(typ.optargs[arg], depth + 1)) + for arg in typ.optargs] + signature = "(%s)->%s" % (", ".join(args), self.name(typ.ret, depth + 1)) delay = typ.delay.find() if isinstance(delay, TVar): - signature += " delay({})".format(self.name(delay)) + signature += " delay({})".format(self.name(delay, depth + 1)) elif not (delay.is_fixed() and iodelay.is_zero(delay.duration)): - signature += " " + self.name(delay) + signature += " " + self.name(delay, depth + 1) if isinstance(typ, TRPCFunction): return "[rpc #{}]{}".format(typ.service, signature) @@ -740,11 +743,12 @@ class TypePrinter(object): elif isinstance(typ, TBuiltinFunction): return "".format(typ.name) elif isinstance(typ, (TConstructor, TExceptionConstructor)): - if typ in self.recurse_guard: + if typ in self.recurse_guard or depth >= max_depth: return "".format(typ.name) else: self.recurse_guard.add(typ) - attrs = ", ".join(["{}: {}".format(attr, self.name(typ.attributes[attr])) + attrs = ", ".join(["{}: {}".format(attr, self.name(typ.attributes[attr], + depth + 1)) for attr in typ.attributes]) return "".format(typ.name, attrs) elif isinstance(typ, TBuiltin):