Skip to content

Commit

Permalink
Code refactoring, new collection of all watches when multiverse is cr…
Browse files Browse the repository at this point in the history
…eated
  • Loading branch information
JoeAtHPI committed May 7, 2024
1 parent f30610e commit ffb5756
Show file tree
Hide file tree
Showing 15 changed files with 96 additions and 68 deletions.
6 changes: 6 additions & 0 deletions packages/Sandblocks-Babylonian/Morph.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ Morph class >> exampleObject [
^ self new
]

{ #category : #'*Sandblocks-Babylonian' }
Morph >> isVariantProxy [

^ false
]

{ #category : #'*Sandblocks-Babylonian' }
Morph >> listensToPermutations [

Expand Down
4 changes: 2 additions & 2 deletions packages/Sandblocks-Babylonian/SBCorrelationView.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ SBCorrelationView >> buildForExample: anExample watching: aWatch [
self containerRow listDirection: #topToBottom;
addAllMorphsBack: {
SBOwnTextMorph new contents: (
'{1}{2}' format: {"anExample label" ''.
'{1}{2}' format: {anExample label.
(aWatch cleanedExpression sourceString withoutLineEndings)}).
self containerRow
listDirection: #topToBottom;
Expand Down Expand Up @@ -113,7 +113,7 @@ SBCorrelationView >> changeVariants [
SBCorrelationView >> collectAllPermutationsOfSelectedVariants [

| allPermutations |
selectedVariants ifEmpty: [^ {SBNilPermutation new referencedVariants: {}} asSet].
selectedVariants ifEmpty: [^ {SBPermutation singularity} asSet].
allPermutations := Set new.
groupedUniverses first do: [:aUniverseContainingSelected | | base |
base := SBPermutation new referencedVariants: selectedVariants.
Expand Down
14 changes: 0 additions & 14 deletions packages/Sandblocks-Babylonian/SBExampleWatch.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ SBExampleWatch class >> report: aValue for: aSymbol modifying: aBlock [
example := SBExecutionEnvironment value ifNil: [^ aValue].
watchers := self registry select: [:watcher | watcher notNil
and: [watcher identifier = aSymbol]
and: [watcher ignoreReports not]
and: [watcher isActive]].
watchers do: [:watcher | watcher reportValue: aValue asSBWatchValue for: example].

Expand Down Expand Up @@ -248,7 +247,6 @@ SBExampleWatch >> exampleFinished: anExample [
SBExampleWatch >> exampleStarting: anExample [

exampleToValues at: anExample put: OrderedCollection new.
self ignoreReports: false.

(exampleToDisplay at: anExample ifAbsentPut: [self buildDefaultDisplayFor: anExample])
exampleStarting: anExample;
Expand Down Expand Up @@ -326,18 +324,6 @@ SBExampleWatch >> identifier: aSymbol [
self world ifNotNil: [self class registerWatch: self]
]

{ #category : #accessing }
SBExampleWatch >> ignoreReports [

^ ignoreReports
]

{ #category : #accessing }
SBExampleWatch >> ignoreReports: aBoolean [

ignoreReports := aBoolean
]

{ #category : #initialization }
SBExampleWatch >> initialize [

Expand Down
8 changes: 7 additions & 1 deletion packages/Sandblocks-Babylonian/SBExploriants.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ SBExploriants >> evaluationReceiver [
^ self object
]

{ #category : #accessing }
SBExploriants >> generationTimeout [

^ 20 seconds
]

{ #category : #accessing }
SBExploriants >> ignoreUpdate [

Expand Down Expand Up @@ -221,7 +227,7 @@ SBExploriants >> updateInBackgroundOnTimeoutRevertTo: theOldMultiverse [
newMultiverse := SBMultiverse bigbangInEditorWithoutKaboom: self sandblockEditor.
self namedBlocks do: [:aTab | aTab multiverse: newMultiverse].
[newMultiverse kaboom]
valueWithin: 20 seconds
valueWithin: self generationTimeout
onTimeout: [newMultiverse cleanUp.
self namedBlocks do: [:aTab | aTab multiverse: theOldMultiverse]].
updateProcess := nil. updateProcessRunning := false.
Expand Down
3 changes: 2 additions & 1 deletion packages/Sandblocks-Babylonian/SBGridResultsView.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@ SBGridResultsView >> newGridContainer [
SBGridResultsView >> visualize [

super visualize.
self concludeContainerWidth
self concludeContainerWidth.

]
27 changes: 9 additions & 18 deletions packages/Sandblocks-Babylonian/SBMultiverse.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,7 @@ SBMultiverse >> asyncKaboom [
SBMultiverse >> cleanUp [

watches do: #resumeGraphicalUpdates.
(watches select: [:anOpenWatch | anOpenWatch containingArtefact isNil]) copy do: #delete.
watches select: #isInEditor thenDo: [:aWatch | aWatch exampleToDisplay values do: #updateDisplay].
allMethodBlocksContainingWatches do: [:aMethodBlock |
(aMethodBlock valueOfProperty: #originals) do: [:aWatch| aWatch ignoreReports: false]].
watches reject: #isInEditor thenDo: [:aWatch | SBExampleWatch unregisterWatch: aWatch].
]

{ #category : #collecting }
Expand Down Expand Up @@ -174,16 +171,9 @@ SBMultiverse >> gatherVariants [
{ #category : #'initialize-release' }
SBMultiverse >> gatherWatches [

allMethodBlocksContainingWatches := self findExistingOrConvertToBlocksMaintainingWatches: self allCompiledMethodsContainingExampleWatches.
allMethodBlocksContainingWatches := self findExistingOrConvertToBlocks: self allCompiledMethodsContainingExampleWatches.

watches := (allMethodBlocksContainingWatches collect: [:aMethodBlock | | copies |
copies := aMethodBlock containedExampleWatches.
"Because the watches share the id, values would be reported to original too. Stop that"
(aMethodBlock valueOfProperty: #originals) do: [:aWatch| aWatch ignoreReports: true].
(aMethodBlock valueOfProperty: #originals) withIndexDo: [:original :i | (copies at: i) copySelectedDisplayIndicesFrom: original].
copies ]) flatten.
watches do: [:aWatch | activeExamples do: [:anExample | aWatch exampleStarting: anExample]].
watches reject: #isInEditor thenDo: [:aWatch | aWatch hide. aWatch extent: 1@1]
watches := (allMethodBlocksContainingWatches collect: #containedExampleWatches) flatten.

]

Expand All @@ -198,15 +188,16 @@ SBMultiverse >> initialize [
{ #category : #actions }
SBMultiverse >> kaboom [

| outOfWorldWatches permutations |
"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 := (SBPermutation allPermutationsOf: variants).
| permutations |
watches do: #stopGraphicalUpdates.
watches reject: #isInEditor thenDo: [:aWatch |
SBExampleWatch registerWatch: aWatch.
activeExamples do: [:anExample | aWatch exampleStarting: anExample]].
permutations := (SBPermutation allPermutationsOf: variants).

"Running the active one last"
(permutations sorted: [:a :b | a activeScore <= b activeScore ] ) do: [:aPermutation |
self runPermutation: aPermutation copyingWatches: watches ].
self runPermutation: aPermutation copyingWatches: watches].

"but stay consistent of the permutation sequences for alignment in clusters"
"sorting this is cheaper than running a permutation twice just to reset to prior state"
Expand Down
2 changes: 1 addition & 1 deletion packages/Sandblocks-Babylonian/SBPlainResultsView.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ SBPlainResultsView >> initialize [

super initialize.

self name: 'Watches'
self name: 'Probes'
]
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ SBSwitchableResultsView >> toggleViewButton [

^ SBButton new
icon: self toggleIcon
label: 'Group By Watches <> In Execution Order'
label: 'Group By Probes <> In Execution Order'
do: [self toggleView];
cornerStyle: #squared
]
Expand Down
4 changes: 2 additions & 2 deletions packages/Sandblocks-Babylonian/SBTrace.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ SBTrace >> sortedWatchValuesFor: anExample givenWatches: aCollectionOfWatches [
| allValues |
allValues := SortedCollection sortBlock: [:a :b | a tracePosition <= b tracePosition].
aCollectionOfWatches do: [:aWatch |
aWatch exampleToValues at: anExample
ifPresent: [:aCollectionOfWatchValues | allValues addAll: aCollectionOfWatchValues ]
aWatch exampleToDisplay at: anExample
ifPresent: [:aDisplay | allValues addAll: aDisplay value display watchValues ]
ifAbsent: [{}]].
^ allValues
]
Expand Down
6 changes: 3 additions & 3 deletions packages/Sandblocks-Core/Collection.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Collection >> asBarChart: converter [
<convert>

converter
if: [self isString not and: [self allSatisfy: SBBarChart supportedInterface]]
if: [self allSatisfy: SBBarChart supportedInterface]
do: [SBBarChart newWithValues: self]
]

Expand All @@ -23,7 +23,7 @@ Collection >> asLineChart: converter [
<convert>

converter
if: [self isString not and: [self allSatisfy: SBLineChart supportedInterface]]
if: [self allSatisfy: SBLineChart supportedInterface]
do: [SBLineChart newWithValues: self]
]

Expand All @@ -32,7 +32,7 @@ Collection >> asRectangleChart: converter [
<convert>

converter
if: [self isString not and: [self isDictionary not and: [self allSatisfy: SBRectangleChart supportedInterface]]]
if: [self allSatisfy: SBRectangleChart supportedInterface]
do: [SBRectangleChart newWithValues: self]
]

Expand Down
12 changes: 7 additions & 5 deletions packages/Sandblocks-Smalltalk/SBVariant.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,7 @@ SBVariant >> allPermutations: allPermutations currentPath: aPermutation [
ifEmpty: [allPermutations add: currentPath]
ifNotEmpty: [:childVariants | | permutations nestedPermutations |
nestedPermutations := childVariants collect: [:child | child allPermutations: OrderedCollection new currentPath: currentPath].
permutations := nestedPermutations first.
(2 to: topLevelVariants size) do: [:index | | nestedPermutation |
nestedPermutation := nestedPermutations at: index.
permutations := permutations gather: [:aNestedPermutation |
nestedPermutation collect: [:aNestedNestedPermutation | SBPermutation newCombinedOf: aNestedPermutation and: aNestedNestedPermutation]]].
permutations := SBPermutation combineAllIn: nestedPermutations.
allPermutations addAll: permutations.
permutations ]]
]
Expand Down Expand Up @@ -263,6 +259,12 @@ SBVariant >> color [
^ Color transparent
]

{ #category : #accessing }
SBVariant >> hasParent [

^ self parentVariant isNil not
]

{ #category : #accessing }
SBVariant >> id [
^ id
Expand Down
23 changes: 20 additions & 3 deletions packages/Sandblocks-Smalltalk/SBVariantProxy.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ SBVariantProxy class >> for: aVariant [
^ self new for: aVariant
]

{ #category : #accessing }
SBVariantProxy >> activeIndex [

^ original activeIndex
]

{ #category : #callbacks }
SBVariantProxy >> artefactChanged: anArtefact [

Expand Down Expand Up @@ -60,6 +66,12 @@ SBVariantProxy >> for: aVariant [
self addMorphBack: original copyBlock.
]

{ #category : #accessing }
SBVariantProxy >> id [

^ original id
]

{ #category : #initialization }
SBVariantProxy >> initialize [

Expand All @@ -79,6 +91,12 @@ SBVariantProxy >> isArtefact [
^ true
]

{ #category : #testing }
SBVariantProxy >> isVariantProxy [

^ true
]

{ #category : #accessing }
SBVariantProxy >> original [

Expand Down Expand Up @@ -106,12 +124,11 @@ SBVariantProxy >> updateOriginalWithOwnValues [

| variantThatNeedsChanging |
variantThatNeedsChanging := self containedMethod detectVariant: original.

variantThatNeedsChanging ifNil: [^self delete].

original replaceBy: (original := self firstSubmorph copyBlock).
original isVariant
ifFalse: [
"If a double click on the widget occured and it replaced itself with code or text"
original isVariant ifFalse: [
self containedMethod save.
^ self delete].

Expand Down
43 changes: 31 additions & 12 deletions packages/Sandblocks-Utils/SBPermutation.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,32 @@ Class {
{ #category : #utils }
SBPermutation class >> allPermutationsOf: aCollectionOfVariants [

| permutations topLevelVariants nestedPermutations |
aCollectionOfVariants ifEmpty:[^{SBNilPermutation new referencedVariants: {}}].
topLevelVariants := aCollectionOfVariants select: [:aVariant | aVariant parentVariant isNil].
| topLevelVariants nestedPermutations |
aCollectionOfVariants ifEmpty:[^{SBPermutation singularity}].
topLevelVariants := aCollectionOfVariants reject: #hasParent.
nestedPermutations := topLevelVariants collect: #allPermutations.
permutations := nestedPermutations first.

(2 to: topLevelVariants size) do: [:i | | nestedPermutation |
nestedPermutation := (nestedPermutations at: i).
permutations := permutations gather: [:aPermutation |
nestedPermutation collect: [:aNestedPermutation | self newCombinedOf: aPermutation and: aNestedPermutation]]].

^ permutations

^ SBPermutation combineAllIn: nestedPermutations.
]

{ #category : #utils }
SBPermutation class >> combine: aPermutation withAll: aCollectionOfPermutations [

^ aCollectionOfPermutations collect: [:anotherPermutation |
self newCombinedOf: aPermutation and: anotherPermutation]
]

{ #category : #utils }
SBPermutation class >> combineAllIn: aCollectionOfNestedPermutations [

| combinedPermutations |
combinedPermutations := aCollectionOfNestedPermutations first.
(2 to: aCollectionOfNestedPermutations size) do: [:index | | aCollectionOfPermutations |
aCollectionOfPermutations := aCollectionOfNestedPermutations at: index.
combinedPermutations := combinedPermutations gather: [:aPermutation |
SBPermutation combine: aPermutation withAll: aCollectionOfPermutations]].

^ combinedPermutations
]

{ #category : #utils }
Expand All @@ -42,6 +55,12 @@ SBPermutation class >> newCombinedOf: onePermutation and: anotherPermutation [

]

{ #category : #utils }
SBPermutation class >> singularity [

^ SBNilPermutation new referencedVariants: {}
]

{ #category : #accessing }
SBPermutation >> activeScore [

Expand Down Expand Up @@ -151,7 +170,7 @@ SBPermutation >> copyRemovingVariants: aCollectionOfVariants [
| copy |
copy := self class new.
copy referencedVariants: (self referencedVariants reject: [:aVariant | aCollectionOfVariants includes: aVariant]).
copy referencedVariants ifEmpty: [^ SBNilPermutation new referencedVariants: {}].
copy referencedVariants ifEmpty: [^ SBPermutation singularity].
"copy := self veryDeepCopy.
copy referencedVariants: (copy referencedVariants difference: aCollectionOfVariants)."

Expand Down
6 changes: 3 additions & 3 deletions packages/Sandblocks-Watch/SBLineChart.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ SBLineChart >> datapointDefaultColor [
{ #category : #'visualization - constants' }
SBLineChart >> datapointExtent [

^ 2@2
^ 3@3 sbScaled
]

{ #category : #geometry }
Expand All @@ -60,7 +60,7 @@ SBLineChart >> lineColorFrom: aDataPoint1 to: aDataPoint2 [
{ #category : #'visualization - constants' }
SBLineChart >> lineWidth [

^ 2
^ 2 sbScaled
]

{ #category : #'visualization - constants' }
Expand Down Expand Up @@ -166,7 +166,7 @@ SBLineChart >> positiveGradientColor [
{ #category : #'visualization - constants' }
SBLineChart >> spaceBetweenPoints [

^ 6
^ 6 sbScaled
]

{ #category : #visualization }
Expand Down
4 changes: 2 additions & 2 deletions packages/Sandblocks-Watch/SBWatchView.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ SBWatchView >> layoutCommands [
{ #category : #layout }
SBWatchView >> maxWidth [

^ 350
^ 350 sbScaled
]

{ #category : #'object interface' }
Expand Down Expand Up @@ -309,7 +309,7 @@ SBWatchView >> reportValues: aCollectionOfWatchValues sized: aMorphResizer [
SBWatchView >> resetOnlyValues [
"Private"

count contents: '0'.
shouldUpdateDisplay ifTrue: [count contents: '0'].
watchValues := LinkedList new.

]
Expand Down

0 comments on commit ffb5756

Please sign in to comment.