Skip to content

Commit 9db199c

Browse files
author
whitequark
committedJul 23, 2015
Handle closure effects appropriately in LocalAccessValidator.
·
8.01.0rc1
1 parent acb8810 commit 9db199c

File tree

5 files changed

+16
-15
lines changed

5 files changed

+16
-15
lines changed
 

‎artiq/compiler/module.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ def __init__(self, source_buffer, engine=None):
3232
monomorphism_validator.visit(self.typedtree)
3333
escape_validator.visit(self.typedtree)
3434
self.artiq_ir = artiq_ir_generator.visit(self.typedtree)
35-
print(self.artiq_ir[0])
36-
print(self.artiq_ir[1])
3735
dead_code_eliminator.process(self.artiq_ir)
3836
local_access_validator.process(self.artiq_ir)
3937
self.llvm_ir = llvm_ir_generator.process(self.artiq_ir)

‎artiq/compiler/testbench/inferencer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def generic_visit(self, node):
4242
":{}".format(self.type_printer.name(node.type)))
4343

4444
def main():
45-
if sys.argv[1] == "+mono":
45+
if len(sys.argv) > 1 and sys.argv[1] == "+mono":
4646
del sys.argv[1]
4747
monomorphize = True
4848
else:

‎artiq/compiler/transforms/llvm_ir_generator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ def __init__(self, engine, module_name, context=ll.Context()):
1717
self.fixups = []
1818

1919
def llty_of_type(self, typ, bare=False, for_return=False):
20+
typ = typ.find()
2021
if types.is_tuple(typ):
21-
return ll.LiteralStructType([self.llty_of_type(eltty) for eltty in typ.find().elts])
22+
return ll.LiteralStructType([self.llty_of_type(eltty) for eltty in typ.elts])
2223
elif types.is_function(typ):
2324
envarg = ll.IntType(8).as_pointer()
2425
llty = ll.FunctionType(args=[envarg] +

‎artiq/compiler/validators/local_access.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,18 @@ def pred_at_fault(env, var_name):
9797
self._uninitialized_access(insn, var_name,
9898
pred_at_fault(env, var_name))
9999

100-
if isinstance(insn, ir.Closure):
101-
env = insn.environment()
102-
# Make sure this environment has any interesting variables.
103-
if env in block_state:
104-
for var_name in block_state[env]:
105-
if not block_state[env][var_name]:
106-
# A closure would capture this variable while it is not always
107-
# initialized. Note that this check is transitive.
108-
self._uninitialized_access(insn, var_name,
109-
pred_at_fault(env, var_name))
100+
# Creating a closure has no side effects. However, using a closure does.
101+
for operand in insn.operands:
102+
if isinstance(operand, ir.Closure):
103+
env = operand.environment()
104+
# Make sure this environment has any interesting variables.
105+
if env in block_state:
106+
for var_name in block_state[env]:
107+
if not block_state[env][var_name]:
108+
# A closure would capture this variable while it is not always
109+
# initialized. Note that this check is transitive.
110+
self._uninitialized_access(operand, var_name,
111+
pred_at_fault(env, var_name))
110112

111113
# Save the state.
112114
state[block] = block_state

‎lit-test/compiler/local_access/invalid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
-t
2121

2222
# CHECK-L: ${LINE:+1}: error: variable 't' can be captured in a closure uninitialized
23-
lambda: t
23+
l = lambda: t
2424

2525
# CHECK-L: ${LINE:+1}: error: variable 't' can be captured in a closure uninitialized
2626
def f():

0 commit comments

Comments
 (0)
Please sign in to comment.