Skip to content

Commit 8b67a92

Browse files
committed
Create explicit cown region
1 parent fa7570d commit 8b67a92

4 files changed

Lines changed: 17 additions & 14 deletions

File tree

src/rt/core.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ namespace rt::core
5858
class FuncObject : public objects::DynObject
5959
{
6060
public:
61-
FuncObject(objects::DynObject* prototype_)
62-
: objects::DynObject(prototype_)
61+
FuncObject(objects::DynObject* prototype_) : objects::DynObject(prototype_)
6362
{}
6463
};
6564

@@ -197,7 +196,7 @@ namespace rt::core
197196
{
198197
public:
199198
CownObject(objects::DynObject* region)
200-
: objects::DynObject(cownPrototypeObject())
199+
: objects::DynObject(cownPrototypeObject(), objects::cown_region)
201200
{
202201
// FIXME: Add once regions are reified
203202
// assert(
@@ -232,11 +231,6 @@ namespace rt::core
232231
// always be opaque.
233232
return true;
234233
}
235-
236-
bool is_cown() override
237-
{
238-
return true;
239-
}
240234
};
241235

242236
inline std::set<objects::DynObject*>* globals()

src/rt/objects/dyn_object.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ namespace rt::objects
7979
}
8080

8181
// prototype is borrowed, the caller does not need to provide an RC.
82-
DynObject(DynObject* prototype_ = nullptr, Region* containing_region = get_local_region())
82+
DynObject(
83+
DynObject* prototype_ = nullptr,
84+
Region* containing_region = get_local_region())
8385
: prototype(prototype_)
8486
{
8587
assert(containing_region != nullptr);
@@ -146,24 +148,24 @@ namespace rt::objects
146148
return false;
147149
}
148150

149-
virtual bool is_cown()
151+
bool is_cown()
150152
{
151-
return false;
153+
return region.get_ptr() == objects::cown_region;
152154
}
153155

154156
void freeze()
155157
{
156158
// TODO SCC algorithm
157159
visit(this, [](Edge e) {
158160
auto obj = e.target;
159-
if (!obj || obj->is_immutable())
161+
if (!obj || obj->is_immutable() || obj->is_cown())
160162
return false;
161163

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

166-
return !obj->is_cown();
168+
return true;
167169
});
168170
}
169171

src/rt/objects/region.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ namespace rt::objects
7777
if (target == immutable_region)
7878
return;
7979

80+
// Handle cown case
81+
if (target == cown_region)
82+
return;
83+
8084
if (src == get_local_region())
8185
{
8286
Region::dec_lrc(target);
@@ -152,7 +156,7 @@ namespace rt::objects
152156
{
153157
assert(src != nullptr);
154158
assert(dst != nullptr);
155-
if (target == nullptr || target->is_immutable())
159+
if (target == nullptr || target->is_immutable() || target->is_cown())
156160
return;
157161

158162
auto src_region = get_region(src);

src/rt/objects/region.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,7 @@ namespace rt::objects
181181

182182
inline Region immutable_region_impl;
183183
inline constexpr Region* immutable_region{&immutable_region_impl};
184+
185+
inline Region cown_region_impl;
186+
inline constexpr Region* cown_region{&cown_region_impl};
184187
} // namespace rt::objects

0 commit comments

Comments
 (0)