From bfabca494bd1d3dc0ddd163f41229f1054de8f49 Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 2 Jul 2015 22:55:08 +0300 Subject: [PATCH] Remove regions from types. Unification-based inference for regions is useful with a language that has let bindings (which would propagate the regions) and functions polymorphic over regions. For reasons of simplicity, ARTIQ has neither, and making unification-based inference work would essentially mean adding region coercions between most AST nodes, and having every source subexpression have its own region variable, with the appropriate subtyping relationship. It's simpler to just keep that state outside of typedtree. --- artiq/compiler/module.py | 2 ++ artiq/compiler/types.py | 11 ++++------- artiq/compiler/validators/escape.py | 10 ++++++++++ 3 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 artiq/compiler/validators/escape.py diff --git a/artiq/compiler/module.py b/artiq/compiler/module.py index d5d21391b..2b847eb27 100644 --- a/artiq/compiler/module.py +++ b/artiq/compiler/module.py @@ -15,6 +15,7 @@ class Module: inferencer = transforms.Inferencer(engine=engine) int_monomorphizer = transforms.IntMonomorphizer(engine=engine) monomorphism_validator = validators.MonomorphismValidator(engine=engine) + escape_validator = validators.EscapeValidator(engine=engine) parsetree, comments = parse_buffer(source_buffer, engine=engine) typedtree = asttyped_rewriter.visit(parsetree) @@ -22,6 +23,7 @@ class Module: int_monomorphizer.visit(typedtree) inferencer.visit(typedtree) monomorphism_validator.visit(typedtree) + escape_validator.visit(typedtree) self.name = os.path.basename(source_buffer.name) self.globals = asttyped_rewriter.globals diff --git a/artiq/compiler/types.py b/artiq/compiler/types.py index 47d6f055b..7e8c611f6 100644 --- a/artiq/compiler/types.py +++ b/artiq/compiler/types.py @@ -82,8 +82,8 @@ class TMono(Type): attributes = {} - def __init__(self, name, params={}, region=None): - self.name, self.params, self.region = name, params, region + def __init__(self, name, params={}): + self.name, self.params = name, params def find(self): return self @@ -125,7 +125,6 @@ class TTuple(Type): """ attributes = {} - region = None def __init__(self, elts=[]): self.elts = elts @@ -171,8 +170,8 @@ class TFunction(Type): attributes = {} - def __init__(self, args, optargs, ret, region=None): - self.args, self.optargs, self.ret, self.region = args, optargs, ret, region + def __init__(self, args, optargs, ret): + self.args, self.optargs, self.ret = args, optargs, ret def arity(self): return len(self.args) + len(self.optargs) @@ -219,8 +218,6 @@ class TBuiltin(Type): type is treated specially according to its name. """ - region = None - def __init__(self, name): self.name = name self.attributes = {} diff --git a/artiq/compiler/validators/escape.py b/artiq/compiler/validators/escape.py new file mode 100644 index 000000000..4f02b1b7c --- /dev/null +++ b/artiq/compiler/validators/escape.py @@ -0,0 +1,10 @@ +""" +:class:`EscapeValidator` verifies that no mutable data escapes +the region of its allocation. +""" + +from pythonparser import algorithm, diagnostic +from .. import asttyped, types, builtins + +class EscapeValidator(algorithm.Visitor): + pass