pharo-project / pharo

Pharo is a dynamic reflective pure object-oriented language supporting live programming inspired by Smalltalk.
http://pharo.org
Other
1.21k stars 356 forks source link

Possible issue when getting the #sourceNode for ConstantBlockClosure #16494

Open chisandrei opened 7 months ago

chisandrei commented 7 months ago

Is it expected that this fails in Pharo 11/12 and works in Pharo 10?

blocks := OrderedCollection  new.
(FBDExamples>>#exampleSimpleBlock) innerCompiledBlocksDo: [ :aBlock | 
    blocks add: aBlock  ].

self assert: blocks first sourceNode sourceCode = '[1]'.

In Pharo 10 the returned source code is [1], while in Pharo 11/12 it is ^[1]. The node of the block is RBBlockNode in Pharo 10 and RBReturnNode in Pharo 11/12

To work in Pharo 11/12 we can send value to the sourceNode.

self assert: blocks first sourceNode value sourceCode = '[1]'.
MarcusDenker commented 7 months ago

I tracked this down to the bc-> AST mapping being wrong when the block is a constant block.

Next step is to fix that

MarcusDenker commented 6 months ago

The problem is that OCBytecodeToASTCache>>#generateForNode: does not add any entry for compiledBlocks

I think we have to analyse all pushes, find when a constant block ist pushend and add the mapping pc -> AST from that

chisandrei commented 5 months ago

Just as a side-note, CleanBlockClosure>>#doPrintOn: gets the source node of a compiled block using self sourceNode value instead of self sourceNode. For constant blockssourceNodereturns aRBReturnNodeand sendingvalue` to that returns the correct node. This results in the source code actually being ok when printing it

fedemennite commented 2 months ago

We currently have a workaround implemented by Andrei. @chisandrei it can be interesting to share it here.

chisandrei commented 2 months ago

The workaround is just calling self compiledBlock ast value instead of self compiledBlock ast when handling a RBReturnNode.

Ducasse commented 2 months ago

Thanks!