Skip to content

[WIP] PR for CI: Regions and other fun - #60

Closed
xFrednet wants to merge 41 commits into
regions-basefrom
regions-main
Closed

[WIP] PR for CI: Regions and other fun#60
xFrednet wants to merge 41 commits into
regions-basefrom
regions-main

Conversation

@xFrednet

Copy link
Copy Markdown
Collaborator

Volatile branch, most likely not worth reviewing yet

mjp41 and others added 10 commits July 14, 2025 16:42
* Adding region.c
* IDK something something regions and docs
* Docs and progress
* This is ugly but cleanup is tomorrow
* Nicer union-find code 🎉
* More and more progress
* parent -> owner rename
* More clenaup
* More fun!
* Something compiles I guess
* Why is there no formatter!!!
* Progres progress progresss
@xFrednet
xFrednet marked this pull request as draft July 23, 2025 12:34
@xFrednet

xFrednet commented Aug 1, 2025

Copy link
Copy Markdown
Collaborator Author

Status Update:

The current branch provides a new regions module to construct a Region object. Creating a new bridge object using the Region() constructor will also create a new region. The write barrier is implemented but isn't being called in most places. This results in the LRC and OSC being almost always wrong.

There is also a mechanism to mark all open regions as dirty, however, currently it is not being called, which makes regions remain clean.

Here is a working example:

from regions import Region, is_local
class A:
    pass

r1 = Region()
r2 = Region()

# Check ownership
r1.owns(r1) == True
r2.owns(r1) == False
is_local(r1) == False

# Dictionary assignments have some write barriers
a = A()
r1.a = a

is_local(a) == False
r1.owns(a) == True

The invariant can upper bound the LRC and OSC values and catches incorrect references.

These are the high level TODOs:

  • Add more methods to the Region type (dissove(), close(), is_dirty(), better repr etc)
  • Add more test for regions, methods and objects in the standard library
  • Handle name argument to Region constructor
  • Handle de-allocation of the bridge object (Merge into local and regiondata.name = NULL)
  • Add write barrier to dictionary and bytecode interpreter
  • Add a way to mark types and modules as Pyrona aware
  • Mark open regions as dirty, if Pyrona unaware C code is called
  • Store the bridge RC on close and validate the bridge RC on open, to detect dirty states on closed regions
  • Rebase cowns, and wire them up to regions
  • Support weak references, maybe include them in the LRC or add special handling for regions
  • Merging a region into the local region should open subregions, if the merge didn't happen for error handling

Current approach: Try to break the implementation in the REPL. On failure, add write barriers or do other fixes. Turn passing code into tests.


Bug 1:

>>> r.rr = regions.Region(name="two")
>>> r
<Region name='duck' _lrc=3 _osc=1 is_dirty=False>
>>> r.rr
<Region name='two' _lrc=1 _osc=0 is_dirty=False>
>>> 

The OSC of "duck" is not updated when "two" closes. Maybe because it doesn't close? o.O


Bug 2

import sys
import regions
r = regions.Region("duck")
sys.getrefcount(r)

This increases the RC but doesn't inform LRC


Bug 3

>>> r = Region()
>>> r
<Region name=None _lrc=2 _osc=0 is_dirty=False>
>>> r
<Region name=None _lrc=3 _osc=0 is_dirty=False>
>>> r
<Region name=None _lrc=4 _osc=0 is_dirty=False>

The rc is never decremented

@xFrednet xFrednet closed this Dec 1, 2025
@xFrednet
xFrednet deleted the regions-main branch December 1, 2025 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants