Skip to content

Commit

Permalink
Create explicit cown region
Browse files Browse the repository at this point in the history
  • Loading branch information
mjp41 committed Oct 25, 2024
1 parent fa7570d commit 8b67a92
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
10 changes: 2 additions & 8 deletions src/rt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ namespace rt::core
class FuncObject : public objects::DynObject
{
public:
FuncObject(objects::DynObject* prototype_)
: objects::DynObject(prototype_)
FuncObject(objects::DynObject* prototype_) : objects::DynObject(prototype_)
{}
};

Expand Down Expand Up @@ -197,7 +196,7 @@ namespace rt::core
{
public:
CownObject(objects::DynObject* region)
: objects::DynObject(cownPrototypeObject())
: objects::DynObject(cownPrototypeObject(), objects::cown_region)
{
// FIXME: Add once regions are reified
// assert(
Expand Down Expand Up @@ -232,11 +231,6 @@ namespace rt::core
// always be opaque.
return true;
}

bool is_cown() override
{
return true;
}
};

inline std::set<objects::DynObject*>* globals()
Expand Down
12 changes: 7 additions & 5 deletions src/rt/objects/dyn_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ namespace rt::objects
}

// prototype is borrowed, the caller does not need to provide an RC.
DynObject(DynObject* prototype_ = nullptr, Region* containing_region = get_local_region())
DynObject(
DynObject* prototype_ = nullptr,
Region* containing_region = get_local_region())
: prototype(prototype_)
{
assert(containing_region != nullptr);
Expand Down Expand Up @@ -146,24 +148,24 @@ namespace rt::objects
return false;
}

virtual bool is_cown()
bool is_cown()
{
return false;
return region.get_ptr() == objects::cown_region;
}

void freeze()
{
// TODO SCC algorithm
visit(this, [](Edge e) {
auto obj = e.target;
if (!obj || obj->is_immutable())
if (!obj || obj->is_immutable() || obj->is_cown())
return false;

auto r = get_region(obj);
get_region(obj)->objects.erase(obj);
obj->region.set_ptr(immutable_region);

return !obj->is_cown();
return true;
});
}

Expand Down
6 changes: 5 additions & 1 deletion src/rt/objects/region.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ namespace rt::objects
if (target == immutable_region)
return;

// Handle cown case
if (target == cown_region)
return;

if (src == get_local_region())
{
Region::dec_lrc(target);
Expand Down Expand Up @@ -152,7 +156,7 @@ namespace rt::objects
{
assert(src != nullptr);
assert(dst != nullptr);
if (target == nullptr || target->is_immutable())
if (target == nullptr || target->is_immutable() || target->is_cown())
return;

auto src_region = get_region(src);
Expand Down
3 changes: 3 additions & 0 deletions src/rt/objects/region.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,7 @@ namespace rt::objects

inline Region immutable_region_impl;
inline constexpr Region* immutable_region{&immutable_region_impl};

inline Region cown_region_impl;
inline constexpr Region* cown_region{&cown_region_impl};
} // namespace rt::objects

0 comments on commit 8b67a92

Please sign in to comment.