From 79d0863e62442c4039e91e9aaa8656078c62305d Mon Sep 17 00:00:00 2001 From: Joana Bergsiek Date: Fri, 19 Jan 2024 03:47:17 +0100 Subject: [PATCH] buggy cause blocks fail algebra layout, both added watches and the methods with watches in them --- .../SBExploriants.class.st | 55 ++++++++++- .../SBExploriantsView.class.st | 4 +- .../SBMultiverse.class.st | 96 +++++++++++++------ 3 files changed, 122 insertions(+), 33 deletions(-) diff --git a/packages/Sandblocks-Babylonian/SBExploriants.class.st b/packages/Sandblocks-Babylonian/SBExploriants.class.st index e27ceca4..7057a2da 100644 --- a/packages/Sandblocks-Babylonian/SBExploriants.class.st +++ b/packages/Sandblocks-Babylonian/SBExploriants.class.st @@ -5,7 +5,9 @@ Class { #name : #SBExploriants, #superclass : #SBTabView, #instVars : [ - 'objectToPermutation' + 'objectToPermutation', + 'updateProcess', + 'updateProcessRunning' ], #classInstVars : [ 'uniqueInstance' @@ -43,6 +45,12 @@ SBExploriants >> = other [ ^ self class = other class ] +{ #category : #'as yet unclassified' } +SBExploriants >> artefactSaved: aMethodBlock [ + + (aMethodBlock isMethod and: [self isInEditor]) ifTrue: [self tryToUpdateInBackgroundAfterChangeIn: aMethodBlock] +] + { #category : #'ast helpers' } SBExploriants >> binding: aString for: block class: aClass ifPresent: aBlock [ @@ -86,6 +94,7 @@ SBExploriants >> initialize [ super initialize. objectToPermutation := WeakKeyDictionary new. + updateProcessRunning := false. self attachDecorator: SBMoveDecorator new; @@ -118,13 +127,55 @@ SBExploriants >> selector [ ^ nil ] +{ #category : #'as yet unclassified' } +SBExploriants >> tryToUpdateInBackgroundAfterChangeIn: aMethodBlock [ + + | multiverse | + multiverse := self active multiverse. + "(multiverse allMethodBlocksContainingVariants includes: aMethodBlock) + ifTrue: [ + | methodClass methodSelector latestChange | + methodClass := aMethodBlock compiledMethod methodClass. + methodSelector := aMethodBlock compiledMethod selector. + self halt. + latestChange := (ChangeSet + scanVersionsOf: aMethodBlock compiledMethod + class: methodClass + meta: methodClass isMeta + category: (methodClass organization categoryOfElement: methodSelector) + selector: methodSelector) first." + + "mostRecentChangeSetWithChangeForClass: methodClass selector: methodSelector." + "aMethodBlock compiledMethod getSource asString allRangesOfRegexMatches: '(?<=activeIndex\: )\d*'." + "multiverse variants select: [:aVariant | aVariant containingArtefact = aMethodBlock]""]." + + updateProcessRunning ifTrue: [ + updateProcess ifNotNil: #terminate. + updateProcessRunning := false.]. + + updateProcessRunning := true. + updateProcess := [ + | newMultiverse | + newMultiverse := SBMultiverse bigbangInEditorWithoutKaboom: self sandblockEditor. + self namedBlocks do: [:aTab | aTab multiverse: newMultiverse]. + [newMultiverse kaboom] + valueWithin: 5 seconds + onTimeout: [ + newMultiverse cleanUp. updateProcess := nil. updateProcessRunning := false.]. + updateProcess := nil. updateProcessRunning := false. + ] forkAt: Processor userBackgroundPriority. + + + +] + { #category : #actions } SBExploriants >> visualize [ | tabs | self width: 0. "tabs will visualize as soon as multiverse is finished" - tabs := SBExploriantsView getTabsInMultiverse: (SBMultiverse newInEditor: self sandblockEditor). + tabs := SBExploriantsView getTabsInMultiverse: (SBMultiverse bigbangInEditor: self sandblockEditor). self namedBlocks: tabs activeIndex: 1. diff --git a/packages/Sandblocks-Babylonian/SBExploriantsView.class.st b/packages/Sandblocks-Babylonian/SBExploriantsView.class.st index 8a16a342..fb6f8a9e 100644 --- a/packages/Sandblocks-Babylonian/SBExploriantsView.class.st +++ b/packages/Sandblocks-Babylonian/SBExploriantsView.class.st @@ -95,7 +95,7 @@ SBExploriantsView >> initialize [ { #category : #accessing } SBExploriantsView >> multiverse [ - ^ multiverse ifNil: [self multiverse: (SBMultiverse newInEditor: SBEditor current)] + ^ multiverse ifNil: [self multiverse: (SBMultiverse bigbangInEditor: SBEditor current)] ] { #category : #accessing } @@ -121,7 +121,7 @@ SBExploriantsView >> updateButton [ ^ SBButton new icon: SBIcon iconRotateLeft label: 'Re-Generate Multiverse' - do: [self multiverse initialize]; + do: [self multiverse gatherElements; asyncKaboom]; cornerStyle: #squared ] diff --git a/packages/Sandblocks-Babylonian/SBMultiverse.class.st b/packages/Sandblocks-Babylonian/SBMultiverse.class.st index a41418e5..e040b995 100644 --- a/packages/Sandblocks-Babylonian/SBMultiverse.class.st +++ b/packages/Sandblocks-Babylonian/SBMultiverse.class.st @@ -7,6 +7,7 @@ Class { #instVars : [ 'universes', 'variants', + 'watches', 'activeExamples', 'allMethodBlocksContainingVariants', 'allMethodBlocksContainingWatches', @@ -16,14 +17,17 @@ Class { } { #category : #'instance creation' } -SBMultiverse class >> new [ - - "Use constructor with editor instead" - self shouldNotImplement +SBMultiverse class >> bigbangInEditor: aSandblockEditor [ + + ^ self basicNew + sandblockEditor: aSandblockEditor; + initialize; + asyncKaboom; + yourself ] { #category : #'instance creation' } -SBMultiverse class >> newInEditor: aSandblockEditor [ +SBMultiverse class >> bigbangInEditorWithoutKaboom: aSandblockEditor [ ^ self basicNew sandblockEditor: aSandblockEditor; @@ -31,6 +35,13 @@ SBMultiverse class >> newInEditor: aSandblockEditor [ yourself ] +{ #category : #'instance creation' } +SBMultiverse class >> new [ + + "Use constructor with editor instead" + self shouldNotImplement +] + { #category : #accessing } SBMultiverse >> activeExamples [ @@ -89,12 +100,24 @@ SBMultiverse >> allMethodBlocksContainingWatches [ ] -{ #category : #converting } -SBMultiverse >> createUniverseFomPermutation: aSBPermutation [ +{ #category : #actions } +SBMultiverse >> asyncKaboom [ + + ^ [self kaboom] forkAt: Processor userSchedulingPriority. +] + +{ #category : #actions } +SBMultiverse >> cleanUp [ + + self resetWatchesToOriginalPermutationRunning: activeExamples. + (watches select: [:anOpenWatch | anOpenWatch containingArtefact isNil]) copy do: #delete +] - ^ SBUniverse - newActive: aSBPermutation - watches: self copyWatches +{ #category : #actions } +SBMultiverse >> cleanUpRemovingCopies: outOfWorldWatches [ + + self resetWatchesToOriginalPermutationRunning: activeExamples. + outOfWorldWatches copy do: #delete ] { #category : #collecting } @@ -115,12 +138,14 @@ SBMultiverse >> gatherElements [ have consistency between changes." allMethodBlocksContainingVariants := self findExistingOrConvertToBlocks: self allCompiledMethodsContainingVariants. - "We need existing originals to be noticed of changes." - allMethodBlocksContainingWatches := self findExistingOrConvertToBlocks: self allCompiledMethodsContainingExampleWatches. + allMethodBlocksContainingWatches := self allCompiledMethodsContainingExampleWatches collect: #asSandblock. variants := (allMethodBlocksContainingVariants collect: #containedVariants) flatten. variants := variants select: #isActive. + watches := (self allMethodBlocksContainingWatches collect: #containedExampleWatches) flatten. + + universes := OrderedCollection new. activeExamples := self allActiveExamples. @@ -129,27 +154,23 @@ SBMultiverse >> gatherElements [ { #category : #'initialize-release' } SBMultiverse >> initialize [ - | permutations watches outOfWorldWatches | super initialize. - - self gatherElements. - permutations := SBPermutation allPermutationsOf: variants. - universes := OrderedCollection new. + self gatherElements. +] + +{ #category : #actions } +SBMultiverse >> kaboom [ - watches := (self allMethodBlocksContainingWatches collect: #containedExampleWatches) flatten. + | outOfWorldWatches | "Only open watches display values when examples are run. We want to show them too" (outOfWorldWatches := watches reject: #isInEditor) do: [:aWatch | self sandblockEditor openMorph: aWatch]. - [permutations do: [:aPermutation | - SBActiveVariantPermutation value: aPermutation. - activeExamples do: #runSynchronouslyIgnoreReturn. - universes add: (SBUniverse newActive: aPermutation watches: (watches collect: #asInactiveCopy))]. - outOfWorldWatches copy do: #delete. - self resetWatchesToOriginalPermutationRunning: activeExamples. - self triggerEvent: #updated] forkAt: Processor userSchedulingPriority. - - + (SBPermutation allPermutationsOf: variants) do: [:aPermutation | + self runPermutation: aPermutation copyingWatches: watches ]. + self resetWatchesToOriginalPermutationRunning: activeExamples. + outOfWorldWatches copy do: #delete. + self triggerEvent: #updated. ] { #category : #actions } @@ -159,13 +180,14 @@ SBMultiverse >> reset [ allMethodBlocksContainingWatches := OrderedCollection new. variants := OrderedCollection new. activeExamples := OrderedCollection new. + watches:= OrderedCollection new. universes := OrderedCollection withAll: ((SBPermutation allPermutationsOf: {}) - collect: [:aPermutation | self createUniverseFomPermutation: aPermutation]) . + collect: [:aPermutation | SBUniverse newActive: aPermutation watches: {}]) . self triggerEvent: #updated. ] -{ #category : #state } +{ #category : #'action-helper' } SBMultiverse >> resetWatchesToOriginalPermutationRunning: activeExamples [ SBActiveVariantPermutation value: nil. @@ -189,6 +211,16 @@ SBMultiverse >> resolve [ ] +{ #category : #actions } +SBMultiverse >> runPermutation: aPermutation copyingWatches: allWatches [ + + + SBActiveVariantPermutation value: aPermutation. + activeExamples do: #runSynchronouslyIgnoreReturn. + universes add: (SBUniverse newActive: aPermutation watches: (watches collect: #asInactiveCopy)) + +] + { #category : #accessing } SBMultiverse >> sandblockEditor [ @@ -220,3 +252,9 @@ SBMultiverse >> variants [ ^ variants ] + +{ #category : #accessing } +SBMultiverse >> watches [ + + ^ watches +]