Skip to content
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

11965-Implement-ContextactiveHome-without-using-home #12063

Conversation

MarcusDenker
Copy link
Member

@MarcusDenker MarcusDenker commented Dec 7, 2022

  • implement #activeHome to not need outerContext
  • add test
  • refactor existing test

fixes #11965

#activeHome returns the #home if it is currently on the stack, the debugger uses that to check if a “save and proceed”
is possible when editing code in a Block. It is implemented to search up the sender chain until it finds the #home:

activeHome
	| methodReturnContext |
	self isBlockContext ifFalse: [^self].
	self sender ifNil: [^nil].
	methodReturnContext := self methodReturnContext.
	^self sender findContextSuchThat: [:ctxt | ctxt = methodReturnContext]

But it can be rewritten to do the same, but checking for the #homeMethod:

activeHome
	| homeMethod |
	self isBlockContext ifFalse: [^self].
	homeMethod := self homeMethod.
	^self findMethodContextSuchThat: [:ctxt | ctxt method == homeMethod]

With #homeMethod being implemented to delegate to the bock:

Context>>homeMethod
	"Answer the method in which the receiver was defined, i.e. the context from which an ^-return ] should return from. Note: implemented to not need #home"

	^ closureOrNil ifNil: [ self method ] ifNotNil: [ :closure | closure homeMethod ]

Where, if no #outerContext is available, it asks the CompiledBlock:

BlockClosure>>homeMethod
	"return the home method. If no #home is available due to no outerContext, use the compiledBlock"
	^ (self home
		   ifNotNil: [ :homeContext | homeContext ]
		   ifNil: [ self compiledBlock ]) method

Which uses the static #outerCode chain (CompiledBlocks encode have a back-pointer to the enclosing block or method),
with #method following #outerCode until it reaches a CompiledMethod:

CompiledBlock>>method
	"answer the compiled method that I am installed in, or nil if none.”
	^self outerCode method

@MarcusDenker
Copy link
Member Author

Bootstrap error:


Instance of CleanBlockClosure did not understand #asExportedLiteral
CleanBlockClosure(Object)>>doesNotUnderstand: #asExportedLiteral
[ :e | e asExportedLiteral ] in HEMethod>>fillLiteralsAndBytecode: in Block: [ :e | e asExportedLiteral ]
Array(SequenceableCollection)>>collect:
HEMethod>>fillLiteralsAndBytecode:
HERing2ToHermesBuilder>>visitMethod:

I will move the test to the compiler package for now and open an issue for Hermes to support CleanBlocks

@MarcusDenker
Copy link
Member Author

Failing teset not related:

@MarcusDenker MarcusDenker merged commit bafe42c into pharo-project:Pharo11 Dec 12, 2022
@MarcusDenker MarcusDenker deleted the 11965-Implement-ContextactiveHome-without-using-home branch December 12, 2022 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Context>>#activeHome without using #home
1 participant