-
-
Notifications
You must be signed in to change notification settings - Fork 346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clean method removal of RPackage #14360
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -216,36 +216,20 @@ RPackage >> addClassTag: aSymbol [ | |
{ #category : #'add method - compiled method' } | ||
RPackage >> addMethod: aCompiledMethod [ | ||
"Add the method to the receiver as a defined method if the class is defined in it, else as an extension." | ||
| methodClass | | ||
|
||
| methodClass | | ||
methodClass := aCompiledMethod methodClass. | ||
(self includesClass: methodClass ) | ||
(self includesClass: methodClass) | ||
ifTrue: [ | ||
methodClass isMeta | ||
ifTrue: [ | ||
(metaclassDefinedSelectors | ||
at: methodClass instanceSide name | ||
ifAbsentPut: [ Set new ]) | ||
add: aCompiledMethod selector] | ||
ifFalse: [ | ||
(classDefinedSelectors | ||
at: methodClass name | ||
ifAbsentPut: [ Set new ]) | ||
add: aCompiledMethod selector ] ] | ||
ifFalse: [ | ||
ifTrue: [ (metaclassDefinedSelectors at: methodClass instanceSide name ifAbsentPut: [ Set new ]) add: aCompiledMethod selector ] | ||
ifFalse: [ (classDefinedSelectors at: methodClass name ifAbsentPut: [ Set new ]) add: aCompiledMethod selector ] ] | ||
ifFalse: [ | ||
methodClass isMeta | ||
ifTrue: [ | ||
(metaclassExtensionSelectors | ||
at: methodClass instanceSide name | ||
ifAbsentPut: [ Set new ]) | ||
add: aCompiledMethod selector.] | ||
ifFalse: [ | ||
(classExtensionSelectors | ||
at: methodClass name | ||
ifAbsentPut: [ Set new ]) | ||
add: aCompiledMethod selector]. | ||
"we added a method extension so the receiver is an extending package of the class" | ||
self organizer registerExtendingPackage: self forClass: methodClass ]. | ||
ifTrue: [ (metaclassExtensionSelectors at: methodClass instanceSide name ifAbsentPut: [ Set new ]) add: aCompiledMethod selector ] | ||
ifFalse: [ (classExtensionSelectors at: methodClass name ifAbsentPut: [ Set new ]) add: aCompiledMethod selector ]. | ||
"we added a method extension so the receiver is an extending package of the class" | ||
self organizer registerExtendingPackage: self forClass: methodClass ]. | ||
|
||
^ aCompiledMethod | ||
] | ||
|
@@ -287,31 +271,6 @@ RPackage >> basicImportClass: aClass [ | |
thenDo: [ :protocol | self importProtocol: protocol forClass: aClass ] | ||
] | ||
|
||
{ #category : #'add method - selector' } | ||
RPackage >> basicRemoveSelector: aSelector ofClassName: aClassName [ | ||
"Remove the method in the package but does not propagate to the class itself. Note that this method does not remove the method from the class, it just records in the package that the method is not in the package anymore." | ||
|
||
| selectors | | ||
|
||
selectors := ( self includesClassNamed: aClassName) | ||
ifFalse: [(classExtensionSelectors at: aClassName ifAbsent: [ ^ Set new])] | ||
ifTrue: [(classDefinedSelectors at: aClassName ifAbsent: [ ^ Set new])]. | ||
|
||
selectors remove: aSelector ifAbsent: [ ] | ||
] | ||
|
||
{ #category : #'add method - selector' } | ||
RPackage >> basicRemoveSelector: aSelector ofMetaclassName: aClassName [ | ||
"Remove the method in the package. Note that this method does not remove the method from the class, it just records in the package that the method is not in the package anymore. aClassName is the sole instance class name and not its metaclass one: i.e. adding Point class>>new is done as removeSelector: #new ofMetaclassName: #Point" | ||
|
||
| selectors | | ||
selectors := ( self includesClassNamed: aClassName) | ||
ifFalse: [(metaclassExtensionSelectors at: aClassName ifAbsent: [ ^ Set new])] | ||
ifTrue: [(metaclassDefinedSelectors at: aClassName ifAbsent: [ ^ Set new])]. | ||
|
||
selectors remove: aSelector ifAbsent: [ ] | ||
] | ||
|
||
{ #category : #'class tags' } | ||
RPackage >> basicRemoveTag: tag [ | ||
|
||
|
@@ -1229,18 +1188,34 @@ RPackage >> removeFromSystem [ | |
{ #category : #'add method - compiled method' } | ||
RPackage >> removeMethod: aCompiledMethod [ | ||
"Remove the method to the receiver as a defined method." | ||
| methodClass | | ||
|
||
| methodClass | | ||
methodClass := aCompiledMethod methodClass. | ||
methodClass isMeta | ||
(self includesClass: methodClass) | ||
ifTrue: [ | ||
self | ||
removeSelector: aCompiledMethod selector | ||
ofMetaclassName: methodClass instanceSide originalName ] | ||
methodClass isMeta | ||
ifTrue: [ | ||
metaclassDefinedSelectors at: methodClass instanceSide originalName ifPresent: [ :methods | | ||
methods remove: aCompiledMethod selector ifAbsent: [ ]. | ||
methods ifEmpty: [ metaclassDefinedSelectors removeKey: methodClass instanceSide originalName ] ] ] | ||
ifFalse: [ | ||
classDefinedSelectors at: methodClass originalName ifPresent: [ :methods | | ||
methods remove: aCompiledMethod selector ifAbsent: [ ]. | ||
methods ifEmpty: [ classDefinedSelectors removeKey: methodClass originalName ] ] ] ] | ||
ifFalse: [ | ||
self | ||
removeSelector: aCompiledMethod selector | ||
ofClassName: methodClass originalName ]. | ||
methodClass isMeta | ||
ifTrue: [ | ||
metaclassExtensionSelectors at: methodClass instanceSide originalName ifPresent: [ :methods | | ||
methods remove: aCompiledMethod selector ifAbsent: [ ]. | ||
methods ifEmpty: [ metaclassExtensionSelectors removeKey: methodClass instanceSide originalName ] ] ] | ||
ifFalse: [ | ||
classExtensionSelectors at: methodClass originalName ifPresent: [ :methods | | ||
methods remove: aCompiledMethod selector ifAbsent: [ ]. | ||
methods ifEmpty: [ classExtensionSelectors removeKey: methodClass originalName ] ] ] ]. | ||
Comment on lines
+1206
to
+1214
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be nice to hide and reuse the use of the cache in both methods. Maybe delegating to methods
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm planning to kill some of those caches. For now I'm trying to make the code simpler so that I can do my changes. I also want to merge the class and metaclass caches because it's a bother to always check the #isMeta to call two different methods. Once this is done, I'll see if we can improve further the use of the extension selectors :) |
||
|
||
((metaclassExtensionSelectors at: methodClass instanceSide originalName ifAbsent: [ #( ) ]) isEmpty and: [ | ||
(classExtensionSelectors at: methodClass instanceSide originalName ifAbsent: [ #( ) ]) isEmpty ]) ifTrue: [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Copy-paste issue? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no issue because here we are in the #ifFalse: of But as I said in another comment, I would like to remove the meta/non meta management to use one unified way. |
||
self organizer unregisterExtendingPackage: self forClassName: methodClass instanceSide originalName ]. | ||
|
||
^ aCompiledMethod | ||
] | ||
|
@@ -1274,42 +1249,6 @@ RPackage >> removeProperty: propName ifAbsent: aBlock [ | |
^ property | ||
] | ||
|
||
{ #category : #'add method - selector' } | ||
RPackage >> removeSelector: aSelector ofClassName: aClassName [ | ||
"Remove the method in the package but does not propagate to the class itself. Note that this method does not remove the method from the class, it just records in the package that the method is not in the package anymore." | ||
|
||
self basicRemoveSelector: aSelector ofClassName: aClassName. | ||
(classExtensionSelectors at: aClassName ifAbsent: [ #() ]) ifEmpty: [ | ||
classExtensionSelectors removeKey: aClassName ifAbsent: []. | ||
]. | ||
(classDefinedSelectors at: aClassName ifAbsent: [ #() ]) ifEmpty: [ | ||
classDefinedSelectors removeKey: aClassName ifAbsent: []. | ||
]. | ||
|
||
((metaclassExtensionSelectors at: aClassName ifAbsent: [#()]) isEmpty and: [(classExtensionSelectors at: aClassName ifAbsent: [#()]) isEmpty]) | ||
ifTrue: [ | ||
self organizer unregisterExtendingPackage: self forClassName: aClassName | ||
] | ||
] | ||
|
||
{ #category : #'add method - selector' } | ||
RPackage >> removeSelector: aSelector ofMetaclassName: aClassName [ | ||
"Remove the method in the package. Note that this method does not remove the method from the class, it just records in the package that the method is not in the package anymore. aClassName is the sole instance class name and not its metaclass one: i.e. adding Point class>>new is done as removeSelector: #new ofMetaclassName: #Point" | ||
|
||
self basicRemoveSelector: aSelector ofMetaclassName: aClassName. | ||
(metaclassExtensionSelectors at: aClassName ifAbsent: [ #() ]) ifEmpty: [ | ||
metaclassExtensionSelectors removeKey: aClassName ifAbsent: []. | ||
]. | ||
(metaclassDefinedSelectors at: aClassName ifAbsent: [ #() ]) ifEmpty: [ | ||
metaclassDefinedSelectors removeKey: aClassName ifAbsent: []. | ||
]. | ||
|
||
((metaclassExtensionSelectors at: aClassName ifAbsent: [#()]) isEmpty and: [(classExtensionSelectors at: aClassName ifAbsent: [#()]) isEmpty]) | ||
ifTrue: [ | ||
self organizer unregisterExtendingPackage: self forClassName: aClassName | ||
] | ||
] | ||
|
||
{ #category : #private } | ||
RPackage >> renameExtensionsPrefixedWith: oldName to: newName [ | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On add is used
name
as key, but here is usingoriginalName
. What's the difference?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difference happens with ObsoleteClasses. #name will return the obsolete name while #originalName will return the name of the class when it was not obsolete.
In the end I would like to have real classes instead of class names in the caches so that we do not have to care about that (and so that we do not have to cast them each time we want a class)