[Git][ghc/ghc][wip/js-staging] remove unused STM check invariants
Luite Stegeman (@luite)
gitlab at gitlab.haskell.org
Fri Oct 14 12:00:38 UTC 2022
Luite Stegeman pushed to branch wip/js-staging at Glasgow Haskell Compiler / GHC
Commits:
663cee6c by Luite Stegeman at 2022-10-14T14:00:28+02:00
remove unused STM check invariants
- - - - -
2 changed files:
- compiler/GHC/StgToJS/Rts/Rts.hs
- rts/js/stm.js
Changes:
=====================================
compiler/GHC/StgToJS/Rts/Rts.hs
=====================================
@@ -629,46 +629,8 @@ rts' s =
(appS "h$stmCommitTransaction" []
<> adjSpN' 2
<> returnS (stack .! sp))
- (push' s [var "h$checkInvariants_e"]
- <> returnS (app "h$stmStartTransaction" [stack .! (sp - 2)])))
- , closure (ClosureInfo "h$checkInvariants_e" (CIRegs 0 [PtrV]) "check transaction invariants" (CILayoutFixed 0 []) CIStackFrame mempty)
- (adjSpN' 1
- <> returnS (app "h$stmCheckInvariants" []))
- , closure (ClosureInfo "h$stmCheckInvariantStart_e" (CIRegs 0 []) "start checking invariant" (CILayoutFixed 2 [ObjV, RtsObjV]) CIStackFrame mempty)
- (jVar $ \t inv m t1 ->
- mconcat [ t |= stack .! (sp - 2)
- , inv |= stack .! (sp - 1)
- , m |= var "h$currentThread" .^ "mask"
- , adjSpN' 3
- , t1 |= UOpExpr NewOp (app "h$Transaction" [inv .^ "action", t])
- , t1 .^ "checkRead" |= UOpExpr NewOp (app "h$Set" [])
- , var "h$currentTread" .^ "transaction" |= t1
- , push' s [t1, m, var "h$stmInvariantViolatedHandler", var "h$catchStm_e"]
- , r1 |= inv .^ "action"
- , returnS (app "h$ap_1_0_fast" [])
- ])
- , closure (ClosureInfo "h$stmCheckInvariantResult_e" (CIRegs 0 [PtrV]) "finish checking invariant" (CILayoutFixed 1 [ObjV]) CIStackFrame mempty)
- (jVar $ \inv ->
- mconcat [ inv |= stack .! (sp -1)
- , adjSpN' 2
- , appS "h$stmUpdateInvariantDependencies" [inv]
- , appS "h$stmAbortTransaction" []
- , returnS (stack .! sp)
- ])
+ (returnS (app "h$stmStartTransaction" [stack .! (sp - 2)])))
- -- update invariant TVar dependencies and rethrow exception
- -- handler must be pushed above h$stmCheckInvariantResult_e frame
- , closure (ClosureInfo "h$stmInvariantViolatedHandler_e" (CIRegs 0 [PtrV]) "finish checking invariant" (CILayoutFixed 0 []) (CIFun 2 1) mempty)
- (jVar $ \inv ->
- mconcat [ jwhenS (stack .! sp .===. var "h$stmCheckInvariantResult_e")
- (appS "throw" [jString "h$stmInvariantViolatedHandler_e: unexpected value on stack"])
- , inv |= stack .! (sp - 2)
- , adjSpN' 2
- , appS "h$stmUpdateInvariantDependencies" []
- , appS "h$stmAbortTransaction" []
- , returnS (app "h$throw" [r2, false_])
- ])
- , TxtI "h$stmInvariantViolatedHandler" ||= app "h$c" (var "h$stmInvariantViolatedHandler_e" : [jSystemCCS | csProf s])
, closure (ClosureInfo "h$stmCatchRetry_e" (CIRegs 0 [PtrV]) "catch retry" (CILayoutFixed 1 [PtrV]) CIStackFrame mempty)
(adjSpN' 2
<> appS "h$stmCommitTransaction" []
@@ -683,7 +645,6 @@ rts' s =
(appS "throw" [jString "h$stmResumeRetry_e: unexpected value on stack"])
, blocked |= stack .! (sp - 1)
, adjSpN' 2
- , push' s [var "h$checkInvariants_e"]
, appS "h$stmRemoveBlockedThread" [blocked, var "h$currentThread"]
, returnS (app "h$stmStartTransaction" [stack .! (sp - 2)])
])
=====================================
rts/js/stm.js
=====================================
@@ -25,23 +25,14 @@ function h$Transaction(o, parent) {
this.tvars = new h$Map();
// h$TVar -> h$LocalTVar, all local tvars accessed anywhere in the transaction
this.accessed = parent===null?new h$Map():parent.accessed;
- // nonnull while running a check, contains read variables in this part of the transaction
- this.checkRead = parent===null?null:parent.checkRead;
this.parent = parent;
this.state = h$stmTransactionActive;
- this.invariants = []; // invariants added in this transaction
this.m = 0; // gc mark
#ifdef GHCJS_DEBUG_ALLOC
h$debugAlloc_notifyAlloc(this);
#endif
}
-var h$stmInvariantN = 0;
-/** @constructor */
-function h$StmInvariant(a) {
- this.action = a;
- this._key = ++h$stmInvariantN;
-}
/** @constructor */
function h$WrittenTVar(tv,v) {
this.tvar = tv;
@@ -54,7 +45,6 @@ function h$TVar(v) {
TRACE_STM("creating TVar, value: " + h$collectProps(v));
this.val = v; // current value
this.blocked = new h$Set(); // threads that get woken up if this TVar is updated
- this.invariants = null; // invariants that use this TVar (h$Set)
this.m = 0; // gc mark
this._key = ++h$TVarN; // for storing in h$Map/h$Set
#ifdef GHCJS_DEBUG_ALLOC
@@ -70,12 +60,6 @@ function h$TVarsWaiting(s) {
#endif
}
-/** @constructor */
-function h$LocalInvariant(o) {
- this.action = o;
- this.dependencies = new h$Set();
-}
-
// local view of a TVar
/** @constructor */
function h$LocalTVar(v) {
@@ -86,7 +70,7 @@ function h$LocalTVar(v) {
}
function h$atomically(o) {
- h$p3(o, h$atomically_e, h$checkInvariants_e);
+ h$p2(o, h$atomically_e);
return h$stmStartTransaction(o);
}
@@ -98,20 +82,6 @@ function h$stmStartTransaction(o) {
return h$ap_1_0_fast();
}
-function h$stmUpdateInvariantDependencies(inv) {
- var ii, iter = h$currentThread.transaction.checkRead.iter();
- if(inv instanceof h$LocalInvariant) {
- while((ii = iter.next()) !== null) inv.dependencies.add(ii);
- } else {
- while((ii = iter.next()) !== null) h$stmAddTVarInvariant(ii, inv);
- }
-}
-
-function h$stmAddTVarInvariant(tv, inv) {
- if(tv.invariants === null) tv.invariants = new h$Set();
- tv.invariants.add(inv);
-}
-
// commit current transaction,
// if it's top-level, commit the TVars, otherwise commit to parent
function h$stmCommitTransaction() {
@@ -131,15 +101,10 @@ function h$stmCommitTransaction() {
h$stmRemoveBlockedThread(thread.blockedOn, thread);
h$wakeupThread(thread);
}
- // commit our new invariants
- for(var j=0;j<t.invariants.length;j++) {
- h$stmCommitInvariant(t.invariants[j]);
- }
} else { // commit subtransaction
TRACE_STM("committing subtransaction");
var tpvs = t.parent.tvars;
while((wtv = i.nextVal()) !== null) tpvs.put(wtv.tvar, wtv);
- t.parent.invariants = t.parent.invariants.concat(t.invariants);
}
h$currentThread.transaction = t.parent;
}
@@ -156,13 +121,6 @@ function h$stmAbortTransaction() {
h$currentThread.transaction = h$currentThread.transaction.parent;
}
-
-// add an invariant
-function h$stmCheck(o) {
- h$currentThread.transaction.invariants.push(new h$LocalInvariant(o));
- return false;
-}
-
function h$stmRetry() {
// unwind stack to h$atomically_e or h$stmCatchRetry_e frame
while(h$sp > 0) {
@@ -250,9 +208,6 @@ function h$sameTVar(tv1, tv2) {
// get the local value of the TVar in the transaction t
// tvar is added to the read set
function h$readLocalTVar(t, tv) {
- if(t.checkRead !== null) {
- t.checkRead.add(tv);
- }
var t0 = t;
while(t0 !== null) {
var v = t0.tvars.get(tv);
@@ -282,27 +237,6 @@ function h$setLocalTVar(t, tv, v) {
}
}
-function h$stmCheckInvariants() {
- var t = h$currentThread.transaction;
- function addCheck(inv) {
- h$p5(inv, h$stmCheckInvariantResult_e, t, inv, h$stmCheckInvariantStart_e);
- }
- h$p2(h$r1, h$return);
- var wtv, i = t.tvars.iter();
- while((wtv = i.nextVal()) !== null) {
- TRACE_STM("h$stmCheckInvariants: checking: " + h$collectProps(wtv));
- var ii = wtv.tvar.invariants;
- if(ii) {
- var iv, iii = ii.iter();
- while((iv = iii.next()) !== null) addCheck(iv);
- }
- }
- for(var j=0;j<t.invariants.length;j++) {
- addCheck(t.invariants[j]);
- }
- return h$stack[h$sp];
-}
-
function h$stmCommitTVar(tv, v, threads) {
TRACE_STM("committing tvar: " + tv._key + " " + (v === tv.val));
if(v !== tv.val) {
@@ -320,11 +254,3 @@ function h$stmRemoveBlockedThread(s, thread) {
tv.blocked.remove(thread);
}
}
-
-function h$stmCommitInvariant(localInv) {
- var inv = new h$StmInvariant(localInv.action);
- var dep, i = localInv.dependencies.iter();
- while((dep = i.next()) !== null) {
- h$stmAddTVarInvariant(dep, inv);
- }
-}
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/663cee6c71f8da202dee30d2f09b77b7f7568eda
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/663cee6c71f8da202dee30d2f09b77b7f7568eda
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20221014/a26ea1f3/attachment-0001.html>
More information about the ghc-commits
mailing list