Skip to content

Commit 4ac8cea

Browse files
authored
Merge pull request #61 from fxpl/disable-default-implicit-freeze
Disable implicit freezing by default
2 parents 3ba4ae4 + 12a7f12 commit 4ac8cea

12 files changed

+23
-29
lines changed

Diff for: docs/builtin.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ Dissolves the given region into the local region. The bridge object will lose th
6161

6262
## Pragmas
6363

64-
#### `pragma_disable_implicit_freezing()`
64+
#### `pragma_enable_implicit_freezing()`
6565

66-
Disables implicit freezing for the rest of the program.
66+
Enables implicit freezing for the rest of the program.
6767

6868
#### `pragma_mermaid_draw_regions_nested(bool)`
6969

Diff for: src/rt/core/builtin.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,12 @@ namespace rt::core
338338

339339
void pragma_builtins()
340340
{
341-
add_builtin("pragma_disable_implicit_freezing", [](auto, auto args) {
341+
add_builtin("pragma_enable_implicit_freezing", [](auto, auto args) {
342342
if (args != 0)
343343
{
344-
ui::error("pragma_disable_implicit_freezing() expected 0 arguments");
344+
ui::error("pragma_enable_implicit_freezing() expected 0 arguments");
345345
}
346-
objects::Region::pragma_implicit_freezing = false;
346+
objects::Region::pragma_implicit_freezing = true;
347347
return std::nullopt;
348348
});
349349

Diff for: src/rt/objects/prototype_object.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace rt::objects
1212
PrototypeObject(
1313
std::string name_,
1414
objects::DynObject* prototype = nullptr,
15-
objects::Region* region = objects::get_local_region())
15+
objects::Region* region = objects::immutable_region)
1616
: objects::DynObject(prototype, region), name(name_)
1717
{}
1818

Diff for: src/rt/objects/region.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace rt::objects
3232
static inline thread_local std::set<Region*> dirty_regions{};
3333

3434
/// Indicates if implicit freezing is enabled
35-
static inline bool pragma_implicit_freezing = true;
35+
static inline bool pragma_implicit_freezing = false;
3636

3737
// The local reference count is the number of references to objects in the
3838
// region from local region. Using non-zero LRC for subregions ensures we

Diff for: tests/cowns/cown_from_immutable.frank

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
# Create two regions
2-
r1 = Region()
3-
r2 = Region()
4-
5-
# Create unfrozen data to share
1+
# Create a value to share
62
share = {}
7-
share.text = "Shared Info"
8-
r1.info = share
93

10-
# Trigger implicit freeze by referencing it from r2
11-
r2.info = share
4+
# Freeze the value to make sure it can be put in a cown
5+
freeze(share)
126

137
# Should succeed, as 'share' is now immutable
14-
c = Cown(move share)
8+
c = Cown(share)

Diff for: tests/regions/fail_cross_region_ref.frank

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
pragma_disable_implicit_freezing()
2-
31
# Root a
42
a = Region()
53

Diff for: tests/regions/implicit_freeze_1.frank

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
pragma_enable_implicit_freezing()
2+
13
# Create two regions
24
r1 = Region()
35
r2 = Region()

Diff for: tests/regions/implicit_freeze_2.frank

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
pragma_enable_implicit_freezing()
2+
13
# Create two regions
24
r1 = Region()
35
r2 = Region()

Diff for: tests/regions/merge_bad_3.frank

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
pragma_disable_implicit_freezing()
21
r1 = Region()
32
r2 = Region()
43
r1.r2 = r2

Diff for: tests/regions/region_bad_1.frank

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
pragma_disable_implicit_freezing()
2-
31
# Fails: can't add anything but the bridge object to a region
42
r = Region()
53
a = {}

Diff for: tests/regions/region_bad_2.frank

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
pragma_disable_implicit_freezing()
2-
31
# Fails: can't add anything but the bridge object to a region
42
r = Region()
53
r2 = Region()
@@ -13,4 +11,4 @@ r2.b = b
1311
# Make a reference b, which is fine while local object
1412
a.b = b
1513
# Fails: can't add anything but the bridge object to a region
16-
r.a = a
14+
r.a = a

Diff for: tests/regions/region_close_fail_1.frank

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# Construct regions
22
r1 = Region()
33

4-
# Create a local string to share the `String` prototype
5-
local_string = "Hello Local"
4+
# Create a prototype
5+
local_ty = {}
66

7-
# This also moves the `String` prototype
8-
r1.something = "Important string"
7+
# Create a local object to share the `local_ty` prototype
8+
local_value = create(local_ty)
9+
10+
# Create a value in the region, this also moves the `local_ty` prototype
11+
r1.region_value = create(local_ty)
912

1013
# This should fail, since implicit freezing is disabled
1114
close(r1)

0 commit comments

Comments
 (0)