It is extremely confusing that Nabble strips of the revision number of the changeset upon upload. :-)<br><br>

---<br><br>

Community service, here is the inlined diff:<br><br>

"Change Set:        SimulationSideEffectWarning<br>
Date:            9 May 2021<br>
Author:            Christoph Thiede<br>
<br>
<your descriptive text goes here>"<br>
<br>
Warning subclass: #SimulationSideEffectWarning<br>
    instanceVariableNames: 'primitiveIndex sender suppressed'<br>
    classVariableNames: ''<br>
    poolDictionaries: ''<br>
    category: 'Kernel-Exceptions'<br>
<br>
I am signaled to notify the client of a simulation operation (i.e., a sender of Context) about potential side effects that might occur when resuming the simulation. See Context >> #doPrimitive:method:receiver:args:, #messageText, and Parser >> #simulationGuard for more information.<br>
<br>
doPrimitive: primitiveIndex method: meth receiver: receiver args: arguments<br>
    "Simulate a primitive method whose index is primitiveIndex.  The simulated receiver and<br>
     arguments are given as arguments to this message. If successful, push result and return<br>
     resuming context, else ^ {errCode, PrimitiveFailToken}. Any primitive which provokes<br>
     execution needs to be intercepted and simulated to avoid execution running away."<br>
<br>
    | value |<br>
<s><font color="#0000FF">    "Judicious use of primitive 19 (a null primitive that doesn't do anything) prevents<br>
     the debugger from entering various run-away activities such as spawning a new<br>
     process, etc.  Injudicious use results in the debugger not being able to debug<br>
     interesting code, such as the debugger itself.  Hence use primitive 19 with care :-)"<br>
    "SystemNavigation new browseAllSelect: [:m| m primitive = 19]"<br>
    primitiveIndex = 19 ifTrue: [<br>
        [self notify: ('The code being simulated is trying to control a process ({1}). Process controlling cannot be simulated. If you proceed, things may happen outside the observable area of the simulator.' translated format: {meth reference})]<br>
            ifCurtailed: [self push: nil "Cheap fix of the context's internal state"]].<br>
</font></s><font color="#FF0000">    </font><font color="#FF0000"><b>"Test for unsimulatable side effects (that is, code that will be triggered in the image outside of the simulator range). This includes simulation guards, which are traditionally flagged using primitive 19 (a null primitive that doesn't do anything), as well as certain control primitives that might trigger code on other processes. If a side effect is detected, raise a warning to give the user a chance to cancel the operation."<br>
    "#(19 87) do: [:primitive | self systemNavigation browseAllSelect: [:m | m primitive = primitive]]"<br>
    (primitiveIndex = 19 "simulationGuard" or: [primitiveIndex = 87 "primitiveResume"]) ifTrue: [<br>
        [SimulationSideEffectWarning signalForPrimitive: primitiveIndex sender: self]<br>
            ifCurtailed: [self push: nil "Cheap fix of the context's internal state. Note that unwinding the receiver -- so that the next step would invoke the primitive again -- would be challenging due to to the variety of senders to this method."]].</b></font><font color="#FF0000"><br>
</font>    <br>
    ((primitiveIndex between: 201 and: 222)<br>
     and: [(self objectClass: receiver) includesBehavior: BlockClosure]) ifTrue:<br>
        [(primitiveIndex = 206<br>
          or: [primitiveIndex = 208]) ifTrue:                        "[Full]BlockClosure>>valueWithArguments:"<br>
            [^receiver simulateValueWithArguments: arguments first caller: self].<br>
         ((primitiveIndex between: 201 and: 209)             "[Full]BlockClosure>>value[:value:...]"<br>
          or: [primitiveIndex between: 221 and: 222]) ifTrue: "[Full]BlockClosure>>valueNoContextSwitch[:]"<br>
            [^receiver simulateValueWithArguments: arguments caller: self]].<br>
<br>
    primitiveIndex = 83 ifTrue: "afr 9/11/1998 19:50" "Object>>perform:[with:...]"<br>
        [| selector |<br>
        selector := arguments at: 1 ifAbsent:<br>
            [^ self class primitiveFailTokenFor: #'bad argument'].<br>
        arguments size - 1 = selector numArgs ifFalse:<br>
            [^ self class primitiveFailTokenFor: #'bad number of arguments'].<br>
        ^self send: selector to: receiver with: arguments allButFirst].<br>
    primitiveIndex = 84 ifTrue: "afr 9/11/1998 19:50 & eem 8/18/2009 17:04" "Object>>perform:withArguments:"<br>
        [| selector args |<br>
        arguments size = 2 ifFalse:<br>
            [^ self class primitiveFailTokenFor: #'bad argument'].<br>
        selector := arguments first.<br>
        args := arguments second.<br>
        args isArray ifFalse:<br>
            [^ self class primitiveFailTokenFor: #'bad argument'].<br>
        args size = selector numArgs ifFalse:<br>
            [^ self class primitiveFailTokenFor: #'bad number of arguments'].<br>
        ^self send: selector to: receiver with: args].<br>
    primitiveIndex = 100 ifTrue: "eem 8/18/2009 16:57" "Object>>perform:withArguments:inSuperclass:"<br>
        [| rcvr selector args superclass |<br>
        arguments size<br>
            caseOf: {<br>
                [3] -> [<br>
                    rcvr := receiver.<br>
                    selector := arguments first.<br>
                    args := arguments second.<br>
                    superclass := arguments third].<br>
                [4] -> ["mirror primitive"<br>
                    rcvr := arguments first.<br>
                    selector := arguments second.<br>
                    args := arguments third.<br>
                    superclass := arguments fourth] }<br>
            otherwise: [^ self class primitiveFailTokenFor: #'bad argument'].<br>
        args isArray ifFalse:<br>
            [^ self class primitiveFailTokenFor: #'bad argument'].<br>
        args size = selector numArgs ifFalse:<br>
            [^ self class primitiveFailTokenFor: #'bad number of arguments'].<br>
        ((self objectClass: rcvr) includesBehavior: superclass) ifFalse:<br>
            [^ self class primitiveFailTokenFor: #'bad argument'].<br>
        ^self send: selector to: rcvr with: args lookupIn: superclass].<br>
<br>
    "Mutex>>primitiveEnterCriticalSection<br>
     Mutex>>primitiveTestAndSetOwnershipOfCriticalSection"<br>
    (primitiveIndex = 186 or: [primitiveIndex = 187]) ifTrue:<br>
        [| effective |<br>
         effective := Processor activeProcess effectiveProcess.<br>
         "active == effective"<br>
         value := primitiveIndex = 186<br>
                    ifTrue: [receiver primitiveEnterCriticalSectionOnBehalfOf: effective]<br>
                    ifFalse: [receiver primitiveTestAndSetOwnershipOfCriticalSectionOnBehalfOf: effective].<br>
         ^(self isPrimFailToken: value)<br>
            ifTrue: [value]<br>
            ifFalse: [self push: value]].<br>
<br>
    primitiveIndex = 188 ifTrue:    "Object>>withArgs:executeMethod:<br>
                                    CompiledMethod class>>receiver:withArguments:executeMethod:<br>
                                    VMMirror>>ifFail:object:with:executeMethod: et al"<br>
        [| n args methodArg thisReceiver |<br>
         ((n := arguments size) between: 2 and: 4) ifFalse:<br>
            [^self class primitiveFailTokenFor: #'unsupported operation'].<br>
         ((self objectClass: (args := arguments at: n - 1)) == Array<br>
          and: [(self objectClass: (methodArg := arguments at: n)) includesBehavior: CompiledMethod]) ifFalse:<br>
            [^self class primitiveFailTokenFor: #'bad argument'].<br>
         methodArg numArgs = args size ifFalse:<br>
            [^self class primitiveFailTokenFor: #'bad number of arguments'].<br>
         thisReceiver := arguments at: n - 2 ifAbsent: [receiver].<br>
         methodArg primitive > 0 ifTrue:<br>
            [methodArg isQuick ifTrue:<br>
                [^self push: (methodArg valueWithReceiver: thisReceiver arguments: args)].<br>
             ^self doPrimitive: methodArg primitive method: meth receiver: thisReceiver args: args].<br>
         ^Context<br>
            sender: self<br>
            receiver: thisReceiver<br>
            method: methodArg<br>
            arguments: args].<br>
<br>
    primitiveIndex = 118 ifTrue: "[receiver:]tryPrimitive:withArgs:; avoid recursing in the VM"<br>
        [(arguments size = 3<br>
          and: [(self objectClass: arguments second) == SmallInteger<br>
          and: [(self objectClass: arguments last) == Array]]) ifTrue:<br>
            [^self doPrimitive: arguments second method: meth receiver: arguments first args: arguments last].<br>
         (arguments size = 2<br>
         and: [(self objectClass: arguments first) == SmallInteger<br>
         and: [(self objectClass: arguments last) == Array]]) ifFalse:<br>
            [^self class primitiveFailTokenFor: nil].<br>
         ^self doPrimitive: arguments first method: meth receiver: receiver args: arguments last].<br>
<br>
    value := primitiveIndex = 120 "FFI method"<br>
                ifTrue: [(meth literalAt: 1) tryInvokeWithArguments: arguments]<br>
                ifFalse:<br>
                    [primitiveIndex = 117 "named primitives"<br>
                        ifTrue: [self tryNamedPrimitiveIn: meth for: receiver withArgs: arguments]<br>
                        ifFalse: "should use self receiver: receiver tryPrimitive: primitiveIndex withArgs: arguments but this is only in later VMs (and appears to be broken)"<br>
                            [receiver tryPrimitive: primitiveIndex withArgs: arguments]].<br>
<br>
    ^(self isPrimFailToken: value)<br>
        ifTrue: [value]<br>
        ifFalse: [self push: value]<br>
<br>
invokeSimulationGuard<br>
    <simulationGuard><br>
    "Nothing to see here, please move along!"<br>
    ^ 42<br>
<br>
testSimulationSideEffectWarningControl<br>
<br>
    | warning |<br>
    [Context runSimulated: [[] fork]] on: SimulationSideEffectWarning do: [:ex |<br>
        warning := ex].<br>
    <br>
    self assert: warning notNil.<br>
    self assert: warning isControlPrimitive.<br>
    self assert: warning suppressed.<br>
<br>
testSimulationSideEffectWarningGuard<br>
<br>
    | warning |<br>
    [Context runSimulated: [self invokeSimulationGuard]] on: SimulationSideEffectWarning do: [:ex |<br>
        warning := ex].<br>
    <br>
    self assert: warning notNil.<br>
    self assert: warning isSimulationGuard.<br>
    self deny: warning suppressed.<br>
<br>
testSimulationSideEffectWarningSuppress<br>
<br>
    self<br>
        shouldnt: [(SimulationSideEffectWarning forPrimitive: 42 sender: thisContext)<br>
            suppress;<br>
            defaultAction] raise: UnhandledWarning;<br>
        should: [(SimulationSideEffectWarning forPrimitive: 42 sender: thisContext)<br>
            unsuppress;<br>
            defaultAction] raise: UnhandledWarning.<br>
<br>
activeController: aController <br>
<s><font color="#0000FF">    "Set aController to be the currently active controller. Give the user <br>
    control in it."<br>
    <primitive: 19> "Simulation guard"<br>
</font></s><font color="#FF0000">    </font><font color="#FF0000"><b>"Set aController to be the currently active controller. Give the user control in it."<br>
    <simulationGuard></b></font><font color="#FF0000"><br>
<br>
</font>    activeController := aController.<br>
    (activeController == screenController)<br>
        ifFalse: [self promote: activeController].<br>
    activeControllerProcess := <br>
            [activeController startUp.<br>
            self searchForActiveController] newProcess.<br>
    activeControllerProcess priority: Processor userSchedulingPriority.<br>
    activeControllerProcess resume<br>
<br>
scheduleActive: aController <br>
<s><font color="#0000FF">    "Make aController be scheduled as the active controller. Presumably the <br>
    active scheduling process asked to schedule this controller and that a <br>
    new process associated this controller takes control. So this is the last act <br>
    of the active scheduling process."<br>
    <primitive: 19> "Simulation guard"<br>
</font></s><font color="#FF0000">    </font><font color="#FF0000"><b>"Make aController be scheduled as the active controller. Presumably the active scheduling process asked to schedule this controller and that a new process associated this controller takes control. So this is the last act of the active scheduling process."<br>
    <simulationGuard></b></font><font color="#FF0000"><br>
<br>
</font>    self scheduleActiveNoTerminate: aController.<br>
    Processor terminateActive<br>
<br>
handleLabelUpdatesIn: aBlock whenExecuting: aContext<br>
    "Send the selected message in the accessed method, and regain control <br>
    after the invoked method returns."<br>
    <br>
    ^aBlock<br>
        on: Notification<br>
        do: [:ex|<br>
            (ex tag isArray<br>
             and: [ex tag size = 2<br>
             and: [(ex tag first == aContext or: [ex tag first hasSender: aContext])]])<br>
                ifTrue:<br>
                    [self labelString: ex tag second description.<br>
                     ex resume]<br>
                ifFalse:<br>
<s><font color="#0000FF">                    [ex pass]]<br>
</font></s><font color="#FF0000">                    </font><font color="#FF0000"><b>[ex pass]]<br>
        on: SimulationSideEffectWarning<br>
        do: [:ex |<br>
            ex isControlPrimitive ifTrue: [ex unsuppress].<br>
            ex pass]</b></font><br>
<br>
simulationGuard<br>
    "primitive 19 is a null primitive that always fails. Just a marker for the simulator."<br>
    <pragmaParser><br>
<br>
    self addPragma: (Pragma keyword: #primitive: arguments: #(19)).<br>
    <br>
    self advance.<br>
    ^ true<br>
<br>
isControlPrimitive<br>
    "See StackInterpreter class>>#initializePrimitiveTable."<br>
<br>
    ^ self primitive between: 80 and: 89<br>
<br>
isSimulationGuard<br>
    "See Parser >> #simulationGuard."<br>
<br>
    ^ self primitive = 19<br>
<br>
primitive<br>
<br>
    ^ primitiveIndex<br>
<br>
sender<br>
<br>
    ^ sender<br>
<br>
suppress<br>
<br>
    suppressed := true.<br>
<br>
suppressed<br>
<br>
    ^ suppressed ifNil: [self isSimulationGuard not]<br>
<br>
unsuppress<br>
<br>
    suppressed := false.<br>
<br>
primitive: anInteger sender: senderContext<br>
<br>
    primitiveIndex := anInteger.<br>
    sender := senderContext.<br>
<br>
messageText<br>
<br>
    ^ messageText ifNil: [<br>
        'The code being simulated is trying to control a process ({1}). {2}' translated format: {<br>
            self sender method reference.<br>
            self isSimulationGuard<br>
                ifTrue: ['If you proceed, your image may become unusable. Continue at own risk, and better save your image before.' translated]<br>
                ifFalse: ['Process controlling cannot be simulated. If you proceed, side effects may occur outside the observable area of the simulator.' translated]}]<br>
<br>
defaultAction<br>
<br>
    ^ self suppressed ifFalse: [super defaultAction]<br>
<br>
forPrimitive: primitiveIndex sender: senderContext<br>
<br>
    ^ self new primitive: primitiveIndex sender: senderContext<br>
<br>
signalForPrimitive: primitiveIndex sender: senderContext<br>
<br>
    ^ (self forPrimitive: primitiveIndex sender: senderContext) signal<br>
<br>
('instance creation' forPrimitive:sender:)<br>
('signaling' signalForPrimitive:sender:)<br>
<br>
<br>
('testing' isControlPrimitive isSimulationGuard)<br>
('accessing' primitive sender suppress suppressed unsuppress)<br>
('initialize-release' primitive:sender:)<br>
('printing' messageText)<br>
('priv handling' defaultAction)<br>
<br>
<br>
"Postscript:<br>
CHANGELOG*:<br>
<br>
- Replace generic Warning in Context >> #doPrimitive:method:receiver:args: by specific warning of new class SimulationSideEffectWarning.<br>
- Also signal SimulationSideEffectWarning if primitive 87 (primitiveResume) is hit.<br>
- SimulationSideEffectWarning contains logic to detect the type (simulation guard/control primitive) of the side effect. It can also be suppressed or unsuppressed along the handler chain using the '*suppress*' selectors. Control primitive side effects are suppressed by default.<br>
- Add tests for the changes above.<br>
- In the debugger, unsuppress control primitive warnings.<br>
- Replace definitions of primitive 19 (currently only in ControlManager) by a named alias pragma, <simulationGuard>, which is implemented on Parser.<br>
<br>
For more information, see: http://forum.world.st/The-Trunk-Kernel-nice-1386-mcz-td5128636.html<br>
<br>
<br>
(* Sorry, this should be in the preamble, not in the postscript, I know, but the preamble editor in the ChangeSorter is currently broken. ¬Ø\_(?)_/¬Ø)<br>
"<br>


        
        
        <div class="signature" style="margin-top:1em;color:#666666;font-size:11px;">
                                Carpe Squeak!
                        </div>
<br/><hr align="left" width="300" />
Sent from the <a href="http://forum.world.st/Squeak-Dev-f45488.html">Squeak - Dev mailing list archive</a> at Nabble.com.<br/>