about summary refs log tree commit diff stats
path: root/073deep_copy.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-07-03 01:19:14 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-07-03 01:19:14 -0700
commit14ef940425c921b8881810756a0ef8aa952a77fb (patch)
tree87b5c6b1b8edb9da93fab79d3aa03ff4b3eed560 /073deep_copy.cc
parentf9deca54ce78a81c196547422be7ef0e4b57ec29 (diff)
downloadmu-14ef940425c921b8881810756a0ef8aa952a77fb.tar.gz
3086
More tests, another bugfix. I still don't *really* understand why it
works, though..

The new tests aren't really done yet. No assertions, lots of debug info.
Just translated from sandboxes. deep_copy_stress_test_2 requires the
bugfix.
Diffstat (limited to '073deep_copy.cc')
-rw-r--r--073deep_copy.cc94
1 files changed, 93 insertions, 1 deletions
diff --git a/073deep_copy.cc b/073deep_copy.cc
index 9fb96483..5ddb29fd 100644
--- a/073deep_copy.cc
+++ b/073deep_copy.cc
@@ -185,7 +185,7 @@ int deep_copy_address(const reagent& canonized_in, map<int, int>& addresses_copi
     return get(addresses_copied, in_address);
   reagent/*copy*/ payload = canonized_in;
   payload.properties.push_back(pair<string, string_tree*>("lookup", NULL));
-  int out = allocate(size_of(payload));
+  int out = allocate(payload_size(payload));
   put(addresses_copied, in_address, out);
   reagent/*copy*/ payload_type = payload;
   canonize_type(payload_type);
@@ -241,3 +241,95 @@ void deep_copy(const reagent& canonized_in, map<int, int>& addresses_copied, con
     }
   }
 }
+
+//: moar tests, just because I can't believe it all works
+
+:(scenario deep_copy_stress_test_1)
+container foo1 [
+  p:address:number
+]
+container foo2 [
+  p:address:foo1
+]
+exclusive-container foo3 [
+  p:address:foo1
+  q:address:foo2
+]
+def main [
+  local-scope
+  x:address:number <- new number:type  # 1003 -> 1014 1015
+  *x <- copy 34
+  a:address:foo1 <- new foo1:type  # 1004 -> 1016 1017
+  *a <- merge x  # refcount 1014: 1 -> 2
+  b:address:foo2 <- new foo2:type  # 1005 -> 1018 1019
+  *b <- merge a  # refcount 1016: 1 -> 2
+  c:foo3 <- merge 1/q, b  # 1006 1007; refcount 1018: 1 -> 2
+  d:foo3 <- deep-copy c  # 1008 1009
+    # temporary: 1020 1021
+    # c:foo3: 1/tag@1006 1018@1007
+      # alloc: 1022 1023
+      # foo2: refcount@1018 1016@1019
+        # alloc: 1024 1025
+        # foo1: refcount@1016 1014@1017
+          # alloc: 1026 1027
+          # number: 34@1015
+          # write: 34@1027
+        # write: 1026@1025
+      # write: 1024@1023
+    # write 1/tag@1008 1022@1009
+  e:address:foo2, z:boolean <- maybe-convert d, q:variant  # write: 1022@1010
+  f:address:foo1 <- get *e, p:offset  # write: 1024@1012
+  g:address:number <- get *f, p:offset  # write: 1026@1013
+  1:number/raw <- copy *g  # 1 -> 34
+]
++mem: storing 34 in location 1
+
+:(scenario deep_copy_stress_test_2)
+container foo1 [
+  p:address:number
+]
+container foo2 [
+  p:address:foo1
+]
+exclusive-container foo3 [
+  p:address:foo1
+  q:address:foo2
+]
+container foo4 [
+  p:number
+  q:address:foo3
+]
+def main [
+  local-scope
+  x:address:number <- new number:type  # 1003 -> 1016 1017
+  *x <- copy 34
+  a:address:foo1 <- new foo1:type  # 1004 -> 1018 1019
+  *a <- merge x  # refcount 1016: 1 -> 2
+  b:address:foo2 <- new foo2:type  # 1005 -> 1020 1021
+  *b <- merge a  # refcount 1018: 1 -> 2
+  c:address:foo3 <- new foo3:type  # 1006 -> 1022 1023 1024
+  *c <- merge 1/q, b  # refcount 1020: 1 -> 2
+  d:foo4 <- merge 35, c  # 1007 1008; refcount 1022: 1 -> 2
+  e:foo4 <- deep-copy d  # 1009 1010
+    # temporary: 1025 1026
+    # foo4: 35@1007 1022@1008
+      # alloc: 1027 1028
+      # foo3: 1/tag@1023 1020@1024
+        # alloc: 1029 1030  <<--- wrong
+        # foo2: 1018@1021
+          # alloc: 1031 1032
+          # foo1: 1016@1019
+            # alloc: 1033 1034
+            # number: 34@1017
+            # write 34@1034
+          # write 1033@1032 (refcount 1033: 0 -> 1)
+        # write 1031@1030 (refcount 1031: 0 -> 1)
+      # write should be 1/tag@1029 1029@1028 (refcount 1030: 0 -> 1)
+      # write is 1@1028 1029@1029
+  f:address:foo3 <- get e, q:offset  # write: 1027@1011
+  g:address:foo2, z:boolean <- maybe-convert *f, q:variant  # write: 1030@1012
+  h:address:foo1 <- get *g, p:offset  # write: 1@1014
+  y:address:number <- get *h, p:offset  # write: 0@1015
+  1:number/raw <- copy *y  # write: 0@1
+]
++mem: storing 34 in location 1