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

Adding an API in OCBytecodeToASTCache, RBMethodNode and RBBlockNode to map AST nodes to a pc range. #11651

Conversation

adri09070
Copy link
Collaborator

OCBytecodeToASTCache only provides a way to easily map bytecode offsets to AST nodes but it doesn't allow to do it the other way around.

I implemented an API in this class to do so:

  • OCBytecodeToASTCache>>#pcsForNode:that returns a collection of pcs of bytecodes that are mapped to the argument node.
  • OCBytecodeToASTCache>>#firstBcForNode: that returns the first bytecode offset in the pc range mapped to the argument node, and nil if the argument node isn't mapped to any bytecode offset.
  • OCBytecodeToASTCache>>#lastBcForNode: that returns the last bytecode offset in the pc range mapped to the argument node, and nil if the argument node isn't mapped to any bytecode offset.

This API is also in RBBlockNodeand RBMethodNodeto have an easier AST -> pc mapping, just like it already is for the pc -> AST mapping

…o easily map AST nodes to bytecode offsets + tests
@dionisiydk
Copy link
Contributor

dionisiydk commented Sep 5, 2022

Side comment.
Why we really need OCBytecodeToASTCache? The use case to find a source node for given pc does not look expensive. It seems to me that it will be simpler to have just a lookup API on the level of IR without the need of the full bytecode map:

RBMethodNode>>sourceNodeForPC: anInteger
	^ self ir nodeForPC: anInteger

@MarcusDenker
Copy link
Member

The problem with just using the IR is that then we always have to keep the IR. With the mapping, we do not need to keep the IR around.

@dionisiydk
Copy link
Contributor

The problem with just using the IR is that then we always have to keep the IR. With the mapping, we do not need to keep the IR around.

But it is what we have now:

method := MethodMapExamples>>#helperMethod13.
ast := method ast.
ast sourceNodeForPC: 10.
ast propertyAt: #ir "==> an IRMethod"

And one more observation:

((ast propertyAt: #ir) instVarNamed: #compiledMethod) == method "==> false"

So when we built IR with a bytecode map we perform second compilation and keep new method in a variable.

@MarcusDenker
Copy link
Member

It is like that now, yes, but is that good?

the second compilation is not good, this should be the same method.

@dionisiydk
Copy link
Contributor

Sounds like the place to improve :).

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.

3 participants