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

Phase 3: Py_CHECKWRITE -> write barrier todo list #10

Open
11 of 64 tasks
xFrednet opened this issue Nov 27, 2024 · 4 comments
Open
11 of 64 tasks

Phase 3: Py_CHECKWRITE -> write barrier todo list #10

xFrednet opened this issue Nov 27, 2024 · 4 comments
Assignees

Comments

@xFrednet
Copy link
Collaborator

xFrednet commented Nov 27, 2024

An extract of all Py_CHECKWRITE() calls which need to be adjusted for the write barrier. (From the phase3 branch)

Objects/abstract.c (owner @TobiasWrigstad)

  • Line 224: if(!Py_CHECKWRITE(o)){
  • Line 236: if(!Py_CHECKWRITE(o)){
  • Line 268: if(!Py_CHECKWRITE(o)){
  • Line 280: if(!Py_CHECKWRITE(o)){
  • Line 395: if(!Py_CHECKWRITE(obj)){
  • Line 429: if((flags & PyBUF_WRITABLE) && !Py_CHECKWRITE(obj)){
  • Line 1224: if(!Py_CHECKWRITE(v)){
  • Line 1270: if(!Py_CHECKWRITE(v)){
  • Line 1861: if(!Py_CHECKWRITE(s)){
  • Line 1894: if (!Py_CHECKWRITE(o)){
  • Line 1985: if (!Py_CHECKWRITE(s)){
  • Line 2023: if(!Py_CHECKWRITE(s)){
  • Line 2061: if (!Py_CHECKWRITE(s)){
  • Line 2089: if(!Py_CHECKWRITE(s)){

Python/generated_cases.c.h

  • Line 1923: if (!Py_CHECKWRITE(cell)){
  • Line 1999: if(!Py_CHECKWRITE(cell)){
  • Line 2723: if (!Py_CHECKWRITE(owner))
  • Line 2759: if (!Py_CHECKWRITE(owner))
  • Line 2818: if (!Py_CHECKWRITE(owner))

Objects/setobject.c

  • Line 637: if(!Py_CHECKWRITE(so)){
  • Line 936: if(!Py_CHECKWRITE(so)){
  • Line 1118: if(!Py_CHECKWRITE(so)){
  • Line 1845: if(!Py_CHECKWRITE(so)){
  • Line 1898: if(!Py_CHECKWRITE(so)){
  • Line 1934: if(!Py_CHECKWRITE(so)){
  • Line 2319: if(!Py_CHECKWRITE(set)){
  • Line 2345: if(!Py_CHECKWRITE(set)){
  • Line 2362: if(!Py_CHECKWRITE(anyset)){

Objects/listobject.c

  • Line 270: if(!Py_CHECKWRITE(op)){
  • Line 323: if (!Py_CHECKWRITE(op)){
  • Line 348: if (!Py_CHECKWRITE(op)){
  • Line 754: if(!Py_CHECKWRITE(a)){
  • Line 821: if (!Py_CHECKWRITE(self)){
  • Line 840: if (!Py_CHECKWRITE(self)){
  • Line 874: if (!Py_CHECKWRITE(self)){
  • Line 904: if(!Py_CHECKWRITE(self)){
  • Line 1058: if(!Py_CHECKWRITE(self)){
  • Line 2311: if (!Py_CHECKWRITE(self)){
  • Line 2588: if (!Py_CHECKWRITE(self)){
  • Line 2607: if (!Py_CHECKWRITE(v)){
  • Line 2740: if (!Py_CHECKWRITE(self)){

Objects/dictobject.c (@mjp41 owner)

  • Line 1241: if (!Py_CHECKWRITE(mp)){
  • Line 1359: if (!Py_CHECKWRITE(mp)){
  • Line 2088: if(!Py_CHECKWRITE(op)){
  • Line 2156: if(!Py_CHECKWRITE(op)){
  • Line 2799: if(!Py_CHECKWRITE(self)){
  • Line 3399: if(!Py_CHECKWRITE(d)){
  • Line 3510: if(!Py_CHECKWRITE(mp)){
  • Line 3535: if(!Py_CHECKWRITE(self)){
  • Line 3560: if(!Py_CHECKWRITE(self)){
  • Line 5553: if(!Py_CHECKWRITE(obj)){

Objects/object.c (@TobiasWrigstad owner -- see #26)

  • Line 1176: if(Py_CHECKWRITE(v)){
  • Line 1193: if(Py_CHECKWRITE(v)){
  • Line 1639: if(!Py_CHECKWRITE(obj)){

Objects/tupleobject.c (@TobiasWrigstad owner -- see #46)

  • Line 121: if (!Py_CHECKWRITE(op)){

Objects/cellobject.c (@xFrednet owner)

  • Line 71: (!Py_CHECKWRITE(op)){
  • Line 131: if(!Py_CHECKWRITE(op)){
  • Line 154: if(!Py_CHECKWRITE(op)){

Python/bytecodes.c (@xFrednet owner)

  • Line 1414: if (!Py_CHECKWRITE(cell)){
  • Line 1474: if(!Py_CHECKWRITE(cell)){
  • Line 1969: if (!Py_CHECKWRITE(owner))
  • Line 1996: if (!Py_CHECKWRITE(owner))
  • Line 2046: if (!Py_CHECKWRITE(owner))

Include/cpython/listobject.h

  • Line 43: if (_Py_IsImmutable(op)){ // _Py_CHECKWRITE(op) is not available

cc: @mjp41 @TobiasWrigstad

@mjp41
Copy link
Owner

mjp41 commented Dec 3, 2024

Based on looking through I think we might want

PY_REGIONCHECKINSERT(src, newtgt);
PY_REGIONCHECKREMOVE(src, oldtgt);
PY_REGIONCHECKREPLACE(src, oldtgt, newtgt);
PY_REGIONCHECKREPLACEUNKNOWN(src, newtgt); // Used when we lose precision

There are places I have found that only add or remove, e.g. clearing the dictionary only performs remove.

@xFrednet
Copy link
Collaborator Author

xFrednet commented Dec 3, 2024

Tiny nit: I think by convention the y in Py should be lower case.

I assume with // Used when we lose precision you mean we mark regions as dirty? So we lose our guarantees until we reestablish them?

@mjp41
Copy link
Owner

mjp41 commented Dec 3, 2024

Yeah, I had changed to Py locally when I started typing, but good catch.

Yes, lose precision, is the region is dirty, and might not satisfy the invariant.

I also after trying to use these macros for a few minutes think they need to change. I think we need variandic macros:

With the macros above, if we want to support backing out a failure, then we would need to write something like:

    if (!Py_REGIONCHECKINSERT(mp, key)) {
        goto Fail;
    }

    if (!Py_REGIONCHECKINSERT(mp, value)) {
        Py_REGIONCHECKREMOVE(mp, key);
        goto Fail;
    }

If we had a variadic insert, we could write

    if (!Py_REGIONCHECKINSERT(mp, key, value)) {
        goto Fail;
    }

So, I am trying my changes with this kind of alternative now, which would internally do the back tracking (or at least could be made to).

@xFrednet
Copy link
Collaborator Author

xFrednet commented Dec 3, 2024

Maybe relevant for the fail:

I'm currently creating a draft/dummy RegionException. I think later we want to distinguish between different types of Pyrona errors. Including an indicator if the system is in a valid state after the exception.

These checks should usually leave the system in a valid state, but cleaning might fail and have invalid references remain afterwards

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

No branches or pull requests

3 participants