Alamvic / druid

Meta-compiler to generate an optimised JIT compiler frontend based on an Interpreter definition
8 stars 6 forks source link

Do not lost original AST after optimisations #119

Open PalumboN opened 6 months ago

PalumboN commented 6 months ago

Druid can, for instruction, track the expression in the interpreter from it was created:

image

But if some optimization replaces this instruction with another equivalent, the source is lost. For example, here the subtraction 1 was changed by an addition -1:

image

This is happening because some instructions are being instantiated without origin and originAST:

image

This happens mostly inside the optimizations. They replace instructions with origin with new ones without.

We should keep the origin of an instruction when it is replace:by: a new one (without origin).


To focus on this refactor, I searched the senders of #operands:result: (used to instantiate instructions) and filtered some methods. Maybe help:

DRCogitCanonicaliser>>#visitSubstract:
DRCogitCanonicaliser>>#visitPop: 
DRCogitCanonicaliser>>#visitAddition:
DRCogitCodeGenerator>>#visitLoad: 
DRCogitSendMarshall class>>#send:
DRCogitSimpleStackGenerator>>#visitClosureCreation:
DRCommutativeOperation>>#reversed 
DRGetConditionCode>>#reversed
DRIRGenerator>>#instantiate:operands: 
DRInstruction class>>#result:
DRLinearScanRegisterAllocator>>#assignRegisterToResultInInstruction:
DRLinearScanRegisterAllocator>>#assignRegistersToOperandsInInstruction:
DRLocalVariableInstructionScheluder>>#storeReusedResultOf:
DRPhiSimplication>>#applyTo: 
DRPrimitiveIRGenerator>>#spillStack
DRSCCP>>#tryReplaceInstructionByFoldedValue:
DRSCCPConstantFoldingTest>>#testConstantFoldingOf:betweenOp:andOp:
DRSCCPConstantFoldingTest>>#nonReducibleOperation
DRSCCPWithStaging>>#latticeForLoad: 
DRStager>>#stageInstruction:
DRStrongCopyForInlining>>#asCopy