Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mermaid: Small adjustments #47

Merged
merged 10 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/buildci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
jobs:
build:
runs-on: ${{ matrix.os }}
timeout-minutes: 10

strategy:
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
Expand Down Expand Up @@ -56,6 +57,7 @@ jobs:

format:
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ set_property(TEST leak_with_global.vpy PROPERTY WILL_FAIL true)
set_property(TEST invalid_read.vpy PROPERTY WILL_FAIL true)
set_property(TEST invalid_shared_region.vpy PROPERTY WILL_FAIL true)
set_property(TEST invalid_write.vpy PROPERTY WILL_FAIL true)
set_property(TEST fail_cross_region_reg.vpy PROPERTY WILL_FAIL true)
set_property(TEST invalid_child_region.vpy PROPERTY WILL_FAIL true)
set_property(TEST invalid_not_bridge.vpy PROPERTY WILL_FAIL true)
set_property(TEST region_bad_1.vpy PROPERTY WILL_FAIL true)
set_property(TEST region_bad_2.vpy PROPERTY WILL_FAIL true)
set_property(TEST fail_cross_region_ref.vpy PROPERTY WILL_FAIL true)
14 changes: 11 additions & 3 deletions docs/builtin.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Aborts the interpreter process. It's intended to indicate that an execution bran

## Constructors

#### `region()`
#### `Region()`

Creates a new region object.

Expand Down Expand Up @@ -74,12 +74,20 @@ This explicitly shows the "Cown region" in the generated diagrams.

#### `mermaid_hide_cown_region()`

This hides the "Cown region" and cown prototype in diagram. (This is the default)
This hides the "Cown region" and cown prototype in diagram. (Default)

#### `mermaid_show_immutable_region()`

This explicitly shows the "Immutable region" in the generated diagrams

#### `mermaid_hide_immutable_region()`

This hides the "Immutable region" in diagram. (Default)

#### `mermaid_show_functions()`

Shows user defined functions in the diagram.

#### `mermaid_hide_functions()`

Hides user defined functions in the diagram. (This is the default)
Hides user defined functions in the diagram. (Default)
25 changes: 15 additions & 10 deletions src/rt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,24 @@ namespace rt::core
class CownObject : public objects::DynObject
{
public:
CownObject(objects::DynObject* region)
CownObject(objects::DynObject* bridge)
: objects::DynObject(cownPrototypeObject(), objects::cown_region)
{
// FIXME: Add once regions are reified
// assert(
// region->get_prototype() == regionPrototype() &&
// "Cowns can only store regions");
//
// FIXME: Also check that the region has a LRC == 1, with 1
// being the reference passed into this constructor
auto region = objects::get_region(bridge);
if (region->bridge != bridge)
{
std::stringstream ss;
ss << bridge << " is not the bridge object of the region";
ui::error(ss.str(), bridge);
}

if (region->local_reference_count > 1)
{
ui::error("The given region has a LRC > 1", bridge);
}

// this->set would fail, since this is a cown
this->fields["value"] = region;
this->fields["value"] = bridge;
}

std::string get_name() override
Expand All @@ -233,7 +238,7 @@ namespace rt::core
{
static std::set<objects::DynObject*>* globals =
new std::set<objects::DynObject*>{
objects::regionObjectPrototypeObject(),
objects::regionPrototypeObject(),
framePrototypeObject(),
funcPrototypeObject(),
bytecodeFuncPrototypeObject(),
Expand Down
13 changes: 13 additions & 0 deletions src/rt/core/builtin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,19 @@ namespace rt::core
return std::nullopt;
});

add_builtin(
"mermaid_show_immutable_region", [mermaid](auto, auto, auto args) {
assert(args == 0);
mermaid->draw_immutable_region = true;
return std::nullopt;
});
add_builtin(
"mermaid_hide_immutable_region", [mermaid](auto, auto, auto args) {
assert(args == 0);
mermaid->draw_immutable_region = false;
return std::nullopt;
});

add_builtin("mermaid_show_functions", [mermaid](auto, auto, auto args) {
assert(args == 0);
mermaid->show_functions();
Expand Down
19 changes: 17 additions & 2 deletions src/rt/objects/region.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace rt::objects
return false;
}

if (obj->get_prototype() != objects::regionObjectPrototypeObject())
if (obj->get_prototype() != objects::regionPrototypeObject())
{
ui::error("Cannot add interior region object to another region");
}
Expand Down Expand Up @@ -133,7 +133,7 @@ namespace rt::objects
return;
}

if (target->get_prototype() != objects::regionObjectPrototypeObject())
if (target->get_prototype() != objects::regionPrototypeObject())
{
ui::error("Cannot add interior region object to another region");
}
Expand Down Expand Up @@ -251,4 +251,19 @@ namespace rt::objects
return obj;
}

void Region::action(Region* r)
{
if ((r->local_reference_count == 0) && (r->parent == nullptr))
{
// TODO, this can be hooked to perform delayed operations like send.
// Needs to check for sub_region_reference_count for send, but not
// deallocate.

if (r != get_local_region() && r != cown_region)
{
to_collect.push_back(r);
std::cout << "Collecting region: " << r << std::endl;
}
}
}
}
19 changes: 4 additions & 15 deletions src/rt/objects/region.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,7 @@ namespace rt::objects
return local_reference_count + sub_region_reference_count;
}

static void action(Region* r)
{
if ((r->local_reference_count == 0) && (r->parent == nullptr))
{
// TODO, this can be hooked to perform delayed operations like send.
// Needs to check for sub_region_reference_count for send, but not
// deallocate.

to_collect.push_back(r);
std::cout << "Collecting region: " << r << std::endl;
}
}
static void action(Region*);

static void dec_lrc(Region* r)
{
Expand Down Expand Up @@ -117,9 +106,9 @@ namespace rt::objects
// Check if already parented to another region.
if (r->parent != nullptr)
{
// FIXME: Highlight, once regions have been reified
ui::error(
"Region already has a parent: Creating region DAG not supported!");
"Region already has a parent: Creating region DAG not supported!",
r->bridge);
}

// Prevent creating a cycle
Expand All @@ -129,7 +118,7 @@ namespace rt::objects
if (ancestors == r)
{
// FIXME: Highlight, once regions have been reified
ui::error("Cycle created in region hierarchy");
ui::error("Cycle created in region hierarchy", r->bridge);
}
ancestors = ancestors->parent;
}
Expand Down
20 changes: 15 additions & 5 deletions src/rt/objects/region_object.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#pragma once

#include "prototype_object.h"
#include "region.h"

namespace rt::objects
{
// The prototype object for region entry point objects
inline PrototypeObject* regionObjectPrototypeObject()
inline PrototypeObject* regionPrototypeObject()
{
static PrototypeObject* proto = new PrototypeObject("RegionObject");
return proto;
Expand All @@ -14,8 +15,17 @@ namespace rt::objects
class RegionObject : public DynObject
{
public:
RegionObject(Region* region)
: DynObject(regionObjectPrototypeObject(), region)
{}
RegionObject(Region* region) : DynObject(regionPrototypeObject(), region) {}

std::string get_name() override
{
auto region = get_region(this);

std::stringstream stream;
stream << this << std::endl;
stream << "lrc=" << region->local_reference_count << std::endl;
stream << "sbrc=" << region->sub_region_reference_count;
return stream.str();
}
};
}
}
2 changes: 1 addition & 1 deletion src/rt/rt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ namespace rt
{
// TODO Add some checking. This is need to lookup the correct function in
// the prototype chain.
if (key->get_prototype() != core::stringPrototypeObject())
if (key && key->get_prototype() != core::stringPrototypeObject())
{
ui::error("Key must be a string.", key);
}
Expand Down
2 changes: 2 additions & 0 deletions src/rt/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ namespace rt::ui
std::set<rt::objects::DynObject*> taint;
/// Indicates if the cown region show be explicitly drawn
bool draw_cown_region;
bool draw_immutable_region;
/// Indicates if local functions should be visible
bool draw_funcs;
bool highlight_unreachable = true;

std::vector<objects::DynObject*> error_objects;
std::vector<objects::Edge> error_edges;
Expand Down
Loading
Loading