[Vm-dev] Fix for label duplications in Slang's case expansion
Guillermo Polito
guillermopolito at gmail.com
Fri Jan 24 15:58:55 UTC 2020
Of course, for the test to run, it needs these other two methods :)
methodWithCases
self dispatchOn: currentBytecode in: #( expanded expanded expanded )
expanded
<expandCases>
^ (currentBytecode bitAnd: 15) << 2
> El 24 ene 2020, a las 16:57, Guillermo Polito <guillermopolito at gmail.com> escribió:
>
> Hi all,
>
> with Federico, a student from Argentina, we have found a problem in the label generation inside expanded cases in Slang.
> The problem comes from the fact that expanded cases (using the pragma <expandCase>, typically used for bytecodes), duplicate the entire tree with its inlines too, also duplicating labels inside it, which generates compilation errors due to label redefinition.
>
> I’ve written a test for the case:
>
> | translation method codeGenerator |
> method := self class >> #methodWithCases.
> translation := method asTranslationMethodOfClass: TMethod.
> codeGenerator := CCodeGeneratorGlobalStructure new.
> codeGenerator addMethod: ((self class >> #expanded) asTranslationMethodOfClass: TMethod).
> codeGenerator addMethod: translation.
>
> codeGenerator prepareMethods.
> codeGenerator inlineDispatchesInMethodNamed: #methodWithCases localizingVars: #().
> self assert: translation statements first cases first statements last isLabel.
> self assert: translation statements first cases third statements last isLabel.
>
> self
> deny: translation statements first cases first statements last label
> equals: translation statements first cases third statements last label.
>
>
>
> And I’ve made a fix that renames labels on each expanded case, to ensure non shared labels are unique within each case.
> I’ve put it in vmmaker's inbox. I hope there are no problems regarding timestamps, I’ve been careful about that ^^.
>
> Commit + commit message below:
>
> Name: VMMaker.oscog-GuillermoPolito.2676
> Author: GuillermoPolito
> Time: 24 January 2020, 4:27:09.847804 pm
> UUID: 49bcc820-4659-0d00-b258-043c01043dd2
> Ancestors: VMMaker.oscog-eem.2675
>
> Fix in slang case statement expansion labels.
>
> During expansion in case statements, trees are duplicated and expanded.
> However, labels inside those trees are duplicated using the same name, producing compilation problems due to label conflicts/redefinition.
>
> This fix uses #renameLabelsForInliningInto: when expanding case statements to rewrite labels generating unique labels.
>
> Cheers,
> Guille
More information about the Vm-dev
mailing list