3fbc15daa33c — Leonard Ritter 15 days ago
* `alloca`, `malloc`, `alloca-array` and `malloc-array` propagate view qualifier to generated types
* `Enum`, `Option`: fixed payload extraction not propagating view attributes correctly
4 files changed, 42 insertions(+), 13 deletions(-)

M lib/scopes/enum.sc
M src/prover.cpp
M src/qualifier/unique_qualifiers.cpp
M testing/test_option.sc
M lib/scopes/enum.sc +1 -1
@@ 34,7 34,7 @@ fn _extract-payload (enum-value extractT
             let ptrET = ('change-storage-class
                 ('mutable (pointer.type extractT)) 'Function)
             spice-quote
-                let ptr = (alloca payload-cls)
+                let ptr = (alloca (qualifiersof raw-payload))
                 store raw-payload ptr
                 let ptr = (bitcast ptr ptrET)
                 load ptr

          
M src/prover.cpp +29 -5
@@ 3005,8 3005,14 @@ repeat:
         case FN_Alloca: {
             CHECKARGS(1, 1);
             READ_TYPE_CONST(T);
-            auto op = Alloca::from(T);
-            op->hack_change_value(UNIQUETYPE1(op->get_type()));
+            auto ST = strip_qualifiers(T);
+            auto op = Alloca::from(ST);
+            auto vq = try_view(T);
+            if (vq) {
+                op->hack_change_value(view_type(op->get_type(), vq->ids));
+            } else {
+                op->hack_change_value(UNIQUETYPE1(op->get_type()));
+            }
             return TypedValueRef(call.anchor(), op);
         } break;
         case FN_AllocaArray: {

          
@@ 3014,15 3020,27 @@ repeat:
             READ_TYPE_CONST(T);
             READ_STORAGETYPEOF(size);
             SCOPES_CHECK_RESULT(verify_integer(size));
+            auto ST = strip_qualifiers(T);
             auto op = Alloca::from(T, _size);
-            op->hack_change_value(UNIQUETYPE1(op->get_type()));
+            auto vq = try_view(T);
+            if (vq) {
+                op->hack_change_value(view_type(op->get_type(), vq->ids));
+            } else {
+                op->hack_change_value(UNIQUETYPE1(op->get_type()));
+            }
             return TypedValueRef(call.anchor(), op);
         } break;
         case FN_Malloc: {
             CHECKARGS(1, 1);
             READ_TYPE_CONST(T);
+            auto ST = strip_qualifiers(T);
             auto op = Malloc::from(T);
-            op->hack_change_value(UNIQUETYPE1(op->get_type()));
+            auto vq = try_view(T);
+            if (vq) {
+                op->hack_change_value(view_type(op->get_type(), vq->ids));
+            } else {
+                op->hack_change_value(UNIQUETYPE1(op->get_type()));
+            }
             return TypedValueRef(call.anchor(), op);
         } break;
         case FN_MallocArray: {

          
@@ 3030,8 3048,14 @@ repeat:
             READ_TYPE_CONST(T);
             READ_STORAGETYPEOF(size);
             SCOPES_CHECK_RESULT(verify_integer(size));
+            auto ST = strip_qualifiers(T);
             auto op = Malloc::from(T, _size);
-            op->hack_change_value(UNIQUETYPE1(op->get_type()));
+            auto vq = try_view(T);
+            if (vq) {
+                op->hack_change_value(view_type(op->get_type(), vq->ids));
+            } else {
+                op->hack_change_value(UNIQUETYPE1(op->get_type()));
+            }
             return TypedValueRef(call.anchor(), op);
         } break;
         case FN_Free: {

          
M src/qualifier/unique_qualifiers.cpp +1 -0
@@ 155,6 155,7 @@ ViewQualifier::ViewQualifier(const IDSet
 void ViewQualifier::stream_prefix(StyledStream &ss) const {
     ss << "%";
     if (sorted_ids.empty()) {
+        ss << "?";
     } else {
         for (int i = 0; i < sorted_ids.size(); ++i) {
             if (i > 0) ss << "|";

          
M testing/test_option.sc +11 -7
@@ 4,17 4,21 @@ using import Option
 
 # Option unwrap method
 do
-    let optT = (Option i32)
-    let opt = (optT 1234)
+    let optT = (Option One)
+    let opt = (optT (One 1234))
     let opt2 = (optT)
     let result =
         try ('try-unwrap opt)
-        else 0
-    test (result == 1234)
+        else
+            error "unwrap failed"
+    test (result == (One 1234))
+    let fallback = (One 12345)
     let result =
-        try ('try-unwrap opt2)
-        else 12345
-    test (result == 12345)
+        try (deref ('try-unwrap opt2))
+        else (view fallback)
+    test (result == (One 12345))
+    ;
 
+One.test-refcount-balanced;
 
 ;
  No newline at end of file