forked from M-Labs/artiq
1
0
Fork 0

compiler: quell excessively detailed diagnostics.

This commit is contained in:
whitequark 2016-02-25 19:43:52 +00:00
parent 8e77e561cd
commit 919a49b6bc
1 changed files with 19 additions and 15 deletions

View File

@ -694,42 +694,45 @@ class TypePrinter(object):
self.map = {} self.map = {}
self.recurse_guard = set() self.recurse_guard = set()
def name(self, typ): def name(self, typ, depth=0, max_depth=1):
typ = typ.find() typ = typ.find()
if isinstance(typ, TVar): if isinstance(typ, TVar):
if typ not in self.map: if typ not in self.map:
self.map[typ] = "'%s" % next(self.gen) self.map[typ] = "'%s" % next(self.gen)
return self.map[typ] return self.map[typ]
elif isinstance(typ, TInstance): elif isinstance(typ, TInstance):
if typ in self.recurse_guard: if typ in self.recurse_guard or depth >= max_depth:
return "<instance {}>".format(typ.name) return "<instance {}>".format(typ.name)
else: else:
self.recurse_guard.add(typ) self.recurse_guard.add(typ)
attrs = ", ".join(["{}: {}".format(attr, self.name(typ.attributes[attr])) attrs = ",\n\t\t".join(["{}: {}".format(attr, self.name(typ.attributes[attr],
depth + 1))
for attr in typ.attributes]) for attr in typ.attributes])
return "<instance {} {{{}}}>".format(typ.name, attrs) return "<instance {} {{\n\t\t{}\n\t}}>".format(typ.name, attrs)
elif isinstance(typ, TMono): elif isinstance(typ, TMono):
if typ.params == {}: if typ.params == {}:
return typ.name return typ.name
else: else:
return "%s(%s)" % (typ.name, ", ".join( 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): elif isinstance(typ, TTuple):
if len(typ.elts) == 1: if len(typ.elts) == 1:
return "(%s,)" % self.name(typ.elts[0]) return "(%s,)" % self.name(typ.elts[0], depth + 1)
else: 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)): elif isinstance(typ, (TFunction, TRPCFunction, TCFunction)):
args = [] args = []
args += [ "%s:%s" % (arg, self.name(typ.args[arg])) for arg in typ.args] args += [ "%s:%s" % (arg, self.name(typ.args[arg], depth + 1))
args += ["?%s:%s" % (arg, self.name(typ.optargs[arg])) for arg in typ.optargs] for arg in typ.args]
signature = "(%s)->%s" % (", ".join(args), self.name(typ.ret)) 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() delay = typ.delay.find()
if isinstance(delay, TVar): 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)): 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): if isinstance(typ, TRPCFunction):
return "[rpc #{}]{}".format(typ.service, signature) return "[rpc #{}]{}".format(typ.service, signature)
@ -740,11 +743,12 @@ class TypePrinter(object):
elif isinstance(typ, TBuiltinFunction): elif isinstance(typ, TBuiltinFunction):
return "<function {}>".format(typ.name) return "<function {}>".format(typ.name)
elif isinstance(typ, (TConstructor, TExceptionConstructor)): elif isinstance(typ, (TConstructor, TExceptionConstructor)):
if typ in self.recurse_guard: if typ in self.recurse_guard or depth >= max_depth:
return "<constructor {}>".format(typ.name) return "<constructor {}>".format(typ.name)
else: else:
self.recurse_guard.add(typ) 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]) for attr in typ.attributes])
return "<constructor {} {{{}}}>".format(typ.name, attrs) return "<constructor {} {{{}}}>".format(typ.name, attrs)
elif isinstance(typ, TBuiltin): elif isinstance(typ, TBuiltin):