Skip to content

Commit

Permalink
[mycpp refactor] Simplify translation and fix test harness.
Browse files Browse the repository at this point in the history
Thinking about how to root tuple entries.
  • Loading branch information
Andy C committed Nov 21, 2022
1 parent cedc868 commit 8ad4c76
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 39 deletions.
32 changes: 14 additions & 18 deletions mycpp/TEST.sh
Expand Up @@ -86,20 +86,15 @@ examples-variant() {
log "$num_failed of $num_tests tests failed"
log ''

case $variant in
(gcevery)
if test $num_failed -ne 5; then
# echo "FAIL: Expected 5 failures with GC_EVERY_ALLOC"
return 0 # not an error with -D RET_VAL_ROOTING
fi
;;
(*)
if test $num_failed -ne 0; then
echo "FAIL: Expected no failures, got $num_failed"
return 1
fi
;;
esac
# TODO: fix failure and remove this
if test $variant = 'gcevery'; then
return 0
fi

if test $num_failed -ne 0; then
echo "FAIL: Expected no failures, got $num_failed"
return 1
fi

return 0
}
Expand Down Expand Up @@ -261,20 +256,21 @@ test-runtime() {
test-translator() {
### Invoked by soil/worker.sh

# examples-variant '' rvroot

examples-variant '' asan

# Test with more collections -- 5 failures above
# Test with more collections
examples-variant '' gcevery

run-test-func test-invalid-examples _test/mycpp/test-invalid-examples.log

# Runs test in cxx-asan variant, and benchmarks in cxx-opt variant
# Runs tests in cxx-asan variant, and benchmarks in cxx-opt variant
if ! ninja mycpp-logs-equal; then
log 'FAIL mycpp-logs-equal'
return 1
fi

# Write _test/mycpp-examples.html, used by soil/woker.sh
find-dir-html _test mycpp-examples
}

unit-test-coverage() {
Expand Down
37 changes: 16 additions & 21 deletions mycpp/cppgen_pass.py
Expand Up @@ -298,7 +298,7 @@ def __init__(self, types: Dict[Expression, Type], const_lookup, f,
self.local_var_list = [] # Collected at assignment
self.prepend_to_block = None # For writing vars after {
self.current_func_node = None
self.in_return_expr = False # to return tuples by value
self.return_tuple_value = False # to return tuples by value

# This is cleared when we start visiting a class. Then we visit all the
# methods, and accumulate the types of everything that looks like
Expand Down Expand Up @@ -1074,19 +1074,14 @@ def visit_tuple_expr(self, o: 'mypy.nodes.TupleExpr') -> T:
assert c_type.endswith('*'), c_type
c_type = c_type[:-1] # HACK TO CLEAN UP

maybe_new = c_type if self.in_return_expr else 'Alloc<%s>' % c_type
if len(o.items) == 0:
self.write('(%s())' % maybe_new)
else:
# Use initialize list. Lists are MUTABLE so we can't pull them to
# the top level.
self.write('(%s(' % maybe_new)
for i, item in enumerate(o.items):
if i != 0:
self.write(', ')
self.accept(item)
# TODO: const_lookup
self.write('))')
maybe_new = c_type if self.return_tuple_value else 'Alloc<%s>' % c_type
self.write('(%s(' % maybe_new)
for i, item in enumerate(o.items):
if i != 0:
self.write(', ')
self.accept(item)
# TODO: const_lookup
self.write('))')

def visit_set_expr(self, o: 'mypy.nodes.SetExpr') -> T:
pass
Expand Down Expand Up @@ -2594,30 +2589,30 @@ def visit_return_stmt(self, o: 'mypy.nodes.ReturnStmt') -> T:

if CTypeIsManaged(c_ret_type):
self.write_ind('%s ret_tmp = ', c_ret_type)
self.in_return_expr = True
self.accept(o.expr)
self.in_return_expr = False
self.write(';\n')

self.write_ind('gHeap.RootOnReturn(reinterpret_cast<Obj*>(ret_tmp));\n')
self.write_ind('return ret_tmp;\n')
return

# e.g. return my_int + 3;
# Examples:
# return
# return None
# return my_int + 3;
# return '', None # tuple
self.write_ind('return ')
if o.expr:
self.in_return_expr = True
self.return_tuple_value = True
self.accept(o.expr)
self.in_return_expr = False
self.return_tuple_value = False
self.write(';\n')
return

# OLD StackRoots
self.write_ind('return ')
if o.expr:
self.in_return_expr = True
self.accept(o.expr)
self.in_return_expr = False
self.write(';\n')

def visit_assert_stmt(self, o: 'mypy.nodes.AssertStmt') -> T:
Expand Down

0 comments on commit 8ad4c76

Please sign in to comment.