about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-03-24 11:38:36 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-03-24 11:38:36 -0700
commit3589c440a872f6e622d9fe62af83b4fe69114add (patch)
treed58be59995e27bf24147a7cf7dcc21abbc476302
parent6bed086e87f6bc5d90699e8ddad97eb8bf05371a (diff)
downloadmu-3589c440a872f6e622d9fe62af83b4fe69114add.tar.gz
2810 - undo 2767, reclaiming local allocations
I realize that there's still a serious problem with refcounts.
Everything's fine as long as I copy those shared addresses manually
elsewhere, but there's a couple of places where I just do a memcopy
right now without any extra smarts: in 'copy' and 'merge' instructions.

I need to replace support for arbitrary types in these instructions, and
replace it with transforms to generate the right code. Mu basically
needs copy constructors and destructors, so that containers can
decrement the refcounts of any elements (or elements of elements, or
elements of elements of elements..) that are shared addresses.

But my confidence in this whole approach is shaken. Maybe I should stop
this project. It's turning into a language+OS design project where I was
hoping that being a toy would shelter me from these concerns. I just
want to explore turning manual tests into reproducible automatic ones.
Maybe I should just build libraries for each interface to hardware
(network, disk, screen, keyboard, ...) in C++11 or something. Use no
high-level libraries for sockets, files, etc. Instead rely on just the
kernel syscalls, memory allocator, RAII, STL. Build things from scratch
atop those building blocks.
-rw-r--r--043space.cc45
1 files changed, 25 insertions, 20 deletions
diff --git a/043space.cc b/043space.cc
index 06cd09b1..51c84af6 100644
--- a/043space.cc
+++ b/043space.cc
@@ -211,12 +211,13 @@ def foo [
 # both calls to foo should have received the same default-space
 +mem: storing 1 in location 3
 
-:(scenario local_scope_frees_up_allocations)
-def main [
-  local-scope
-  x:address:shared:array:character <- new [abc]
-]
-+mem: clearing x:address:shared:array:character
+:(code)  // pending test
+//? :(scenario local_scope_frees_up_allocations)
+//? def main [
+//?   local-scope
+//?   x:address:shared:array:character <- new [abc]
+//? ]
+//? +mem: clearing x:address:shared:array:character
 
 //: todo: do this in a transform, rather than magically in the reply instruction
 :(after "Falling Through End Of Recipe")
@@ -240,20 +241,24 @@ void try_reclaim_locals() {
   const instruction& inst = exiting_recipe.steps.at(0);
   if (inst.old_name != "local-scope") return;
   // reclaim any local variables unless they're being returned
-  vector<double> zero;
-  zero.push_back(0);
-  for (int i = /*leave default space for last*/1; i < SIZE(exiting_recipe.steps); ++i) {
-    const instruction& inst = exiting_recipe.steps.at(i);
-    for (int i = 0; i < SIZE(inst.products); ++i) {
-      if (!is_mu_address(inst.products.at(i))) continue;
-      // local variables only
-      if (has_property(inst.products.at(i), "space")) continue;
-      if (has_property(inst.products.at(i), "lookup")) continue;
-      if (escaping(inst.products.at(i))) continue;
-      trace(9999, "mem") << "clearing " << inst.products.at(i).original_string << end();
-      write_memory(inst.products.at(i), zero);
-    }
-  }
+  // TODO: this isn't working yet. Doesn't handle address:shared stored in
+  // containers created by 'copy' or 'merge'. We'd end up deleting the address
+  // even if some container containing it was returned.
+  // This might doom our whole refcounting-based approach :/
+//?   vector<double> zero;
+//?   zero.push_back(0);
+//?   for (int i = /*leave default space for last*/1; i < SIZE(exiting_recipe.steps); ++i) {
+//?     const instruction& inst = exiting_recipe.steps.at(i);
+//?     for (int i = 0; i < SIZE(inst.products); ++i) {
+//?       if (!is_mu_address(inst.products.at(i))) continue;
+//?       // local variables only
+//?       if (has_property(inst.products.at(i), "space")) continue;
+//?       if (has_property(inst.products.at(i), "lookup")) continue;
+//?       if (escaping(inst.products.at(i))) continue;
+//?       trace(9999, "mem") << "clearing " << inst.products.at(i).original_string << end();
+//?       write_memory(inst.products.at(i), zero);
+//?     }
+//?   }
   abandon(current_call().default_space,
           /*refcount*/1 + /*array length*/1 + /*number-of-locals*/Name[r][""]);
 }
'>266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519