Skip to content

Commit

Permalink
Merge pull request #144 from hpi-swa/feature/enhancements
Browse files Browse the repository at this point in the history
SBExploriants Refactorings
  • Loading branch information
tom95 authored May 19, 2024
2 parents 01304ac + 020c41c commit 0276240
Show file tree
Hide file tree
Showing 19 changed files with 199 additions and 99 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
21 changes: 20 additions & 1 deletion packages/Sandblocks-Babylonian/SBExploriants.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ SBExploriants >> buttonClass [
SBExploriants >> cacheType: aClass for: aBlock [
]

{ #category : #actions }
SBExploriants >> changeIndexOf: aVariantId to: aNewIndex [

namedBlocks detect: #isVariantsView
ifFound: [:variantsView | variantsView changeIndexOf: aVariantId to: aNewIndex]
]

{ #category : #testing }
SBExploriants >> evaluationContext [

Expand All @@ -105,6 +112,12 @@ SBExploriants >> evaluationReceiver [
^ self object
]

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

^ 20 seconds
]

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

Expand Down Expand Up @@ -214,13 +227,19 @@ 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.
] forkAt: Processor userBackgroundPriority.
]

{ #category : #actions }
SBExploriants >> variantsView [

^ namedBlocks detect: #isVariantsView
]

{ #category : #actions }
SBExploriants >> visualize [

Expand Down
6 changes: 6 additions & 0 deletions packages/Sandblocks-Babylonian/SBExploriantsView.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ SBExploriantsView >> isOverview [
^false
]

{ #category : #accessing }
SBExploriantsView >> isVariantsView [

^ false
]

{ #category : #accessing }
SBExploriantsView >> multiverse [

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.

]
49 changes: 27 additions & 22 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: true]].
watches reject: #isInEditor thenDo: [:aWatch | SBExampleWatch unregisterWatch: aWatch].
]

{ #category : #collecting }
Expand Down Expand Up @@ -149,27 +146,34 @@ SBMultiverse >> findExistingOrConvertToBlocksMaintainingWatches: aCollectionOfCo
{ #category : #'initialize-release' }
SBMultiverse >> gatherElements [

universes := OrderedCollection new.
activeExamples := self allActiveExamples.

self gatherVariants.

self gatherWatches

]

{ #category : #'initialize-release' }
SBMultiverse >> gatherVariants [

"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.

allMethodBlocksContainingWatches := self findExistingOrConvertToBlocksMaintainingWatches: self allCompiledMethodsContainingExampleWatches.

universes := OrderedCollection new.
activeExamples := self allActiveExamples.

variants := (allMethodBlocksContainingVariants collect: #containedVariants) flatten.
variants := variants select: #isActive.

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]
]

{ #category : #'initialize-release' }
SBMultiverse >> gatherWatches [

allMethodBlocksContainingWatches := self findExistingOrConvertToBlocks: self allCompiledMethodsContainingExampleWatches.

watches := (allMethodBlocksContainingWatches collect: #containedExampleWatches) flatten.

]

Expand All @@ -184,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
31 changes: 26 additions & 5 deletions packages/Sandblocks-Babylonian/SBVariantsView.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,33 @@ Class {
{ #category : #building }
SBVariantsView >> buildMethodSectionFor: aSBStMethod [

| newProxy |
newProxy := aSBStMethod containedVariants collect: #asProxy.
contents addAllMorphsBack: {aSBStMethod methodDefinition.
self containerRow
addAllMorphsBack: (aSBStMethod containedVariants collect: #asProxy).
self containerRow addAllMorphsBack: newProxy.
LineMorph from: 0@0 to: 50@0 color: Color black width: 2}
]

{ #category : #building }
SBVariantsView >> buildNoVariantsText [

contents addMorphBack: (SBOwnTextMorph new contents: 'No variants exist.')
contents addMorphBack: (SBOwnTextMorph new contents: 'No variation points exist.')
]

{ #category : #actions }
SBVariantsView >> changeIndexOf: aVariantId to: aNewIndex [

self proxies
detect: [:aProxy | aProxy original id = aVariantId]
ifFound: [:theProxy | theProxy changeActiveIndexTo: aNewIndex ]
]

{ #category : #actions }
SBVariantsView >> clean [

super clean.

contents submorphs copy do: #delete
contents submorphs copy do: #delete.

]

Expand All @@ -38,7 +47,19 @@ SBVariantsView >> initialize [

contents := self containerRow listDirection: #topToBottom.

self name: 'Variants'.
self name: 'Variation Points'.
]

{ #category : #accessing }
SBVariantsView >> isVariantsView [

^ true
]

{ #category : #actions }
SBVariantsView >> proxies [

^ (contents allMorphs select: [:aMorph | aMorph isKindOf: SBVariantProxy])
]

{ #category : #copying }
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 isDictionary 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 isDictionary 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
2 changes: 2 additions & 0 deletions packages/Sandblocks-Core/SBTabView.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ SBTabView >> asTabButton: aNamedBlock [
{ #category : #tabs }
SBTabView >> basicSetActive: aNamedBlock [

self sandblockEditor ifNil: [^ self activeIndex: (self namedBlocks indexOf: aNamedBlock ifAbsent: 1)].

self sandblockEditor do:
(self switchCommandFor: (self namedBlocks indexOf: aNamedBlock ifAbsent: 1)).

Expand Down
16 changes: 0 additions & 16 deletions packages/Sandblocks-Smalltalk/SBStGrammarHandler.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -462,22 +462,6 @@ SBStGrammarHandler >> useThirdArgument [
self useArgument: 3
]
{ #category : #'action helpers' }
SBStGrammarHandler >> variantNameFor: aCollectionOfBlocks in: aParentBlock [
aParentBlock sandblockEditor = aParentBlock ifTrue: [^ aCollectionOfBlocks printString].
aParentBlock isTopLevel ifTrue: [^ aParentBlock printString].
aParentBlock isMessageSend ifTrue: [^ aCollectionOfBlocks first submorphBefore printString].
(aParentBlock isAssignment and: [aParentBlock receiver isVariant not]) ifTrue: [^ aParentBlock receiver sourceString, ' := '].
aCollectionOfBlocks size = 1 ifTrue: [^ aCollectionOfBlocks first sourceString].
^ '{1}' format: {(aCollectionOfBlocks collect: [:aBlock | aBlock sourceString])
fold: [:a :b | a, ', ', Character cr, b ]}
]
{ #category : #'action helpers' }
SBStGrammarHandler >> variantNameFor: aCollectionOfBlocks in: aParentBlock preceedingBlock: aNeighbor [
Expand Down
14 changes: 8 additions & 6 deletions packages/Sandblocks-Smalltalk/SBVariant.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ SBVariant class >> named: aString associations: aCollectionOfAssociations active

requestor := thisContext sender receiver.
"The requesting object does not require dynamic update behavior in which it needs to know a certain alternative"
SBExploriants objectToPermutation at: (requestor := thisContext sender receiver) ifAbsent: [^ defaultBehavior value].
SBExploriants objectToPermutation at: requestor ifAbsent: [^ defaultBehavior value].
"The permutation is outdated and does not know this variant"
(requiredPermutation := SBExploriants objectToPermutation at: requestor) at: uuid ifAbsent: [^ defaultBehavior value].
"An outdated permutation in which an alternative with a higher index than current has been deleted"
Expand Down 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
Loading

0 comments on commit 0276240

Please sign in to comment.