From fedbf579dc7e30bbee588fb8cdfd1b6dfc1653f7 Mon Sep 17 00:00:00 2001 From: Joana Bergsiek Date: Thu, 16 Nov 2023 13:53:46 +0100 Subject: [PATCH] Adds SBUniverse / SBMultiverse to save objects in a permutation (makes things faster) --- .../SBExploriants.class.st | 8 +- .../SBExploriantsView.class.st | 51 +++--- .../SBGridResultsView.class.st | 8 +- .../SBMultiverse.class.st | 159 ++++++++++++++++++ .../SBResultsView.class.st | 71 ++------ .../Sandblocks-Babylonian/SBUniverse.class.st | 45 +++++ .../SBVariantsView.class.st | 2 +- 7 files changed, 245 insertions(+), 99 deletions(-) create mode 100644 packages/Sandblocks-Babylonian/SBMultiverse.class.st create mode 100644 packages/Sandblocks-Babylonian/SBUniverse.class.st diff --git a/packages/Sandblocks-Babylonian/SBExploriants.class.st b/packages/Sandblocks-Babylonian/SBExploriants.class.st index 37008cae..11619e7d 100644 --- a/packages/Sandblocks-Babylonian/SBExploriants.class.st +++ b/packages/Sandblocks-Babylonian/SBExploriants.class.st @@ -75,7 +75,7 @@ SBExploriants >> saveTryFixing: aFixBoolean quick: aQuickBoolean [ ^ true ] -{ #category : #'as yet unclassified' } +{ #category : #accessing } SBExploriants >> selector [ " if this node represents any selector, return it here " @@ -85,11 +85,9 @@ SBExploriants >> selector [ { #category : #actions } SBExploriants >> visualize [ - "The Views need a parent to visualize themselves. We also want to avoid double-calculations" | tabs | - tabs := SBExploriantsView getTabs. - tabs do: [:aTab | self addMorph: aTab block. aTab visualize.]. - self removeAllMorphs. + tabs := SBExploriantsView getTabsInMultiverse: (SBMultiverse newInEditor: self sandblockEditor). + tabs do: #visualize. self namedBlocks: tabs activeIndex: 1. diff --git a/packages/Sandblocks-Babylonian/SBExploriantsView.class.st b/packages/Sandblocks-Babylonian/SBExploriantsView.class.st index b0214dcf..c1d3d22d 100644 --- a/packages/Sandblocks-Babylonian/SBExploriantsView.class.st +++ b/packages/Sandblocks-Babylonian/SBExploriantsView.class.st @@ -1,10 +1,9 @@ -" -Caution: -The Views need a parent who in in the editor to visualize themselves -" Class { #name : #SBExploriantsView, #superclass : #SBNamedBlock, + #instVars : [ + 'multiverse' + ], #category : #'Sandblocks-Babylonian' } @@ -22,34 +21,18 @@ SBExploriantsView class >> deepSubclasses: aClass [ ] { #category : #'instance creation' } -SBExploriantsView class >> getTabs [ +SBExploriantsView class >> getTabsInMultiverse: aSBMultiverse [ - ^ (self subclasses collect: [:mySubClass | self deepSubclasses: mySubClass]) flatten collect: #new + ^ (self subclasses collect: [:mySubClass | self deepSubclasses: mySubClass]) flatten + collect: [:mySubclass | mySubclass newMultiverse: aSBMultiverse] ] -{ #category : #accessing } -SBExploriantsView >> allCompiledMethodsContainingClass: aClass [ - - "aClass should have #matchingSelectors implemented" - ^ (((aClass matchingSelectors collect: [:aSelector | self systemNavigation allCallsOn: aSelector]) flatten) - reject: [:aMethodReference | aMethodReference actualClass = aClass class]) - collect: #compiledMethod -] - -{ #category : #accessing } -SBExploriantsView >> allCompiledMethodsContainingVariants [ - - ^ self allCompiledMethodsContainingClass: SBVariant -] - -{ #category : #accessing } -SBExploriantsView >> allMethodBlocksContainingVariants [ - - "We are looking for already opened methods so that we can assign the - variant there as the original in SBVariantProxy. That way, we immediately - have consistency between changes." - ^ self findExistingOrConvertToBlocks: self allCompiledMethodsContainingVariants +{ #category : #'instance creation' } +SBExploriantsView class >> newMultiverse: aSBMultiverse [ + ^ self new + multiverse: aSBMultiverse; + yourself ] { #category : #actions } @@ -100,6 +83,18 @@ SBExploriantsView >> initialize [ vResizing: #shrinkWrap) ] +{ #category : #accessing } +SBExploriantsView >> multiverse [ + + ^ multiverse ifNil: [multiverse := SBMultiverse newInEditor: SBEditor current] +] + +{ #category : #accessing } +SBExploriantsView >> multiverse: aSBMultiverse [ + + multiverse := aSBMultiverse +] + { #category : #actions } SBExploriantsView >> visualize [ diff --git a/packages/Sandblocks-Babylonian/SBGridResultsView.class.st b/packages/Sandblocks-Babylonian/SBGridResultsView.class.st index e861ed00..feb7fe26 100644 --- a/packages/Sandblocks-Babylonian/SBGridResultsView.class.st +++ b/packages/Sandblocks-Babylonian/SBGridResultsView.class.st @@ -5,14 +5,14 @@ Class { } { #category : #building } -SBGridResultsView >> buildPermutationFor: aPermutation collectingWatchesFrom: aCollectionOfMethodBlocks [ +SBGridResultsView >> buildPermutationFor: aSBUniverse [ - self block addAllMorphsBack: { SBOwnTextMorph new contents: aPermutation asString. - self applyButtonFor: aPermutation. + self block addAllMorphsBack: { SBOwnTextMorph new contents: aSBUniverse activePermutation asString. + self applyButtonFor: aSBUniverse activePermutation. (self containerRow listDirection: #leftToRight) addMorph: (( SBPermutationCluster - newFromWatches: (self allWatchesIn: aCollectionOfMethodBlocks) + newFromWatches: aSBUniverse watches havingSize: (SBMorphResizer newMedium))). LineMorph from: 0@0 to: 50@0 color: Color black width: 2} ] diff --git a/packages/Sandblocks-Babylonian/SBMultiverse.class.st b/packages/Sandblocks-Babylonian/SBMultiverse.class.st new file mode 100644 index 00000000..49103977 --- /dev/null +++ b/packages/Sandblocks-Babylonian/SBMultiverse.class.st @@ -0,0 +1,159 @@ +Class { + #name : #SBMultiverse, + #superclass : #Object, + #instVars : [ + 'universes', + 'variants', + 'watches', + 'activeExamples', + 'allMethodBlocksContainingVariants', + 'allMethodBlocksContainingWatches', + 'sandblockEditor' + ], + #category : #'Sandblocks-Babylonian' +} + +{ #category : #'instance creation' } +SBMultiverse class >> new [ + + "Use constructor with editor instead" + self shouldNotImplement +] + +{ #category : #'instance creation' } +SBMultiverse class >> newInEditor: aSandblockEditor [ + + ^ self basicNew + sandblockEditor: aSandblockEditor; + initialize; + yourself +] + +{ #category : #accessing } +SBMultiverse >> activeExamples [ + + ^ activeExamples +] + +{ #category : #collecting } +SBMultiverse >> allActiveExamples [ + + ^ (self allCompiledMethodsContainingExamples + collect: [:aCompiledMethod | + "Only examples which are open in the editor can actually be active." + self sandblockEditor blockFor: aCompiledMethod withInterfaces: #(#isMethod) + ifOpen: [:existingMethodBlock | existingMethodBlock containedExamples select: #active] + ifClosed: [#()]]) flatten +] + +{ #category : #collecting } +SBMultiverse >> allCompiledMethodsContainingClass: aClass [ + + "aClass should have #matchingSelectors implemented" + ^ (((aClass matchingSelectors collect: [:aSelector | self systemNavigation allCallsOn: aSelector]) flatten) + reject: [:aMethodReference | aMethodReference actualClass = aClass class]) + collect: #compiledMethod +] + +{ #category : #collecting } +SBMultiverse >> allCompiledMethodsContainingExampleWatches [ + + ^ self allCompiledMethodsContainingClass: SBExampleWatch +] + +{ #category : #collecting } +SBMultiverse >> allCompiledMethodsContainingExamples [ + + ^ self allCompiledMethodsContainingClass: SBExample +] + +{ #category : #collecting } +SBMultiverse >> allCompiledMethodsContainingVariants [ + + ^ self allCompiledMethodsContainingClass: SBVariant +] + +{ #category : #accessing } +SBMultiverse >> allMethodBlocksContainingVariants [ + + ^ allMethodBlocksContainingVariants + +] + +{ #category : #accessing } +SBMultiverse >> allMethodBlocksContainingWatches [ + + ^ allMethodBlocksContainingWatches + +] + +{ #category : #collecting } +SBMultiverse >> copyWatchesIn: aCollectionOfMethodBlocks [ + + ^ (aCollectionOfMethodBlocks collect: [:aMethodBlock | + aMethodBlock containedExampleWatches collect: #asInactiveCopy]) flatten +] + +{ #category : #converting } +SBMultiverse >> createUniverseFomPermutation: aSBPermutation [ + + ^ SBUniverse + newActive: aSBPermutation + watches: (self copyWatchesIn: self allMethodBlocksContainingWatches) +] + +{ #category : #collecting } +SBMultiverse >> findExistingOrConvertToBlocks: aCollectionOfCompiledMethods [ + + ^ aCollectionOfCompiledMethods + collect: [:aCompiledMethod | + self sandblockEditor blockFor: aCompiledMethod withInterfaces: #(#isMethod) + ifOpen: [:existingMethodBlock | existingMethodBlock] + ifClosed: [aCompiledMethod asSandblock]] +] + +{ #category : #'initialize-release' } +SBMultiverse >> initialize [ + + super initialize. + + "We are looking for already opened methods so that we can assign the + variant there as the original in SBVariantProxy. That way, we immediately + have consistency between changes." + allMethodBlocksContainingVariants := self findExistingOrConvertToBlocks: self allCompiledMethodsContainingVariants. + + "We need existing originals to be noticed of changes." + allMethodBlocksContainingWatches := self findExistingOrConvertToBlocks: self allCompiledMethodsContainingExampleWatches. + + variants := (allMethodBlocksContainingVariants collect: #containedVariants) flatten. + activeExamples := self allActiveExamples. + + universes := (SBPermutation allPermutationsOf: variants) collect: [:aPermutation | + self createUniverseFomPermutation: aPermutation]. + + +] + +{ #category : #accessing } +SBMultiverse >> sandblockEditor [ + + ^ sandblockEditor +] + +{ #category : #accessing } +SBMultiverse >> sandblockEditor: aSandblockEditor [ + + sandblockEditor := aSandblockEditor +] + +{ #category : #accessing } +SBMultiverse >> universes [ + + ^ universes +] + +{ #category : #accessing } +SBMultiverse >> variants [ + + ^ variants +] diff --git a/packages/Sandblocks-Babylonian/SBResultsView.class.st b/packages/Sandblocks-Babylonian/SBResultsView.class.st index bd221626..6d159981 100644 --- a/packages/Sandblocks-Babylonian/SBResultsView.class.st +++ b/packages/Sandblocks-Babylonian/SBResultsView.class.st @@ -4,50 +4,6 @@ Class { #category : #'Sandblocks-Babylonian' } -{ #category : #building } -SBResultsView >> addAllWatchesFrom: aCollectionOfMethodBlocks [ - - self block addAllMorphsBack: (self allWatchesIn: aCollectionOfMethodBlocks) -] - -{ #category : #accessing } -SBResultsView >> allActiveExamples [ - - ^ (self allCompiledMethodsContainingExamples - collect: [:aCompiledMethod | - "Only examples which are open in the editor can actually be active." - self block sandblockEditor blockFor: aCompiledMethod withInterfaces: #(#isMethod) - ifOpen: [:existingMethodBlock | existingMethodBlock containedExamples select: #active] - ifClosed: [#()]]) flatten -] - -{ #category : #accessing } -SBResultsView >> allCompiledMethodsContainingExampleWatches [ - - ^ self allCompiledMethodsContainingClass: SBExampleWatch -] - -{ #category : #accessing } -SBResultsView >> allCompiledMethodsContainingExamples [ - - ^ self allCompiledMethodsContainingClass: SBExample -] - -{ #category : #accessing } -SBResultsView >> allMethodBlocksContainingWatches [ - - "We need existing originals to be noticed of changes." - ^ self findExistingOrConvertToBlocks: self allCompiledMethodsContainingExampleWatches - -] - -{ #category : #accessing } -SBResultsView >> allWatchesIn: aCollectionOfMethodBlocks [ - - ^ (aCollectionOfMethodBlocks collect: [:aMethodBlock | - aMethodBlock containedExampleWatches collect: #asInactiveCopy]) flatten -] - { #category : #building } SBResultsView >> applyButtonFor: aPermutation [ @@ -63,30 +19,23 @@ SBResultsView >> applyButtonFor: aPermutation [ { #category : #building } SBResultsView >> buildAllPossibleResults [ - - | permutations activeExamples watchMethodBlocks variants | - self flag: #todo. "don't calculate all variants a second time (first time being the variants view) -jb" - variants := (self allMethodBlocksContainingVariants collect: #containedVariants) flatten. - watchMethodBlocks := self allMethodBlocksContainingWatches. - activeExamples := self allActiveExamples. - permutations := SBPermutation allPermutationsOf: variants. - permutations ifEmpty: [self addAllWatchesFrom: watchMethodBlocks]. + self multiverse universes ifEmpty: [self block addAllMorphsBack: self mutliverse watches]. - [ permutations do: [:aPermutation | - SBActiveVariantPermutation value: aPermutation. - activeExamples do: #runSynchronouslyIgnoreReturn. - self buildPermutationFor: aPermutation collectingWatchesFrom: watchMethodBlocks]. - self resetWatchesToOriginalPermutationRunning: activeExamples] forkAt: Processor userSchedulingPriority + [ self multiverse universes do: [:aUniverse | + SBActiveVariantPermutation value: aUniverse activePermutation. + self multiverse activeExamples do: #runSynchronouslyIgnoreReturn. + self buildPermutationFor: aUniverse]. + self resetWatchesToOriginalPermutationRunning: self multiverse activeExamples] forkAt: Processor userSchedulingPriority ] { #category : #building } -SBResultsView >> buildPermutationFor: aPermutation collectingWatchesFrom: aCollectionOfMethodBlocks [ +SBResultsView >> buildPermutationFor: aSBUniverse [ - self block addAllMorphsBack: { SBOwnTextMorph new contents: aPermutation asString. - self applyButtonFor: aPermutation. + self block addAllMorphsBack: { SBOwnTextMorph new contents: aSBUniverse activePermutation asString. + self applyButtonFor: aSBUniverse activePermutation. (self containerRow listDirection: #leftToRight) - addAllMorphsBack: (self allWatchesIn: aCollectionOfMethodBlocks). + addAllMorphsBack: aSBUniverse watches. LineMorph from: 0@0 to: 50@0 color: Color black width: 2} ] diff --git a/packages/Sandblocks-Babylonian/SBUniverse.class.st b/packages/Sandblocks-Babylonian/SBUniverse.class.st new file mode 100644 index 00000000..a7c0483d --- /dev/null +++ b/packages/Sandblocks-Babylonian/SBUniverse.class.st @@ -0,0 +1,45 @@ +" +A codeflow state caused by a particular permutation, resulting in varying watches +" +Class { + #name : #SBUniverse, + #superclass : #Object, + #instVars : [ + 'activePermutation', + 'watches' + ], + #category : #'Sandblocks-Babylonian' +} + +{ #category : #'instance creation' } +SBUniverse class >> newActive: aSBPermutation watches: aCollectionOfSBExampleWatches [ + + ^ self new + activePermutation: aSBPermutation; + watches: aCollectionOfSBExampleWatches; + yourself +] + +{ #category : #accessing } +SBUniverse >> activePermutation [ + + ^ activePermutation +] + +{ #category : #accessing } +SBUniverse >> activePermutation: aSBPermutation [ + + activePermutation := aSBPermutation +] + +{ #category : #accessing } +SBUniverse >> watches [ + + ^ watches +] + +{ #category : #accessing } +SBUniverse >> watches: aCollectionOfSBExampleWatches [ + + watches := aCollectionOfSBExampleWatches +] diff --git a/packages/Sandblocks-Babylonian/SBVariantsView.class.st b/packages/Sandblocks-Babylonian/SBVariantsView.class.st index 034e9d63..2cd6c0ed 100644 --- a/packages/Sandblocks-Babylonian/SBVariantsView.class.st +++ b/packages/Sandblocks-Babylonian/SBVariantsView.class.st @@ -32,7 +32,7 @@ SBVariantsView >> visualize [ self clean. - self allMethodBlocksContainingVariants + self multiverse allMethodBlocksContainingVariants ifNotEmptyDo: [:theMethods | theMethods do: [:aSBStMethod | self buildMethodSectionFor: aSBStMethod]] ifEmpty: [self buildNoVariantsText] ]