Skip to content

Commit

Permalink
Backport changes from Pharo 12
Browse files Browse the repository at this point in the history
  • Loading branch information
theseion committed Dec 30, 2023
1 parent 02ee8a7 commit b43a4b4
Show file tree
Hide file tree
Showing 37 changed files with 50 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ tests-fuelAfterMaterialization
testExecuteAfterMaterialization

| anObject result aClass |
aClass := self classFactory silentlyMake: [ :aBuilder | aBuilder slotsFromString: 'a' ].
aClass := self classFactory silentlyMake: [ :aBuilder | aBuilder slots: #(a) ].
self classFactory silentlyCompile: 'fuelAfterMaterialization a := #A' in: aClass.
anObject := aClass new.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ tests-change
testBlockClosureMaterializesClassVariablesCorrectly

| class closure method |
class := self classFactory silentlyMake: [ :aBuilder | aBuilder sharedVariablesFromString: 'ClassVariableForTesting' ].
class := self classFactory silentlyMake: [ :aBuilder | aBuilder sharedVariables: #(ClassVariableForTesting)].
self classFactory silentlyCompile: 'methodWithClosure ^ [ ClassVariableForTesting ]' in: class.

method := class methodNamed: #methodWithClosure.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ tests
testMethodAccessingAClassVariable

| aClassWithVariable aMethod materializedMethod |
aClassWithVariable := self classFactory silentlyMake: [ :aBuilder | aBuilder sharedVariablesFromString: 'A' ].
aClassWithVariable := self classFactory silentlyMake: [ :aBuilder | aBuilder sharedVariables: #(A) ].

self classFactory silentlyCompile: 'm1 A:= 3' in: aClassWithVariable.
aMethod := aClassWithVariable >> #m1.
aClassWithVariable classVarNamed: #A put: 7.
aClassWithVariable writeClassVariableNamed: #A value: 7.

materializedMethod := self resultOfSerializeAndMaterialize: aMethod.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ tests
testMethodAccessingAClassVariableInADoit

| aClassWithVariable aMethod materializedMethod |
aClassWithVariable := self classFactory silentlyMake: [ :aBuilder | aBuilder sharedVariablesFromString: 'A' ].
aClassWithVariable := self classFactory silentlyMake: [ :aBuilder | aBuilder sharedVariables: #(A)].

self classFactory silentlyCompile: 'DoIt A:= 3' in: aClassWithVariable.
aMethod := aClassWithVariable >> #DoIt.
aClassWithVariable classVarNamed: #A put: 7.
aClassWithVariable writeClassVariableNamed: #A value: 7.

materializedMethod := self resultOfSerializeAndMaterialize: aMethod.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ testStreamFinalizerDefault

<ignoreNotImplementedSelectors: #( _log )>
| logClass log |
logClass := self classFactory silentlyMake: [ :aBuilder | aBuilder slotsFromString: 'log' ].
logClass := self classFactory silentlyMake: [ :aBuilder | aBuilder slots: #(log) ].
self classFactory
silentlyCompile: 'initialize log := OrderedCollection new' in: logClass;
silentlyCompile: '_log ^ log' in: logClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ testCreateClassWithClassVariable
"Tests materialization a class not defined in the image, with a class variable."

| aClass materializedClass |
aClass := self classFactory make: [ :aBuilder | aBuilder sharedVariablesFromString: #ClassVariable ].
aClass := self classFactory make: [ :aBuilder | aBuilder sharedVariables: #(ClassVariable) ].
(aClass classVariableNamed: #ClassVariable) write: #test.

materializedClass := self resultOfSerializeRemoveAndMaterialize: aClass.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ testCreateClassWithCreatedTraitWithInstanceVariable
The trait has instance variables."

| aClass aTrait result materializedClass materializedTrait materializedObject |
aClass := self classFactory silentlyMake: [ :aBuilder | aBuilder slotsFromString: 'ivar' ].
aClass := self classFactory silentlyMake: [ :aBuilder | aBuilder slots: #(ivar) ].
self classFactory silentlyCompile: 'ivar: x ivar := x' in: aClass.
self classFactory silentlyCompile: 'ivar ^ ivar' in: aClass.
aTrait := self classFactory silentlyMake: [ :aBuilder |
aBuilder
beTrait;
slotsFromString: 'traitIvar' ].
slots: #(traitIvar) ].
self classFactory silentlyCompile: 'traitIvar: x traitIvar := x' in: aTrait.
self classFactory silentlyCompile: 'traitIvar ^ traitIvar' in: aTrait.
aClass addToComposition: aTrait.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ testCreateClassWithInstance
"Tests materialization of a class who references an instance of itself."

| aClass anInstance materializedClass materializedInstance |
aClass := self classFactory make: [ :aBuilder | aBuilder slotsFromString: 'name' ].
aClass := self classFactory make: [ :aBuilder | aBuilder slots: #(name) ].
aClass class instanceVariableNames: 'instance'.

anInstance := aClass new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ testCreateClassWithVariables
"Tests materialization of a class not defined in the image, with instance variables."

| aClass materializedClass |
aClass := self classFactory make: [ :aBuilder | aBuilder slotsFromString: 'var1 var2' ].
aClass := self classFactory make: [ :aBuilder | aBuilder slots: #(var1 var2) ].

materializedClass := self resultOfSerializeRemoveAndMaterialize: aClass.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ testCreateWithClassVariableAccessors
"Tests materialization of a compiled method in a class not defined in the image. The class defines accessors for a class variable."

| aClass materializedClass instance |
aClass := self classFactory silentlyMake: [ :aBuilder | aBuilder sharedVariablesFromString: 'AnFLClassVariable' ].
aClass := self classFactory silentlyMake: [ :aBuilder | aBuilder sharedVariables: #(AnFLClassVariable) ].
self classFactory
silentlyCompile: 'classVariable ^AnFLClassVariable' in: aClass;
silentlyCompile: 'classVariable: value AnFLClassVariable := value' in: aClass.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ testMaterializationDoesNotModifySerializedClass
"Tests that materialization does not change the source class."

| aClass materializedClass |
aClass := self classFactory make: [ :aBuilder | aBuilder slotsFromString: 'var' ].
aClass := self classFactory make: [ :aBuilder | aBuilder slots: #(var) ].

self serializer fullySerializeBehavior: aClass.
self serialize: aClass.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ testCreateClassWithChangedSuperclassFormat
"Tests issue #221"

| a b |
a := self classFactory make: [ :aBuilder | aBuilder slotsFromString: 'one' ].
a := self classFactory make: [ :aBuilder | aBuilder slots: #(one) ].
b := self classFactory make: [ :aBuilder |
aBuilder
superclass: a;
slotsFromString: 'two' ].
slots: #(two) ].
self serializer fullySerializeBehavior: b.
self serialize: {
b new.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ testPostMaterializationActions
| aClass |
CompilationContext optionCleanBlockClosure ifTrue: [ ^ self skip ].

aClass := self classFactory make: [ :aBuilder | aBuilder sharedVariablesFromString: 'TestClassVariable TestClassVariable2' ].
aClass := self classFactory make: [ :aBuilder | aBuilder sharedVariables: #(TestClassVariable TestClassVariable2) ].
self classFactory
silentlyCompile: 'postLoadMethod TestClassVariable := 1' in: aClass class;
silentlyCompile: 'postLoadMethod2 TestClassVariable := 2' in: aClass class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ testPreMaterializationActions
| aClass |
CompilationContext optionCleanBlockClosure ifTrue: [ ^ self skip ].

aClass := self classFactory make: [ :aBuilder | aBuilder sharedVariablesFromString: 'TestClassVariable TestClassVariable2' ].
aClass := self classFactory make: [ :aBuilder | aBuilder sharedVariables: #(TestClassVariable TestClassVariable2) ].
self classFactory
silentlyCompile: 'postLoadMethod TestClassVariable := 1' in: aClass class;
silentlyCompile: 'postLoadMethod2 TestClassVariable := 2' in: aClass class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ testCreateClassWithCreatedTraitWithInstanceVariable
The trait has instance variables."

| aClass aTrait result materializedClass materializedTrait materializedObject |
aClass := self classFactory silentlyMake: [ :aBuilder | aBuilder slotsFromString: 'ivar' ].
aClass := self classFactory silentlyMake: [ :aBuilder | aBuilder slots: #(ivar) ].
self classFactory silentlyCompile: 'ivar: x ivar := x' in: aClass.
self classFactory silentlyCompile: 'ivar ^ ivar' in: aClass.
aTrait := self classFactory silentlyMake: [ :aBuilder |
aBuilder
beTrait;
slotsFromString: 'traitIvar' ].
slots: #(traitIvar) ].
self classFactory silentlyCompile: 'traitIvar: x traitIvar := x' in: aTrait.
self classFactory silentlyCompile: 'traitIvar ^ traitIvar' in: aTrait.
aClass addToComposition: aTrait.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ testPostMaterializationActions
| aClass |
CompilationContext optionCleanBlockClosure ifTrue: [ ^ self skip ].

aClass := self classFactory make: [ :aBuilder | aBuilder sharedVariablesFromString: 'TestClassVariable TestClassVariable2' ].
aClass := self classFactory make: [ :aBuilder | aBuilder sharedVariables: #(TestClassVariable TestClassVariable2) ].
self classFactory
silentlyCompile: 'postLoadMethod TestClassVariable := 1' in: aClass class;
silentlyCompile: 'postLoadMethod2 TestClassVariable := 2' in: aClass class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ testPreMaterializationActions
| aClass |
CompilationContext optionCleanBlockClosure ifTrue: [ ^ self skip ].

aClass := self classFactory make: [ :aBuilder | aBuilder sharedVariablesFromString: 'TestClassVariable TestClassVariable2' ].
aClass := self classFactory make: [ :aBuilder | aBuilder sharedVariables: #(TestClassVariable TestClassVariable2) ].
self classFactory
silentlyCompile: 'postLoadMethod TestClassVariable := 1' in: aClass class;
silentlyCompile: 'postLoadMethod2 TestClassVariable := 2' in: aClass class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ tests
testClassWithCachedValueByNil

| aClassWithCachedValue result original |
aClassWithCachedValue := self classFactory silentlyMake: [ :aBuilder | aBuilder slotsFromString: 'cache' ].
aClassWithCachedValue := self classFactory silentlyMake: [ :aBuilder | aBuilder slots: #(cache) ].
self classFactory
silentlyCompile: 'cache ^cache' in: aClassWithCachedValue;
silentlyCompile: 'cache: x cache := x' in: aClassWithCachedValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ testObjectByProxyThatBecomesItsContent
"Tests a substitution of an object by a proxy that becomes another object on materialization."

| aProxyClass result |
aProxyClass := self classFactory silentlyMake: [ :aBuilder | aBuilder slotsFromString: 'someState' ].
aProxyClass := self classFactory silentlyMake: [ :aBuilder | aBuilder slots: #(someState) ].
self classFactory
silentlyCompile: 'initialize someState := 5@1' in: aProxyClass;
silentlyCompile: 'fuelAccept: aVisitor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ tests
testProxyByTarget

| aProxyClass result original |
aProxyClass := self classFactory silentlyMake: [ :aBuilder | aBuilder sharedVariablesFromString: 'Target' ].
aProxyClass := self classFactory silentlyMake: [ :aBuilder | aBuilder sharedVariables: #(Target) ].
self classFactory
silentlyCompile: 'target: x Target := x' in: aProxyClass;
silentlyCompile: 'fuelAccept: aVisitor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ tests
testProxyByTargetAnalisysIsPropagated

| aProxyClass result pair original |
aProxyClass := self classFactory silentlyMake: [ :aBuilder | aBuilder sharedVariablesFromString: 'Target' ].
aProxyClass := self classFactory silentlyMake: [ :aBuilder | aBuilder sharedVariables: #(Target) ].
self classFactory
silentlyCompile: 'target: x Target := x' in: aProxyClass;
silentlyCompile: 'fuelAccept: aVisitor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ tests
testProxyByTargetInsideObjectAndAnalisysIsPropagated

| aProxyClass result original pair pairRoot |
aProxyClass := self classFactory silentlyMake: [ :aBuilder | aBuilder sharedVariablesFromString: 'Target' ].
aProxyClass := self classFactory silentlyMake: [ :aBuilder | aBuilder sharedVariables: #(Target) ].
self classFactory
silentlyCompile: 'target: x Target := x' in: aProxyClass;
silentlyCompile: 'fuelAccept: aVisitor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ tests
testProxyInsideObjectByTarget

| aProxyClass result original pair |
aProxyClass := self classFactory silentlyMake: [ :aBuilder | aBuilder sharedVariablesFromString: 'Target' ].
aProxyClass := self classFactory silentlyMake: [ :aBuilder | aBuilder sharedVariables: #(Target) ].
self classFactory
silentlyCompile: 'target: x Target := x' in: aProxyClass;
silentlyCompile: 'fuelAccept: aVisitor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ tests
testAllVariablesIgnored

| anObject result aClass |
aClass := self classFactory make: [ :aBuilder | aBuilder slotsFromString: 'a b' ].
aClass := self classFactory make: [ :aBuilder | aBuilder slots: #(a b) ].
self classFactory silentlyCompile: 'fuelIgnoredInstanceVariableNames ^#(a b)' in: aClass class.
anObject := aClass new
instVarAt: 1 put: $A;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ tests
testIgnoredValueIsNotMaterialized

| anObject materialized aClass |
aClass := self classFactory make: [ :aBuilder | aBuilder slotsFromString: 'a' ].
aClass := self classFactory make: [ :aBuilder | aBuilder slots: #(a) ].
self classFactory silentlyCompile: 'fuelIgnoredInstanceVariableNames ^#(a)' in: aClass class.
anObject := aClass new
instVarAt: 1 put: #A;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ tests
testOneIgnoredVariable

| anObject result aClass |
aClass := self classFactory make: [ :aBuilder | aBuilder slotsFromString: 'a b c' ].
aClass := self classFactory make: [ :aBuilder | aBuilder slots: #(a b c) ].
self classFactory silentlyCompile: 'fuelIgnoredInstanceVariableNames ^#(b)' in: aClass class.
anObject := aClass new
instVarAt: 1 put: $A;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ tests
testTwoIgnoredVariables

| anObject result aClass |
aClass := self classFactory make: [ :aBuilder | aBuilder slotsFromString: 'a b c' ].
aClass := self classFactory make: [ :aBuilder | aBuilder slots: #(a b c) ].
self classFactory silentlyCompile: 'fuelIgnoredInstanceVariableNames ^#(a c)' in: aClass class.
anObject := aClass new
instVarAt: 1 put: $A;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ redefined: aClass with: instanceVariableNames
^ self classFactory make: [ :aBuilder |
aBuilder
fillFor: aClass;
slotsFromString: instanceVariableNames ]
slots: instanceVariableNames ]
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ tests-manual
testBadDestinationVariableRename

| pointClass aPoint pointClassName |
pointClass := self classFactory make: [ :aBuilder | aBuilder slotsFromString: 'x y' ].
pointClass := self classFactory make: [ :aBuilder | aBuilder slots: #(x y) ].
pointClassName := pointClass name.
aPoint := pointClass new.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ testChangeInSuperclass
"Tests that serializer tolarates when there is a change in the superclass between serialization and materialization"

| aClass aClassSubclass instance materializedInstance |
aClass := self classFactory make: [ :aBuilder | aBuilder slotsFromString: 'a b c' ].
aClass := self classFactory make: [ :aBuilder | aBuilder slots: #(a b c) ].
aClassSubclass := self classFactory make: [ :aBuilder |
aBuilder
superclass: aClass;
slotsFromString: 'd e' ].
slots: #(d e) ].

instance := aClassSubclass new.
instance instVarNamed: 'a' put: $A.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ tests-manual
testClassAndVariableRename

| pointClass aPoint resultPoint pointClassName |
pointClass := self classFactory make: [ :aBuilder | aBuilder slotsFromString: 'x y' ].
pointClass := self classFactory make: [ :aBuilder | aBuilder slots: #(x y) ].
pointClassName := pointClass name.
aPoint := pointClass new.
aPoint instVarNamed: 'x' put: 7.
aPoint instVarNamed: 'y' put: 11.

self serialize: aPoint.
self classFactory silentlyRename: pointClass to: (pointClassName , 'Renamed') asSymbol.
pointClass := self redefined: pointClass with: 'posY posX'.
pointClass := self redefined: pointClass with: #(posY posX).

self materializer migrateClassNamed: pointClassName toClass: pointClass variables: (Dictionary new
at: 'x' put: 'posX';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ tests-manual
testClassRename

| pointClass aPoint resultPoint pointClassName |
pointClass := self classFactory make: [ :aBuilder | aBuilder slotsFromString: 'x y' ].
pointClass := self classFactory make: [ :aBuilder | aBuilder slots: #(x y) ].
pointClassName := pointClass name.
aPoint := pointClass new.
aPoint instVarNamed: 'x' put: 7.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ testSuperclassChange
"Tests that serializer tolarates when the superclass changed between serialization and materialization"

| aClass aClassSubclass instance materializedInstance anotherSuperclass |
aClass := self classFactory make: [ :aBuilder | aBuilder slotsFromString: 'a b c' ].
aClass := self classFactory make: [ :aBuilder | aBuilder slots: #(a b c) ].
aClassSubclass := self classFactory make: [ :aBuilder |
aBuilder
superclass: aClass;
slotsFromString: 'd e' ].
anotherSuperclass := self classFactory make: [ :aBuilder | aBuilder slotsFromString: 'x' ].
slots: #(d e) ].
anotherSuperclass := self classFactory make: [ :aBuilder | aBuilder slots: #(x) ].

instance := aClassSubclass new.
instance instVarNamed: 'a' put: $A.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ testVariableInsertion
"Tests that serializer tolarates when there is a new instance variable on materialization"

| pairClass aPair resultPair |
pairClass := self classFactory make: [ :aBuilder | aBuilder slotsFromString: 'left right' ].
pairClass := self classFactory make: [ :aBuilder | aBuilder slots: #(left right) ].
aPair := pairClass new.
aPair instVarAt: 1 put: $A.
aPair instVarAt: 2 put: $B.

self serialize: aPair.
self redefined: pairClass with: 'left middle right'.
self redefined: pairClass with: #(left middle right).
resultPair := self materialized.

self assert: $A equals: (resultPair instVarAt: 1).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ testVariableOrderChange
"Tests that serializer tolarates when the order in the instance variables changed between serialization and materialization"

| pairClass aPair resultPair |
pairClass := self classFactory make: [ :aBuilder | aBuilder slotsFromString: 'left right' ].
pairClass := self classFactory make: [ :aBuilder | aBuilder slots: #(left right) ].
aPair := pairClass new.
aPair instVarAt: 1 put: $A.
aPair instVarAt: 2 put: $B.

self serialize: aPair.
self redefined: pairClass with: 'right left'.
self redefined: pairClass with: #(right left).
resultPair := self materialized.

self assert: $B equals: (resultPair instVarAt: 1).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ testVariableRemoved
"Tests that serializer tolarates when an instance variable is missing on materialization"

| pairClass aPair resultPair |
pairClass := self classFactory make: [ :aBuilder | aBuilder slotsFromString: 'left right' ].
pairClass := self classFactory make: [ :aBuilder | aBuilder slots: #(left right) ].
aPair := pairClass new.
aPair instVarAt: 1 put: $A.
aPair instVarAt: 2 put: $B.

self serialize: aPair.
self redefined: pairClass with: 'right'.
self redefined: pairClass with: #(right).
resultPair := self materialized.

self assert: $B equals: (resultPair instVarAt: 1)
Loading

0 comments on commit b43a4b4

Please sign in to comment.