[Vm-dev] Fix for label duplications in Slang's case expansion

Eliot Miranda eliot.miranda at gmail.com
Fri Jan 24 18:14:58 UTC 2020


Thanks Guille!

_,,,^..^,,,_

> On Jan 24, 2020, at 7:57 AM, Guillermo Polito <guillermopolito at gmail.com> wrote:
> 
> 
> 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