forked from M-Labs/artiq
1
0
Fork 0

Unbreak tests.

This commit is contained in:
whitequark 2015-08-18 22:44:09 -07:00
parent 6c8de9b6d4
commit 51c591f01a
7 changed files with 25 additions and 21 deletions

View File

@ -201,9 +201,8 @@ def is_collection(typ):
types.is_mono(typ, "list") types.is_mono(typ, "list")
def is_allocated(typ): def is_allocated(typ):
return typ.fold(False, lambda accum, typ: return not (is_none(typ) or is_bool(typ) or is_int(typ) or
accum or not (is_none(typ) or is_bool(typ) or is_int(typ) or is_float(typ) or is_range(typ) or
is_float(typ) or is_range(typ) or types.is_c_function(typ) or types.is_rpc_function(typ) or
types.is_c_function(typ) or types.is_rpc_function(typ) or types.is_method(typ) or types.is_tuple(typ) or
types.is_method(typ) or types.is_value(typ))
types.is_value(typ)))

View File

@ -1411,15 +1411,15 @@ class ARTIQIRGenerator(algorithm.Visitor):
return ir.Constant(None, builtins.TNone()) return ir.Constant(None, builtins.TNone())
elif types.is_exn_constructor(typ): elif types.is_exn_constructor(typ):
return self.alloc_exn(node.type, *[self.visit(arg_node) for arg_node in node.args]) return self.alloc_exn(node.type, *[self.visit(arg_node) for arg_node in node.args])
elif types.is_constructor(typ):
return self.append(ir.Alloc([], typ.instance))
else: else:
assert False assert False
def visit_CallT(self, node): def visit_CallT(self, node):
typ = node.func.type.find() typ = node.func.type.find()
if types.is_constructor(typ) and not types.is_exn_constructor(typ): if types.is_builtin(typ):
return self.append(ir.Alloc([], typ.instance))
elif types.is_builtin(typ):
return self.visit_builtin_call(node) return self.visit_builtin_call(node)
else: else:
if types.is_function(typ): if types.is_function(typ):

View File

@ -705,6 +705,12 @@ class Inferencer(algorithm.Visitor):
pass pass
else: else:
diagnose(valid_forms()) diagnose(valid_forms())
elif types.is_constructor(typ):
# An user-defined class.
self._unify(node.type, typ.find().instance,
node.loc, None)
else:
assert False
def visit_CallT(self, node): def visit_CallT(self, node):
self.generic_visit(node) self.generic_visit(node)
@ -722,10 +728,6 @@ class Inferencer(algorithm.Visitor):
if types.is_var(typ): if types.is_var(typ):
return # not enough info yet return # not enough info yet
elif types.is_constructor(typ) and not types.is_exn_constructor(typ):
self._unify(node.type, typ.find().instance,
node.loc, None)
return
elif types.is_builtin(typ): elif types.is_builtin(typ):
return self.visit_builtin_call(node) return self.visit_builtin_call(node)
elif not (types.is_function(typ) or types.is_method(typ)): elif not (types.is_function(typ) or types.is_method(typ)):

View File

@ -391,7 +391,7 @@ class LLVMIRGenerator:
assert llinsn is not None assert llinsn is not None
self.llmap[insn] = llinsn self.llmap[insn] = llinsn
if insn.loc is not None: if insn.loc is not None and not isinstance(llinsn, ll.Constant):
diloc = self.debug_info_emitter.emit_loc(insn.loc, disubprogram) diloc = self.debug_info_emitter.emit_loc(insn.loc, disubprogram)
llinsn.set_metadata('dbg', diloc) llinsn.set_metadata('dbg', diloc)

View File

@ -99,8 +99,8 @@ class TMono(Type):
attributes = OrderedDict() attributes = OrderedDict()
def __init__(self, name, params={}): def __init__(self, name, params={}):
assert isinstance(params, dict) assert isinstance(params, (dict, OrderedDict))
self.name, self.params = name, params self.name, self.params = name, OrderedDict(sorted(params.items()))
def find(self): def find(self):
return self return self

View File

@ -7,6 +7,9 @@ import functools
from pythonparser import algorithm, diagnostic from pythonparser import algorithm, diagnostic
from .. import asttyped, types, builtins from .. import asttyped, types, builtins
def has_region(typ):
return typ.fold(False, lambda accum, typ: accum or builtins.is_allocated(typ))
class Region: class Region:
""" """
A last-in-first-out allocation region. Tied to lexical scoping A last-in-first-out allocation region. Tied to lexical scoping
@ -78,7 +81,7 @@ class RegionOf(algorithm.Visitor):
# Value lives as long as the current scope, if it's mutable, # Value lives as long as the current scope, if it's mutable,
# or else forever # or else forever
def visit_sometimes_allocating(self, node): def visit_sometimes_allocating(self, node):
if builtins.is_allocated(node.type): if has_region(node.type):
return self.youngest_region return self.youngest_region
else: else:
return None return None
@ -89,7 +92,7 @@ class RegionOf(algorithm.Visitor):
# Value lives as long as the object/container, if it's mutable, # Value lives as long as the object/container, if it's mutable,
# or else forever # or else forever
def visit_accessor(self, node): def visit_accessor(self, node):
if builtins.is_allocated(node.type): if has_region(node.type):
return self.visit(node.value) return self.visit(node.value)
else: else:
return None return None
@ -131,7 +134,7 @@ class RegionOf(algorithm.Visitor):
# Value lives forever # Value lives forever
def visit_immutable(self, node): def visit_immutable(self, node):
assert not builtins.is_allocated(node.type) assert not has_region(node.type)
return None return None
visit_NameConstantT = visit_immutable visit_NameConstantT = visit_immutable
@ -217,7 +220,7 @@ class EscapeValidator(algorithm.Visitor):
self.youngest_env = {} self.youngest_env = {}
for name in typing_env: for name in typing_env:
if builtins.is_allocated(typing_env[name]): if has_region(typing_env[name]):
self.youngest_env[name] = Region(None) # not yet known self.youngest_env[name] = Region(None) # not yet known
else: else:
self.youngest_env[name] = None # lives forever self.youngest_env[name] = None # lives forever

View File

@ -15,5 +15,5 @@ c.a
# CHECK-L: .f:()->NoneType # CHECK-L: .f:()->NoneType
c.f c.f
# CHECK-L: .m:method(self=c, fn=(self:c)->NoneType) # CHECK-L: .m:method(fn=(self:c)->NoneType, self=c)
c().m() c().m()