#include #include #include void baseline() { string x = "hi"; string y = x; // construct y in same context, no write yet => no copy yet assert( y.inner->Handle.s == x.inner->Handle.s); sout | y; // hi x = "bye"; y = x; // y in same context, no write yet => no copy yet assert( y.inner->Handle.s == x.inner->Handle.s); sout | y; // bye } void eagerCopy() { string x = "hi"; string_sharectx c = { NEW_SHARING }; string y = x; // construct y in different context => eager copy assert( y.inner->Handle.s != x.inner->Handle.s); sout | y; // hi x = "bye"; //.... Bookmark 9/30 shallow: surprisingly this step failed y = x; // y was already in different context => eager copy assert( y.inner->Handle.s != x.inner->Handle.s); sout | y; // bye } void failSoloAlloc() { string x = "hi"; string_sharectx c = { NO_SHARING }; // want: allocation into private pad, with forced eager copy into it // got: assertion failure, "Need to implement private contexts" string y = x; } volatile bool showFail = false; int main() { baseline(); eagerCopy(); if (showFail) { failSoloAlloc(); } printf("done\n"); }