Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8ef6f21
refactor of inlining to its own class
RenaudFondeur Apr 18, 2025
06d0003
refactor duplicated code
RenaudFondeur May 5, 2025
5ba0058
refactor code
RenaudFondeur May 6, 2025
43389be
refactor to supress unused arguments
RenaudFondeur May 7, 2025
ad52874
fix the visitor
RenaudFondeur May 15, 2025
26be84b
fix broken test + clean infos of visitor when no longer needed
RenaudFondeur May 15, 2025
c6d9145
add test for returning node as expression handle with an old potentia…
RenaudFondeur May 19, 2025
78d204e
remove halt in test
RenaudFondeur May 19, 2025
df164a1
add a strategy pattern for using inlining
RenaudFondeur May 20, 2025
d3c5475
revert change to old method
RenaudFondeur May 21, 2025
cf4ba82
remove conditional check in copyWithoutReturn
RenaudFondeur May 21, 2025
834b303
small change to the visitor
RenaudFondeur Jun 10, 2025
60f11de
fix bug + cleaning
RenaudFondeur Jun 10, 2025
c1cf166
cleaning + fix a bug with multiple return in a returning inlined expr…
RenaudFondeur Jun 10, 2025
7b7ddc4
better tests
RenaudFondeur Jun 13, 2025
105a0c7
start of revert to stable
RenaudFondeur Jun 13, 2025
6e7f0e0
no use of the visitor in new strategy
RenaudFondeur Jun 13, 2025
471fcad
clean the code
RenaudFondeur Jun 13, 2025
3f6cf1a
add tests for bugs
Jun 18, 2025
b15d23a
change little things to clean the pr
RenaudFondeur Jun 19, 2025
0c03177
restore previous addAllLast handling comments in its own methods ans …
RenaudFondeur Jun 19, 2025
ae41f05
revert (but without the unecessary returnNode) to incorrect but stabl…
RenaudFondeur Jun 19, 2025
5bc8037
Apply suggestions from code review
guillep Jul 11, 2025
bdda5f9
suppress failing tests
RenaudFondeur Jul 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions smalltalksrc/Slang-Tests/SLDeadCodeEliminationTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ SLDeadCodeEliminationTest >> testConditionalWithOnlyCommentNoSendInReceiver [
tMethod := ccg methodNamed:
#conditionalWithOnlyCommentNoSendInReceiver.

ccg prepareMethods.
ccg doBasicInlining: true.

sLDeadCodeElimination currentMethod: tMethod.
Expand All @@ -55,11 +56,11 @@ SLDeadCodeEliminationTest >> testConditionalWithOnlyCommentSendInReceiver [
"currently the only way to get comments in a methods is through inlining, having only comments is equivalent to being empty so it shouldn't change the behavior of the dead code elimination process"

| translation tMethod |
tMethod := ccg methodNamed:
#conditionalWithOnlyCommentSendInReceiver.
tMethod := ccg methodNamed: #conditionalWithOnlyCommentSendInReceiver.

ccg prepareMethods.
ccg doBasicInlining: true.

sLDeadCodeElimination currentMethod: tMethod.
sLDeadCodeElimination removeDeadCodeInCurrentMethod.

Expand Down Expand Up @@ -1795,7 +1796,8 @@ SLDeadCodeEliminationTest >> testMethodWithNeverUsedLocalsFromBlockasArguments [
| translation tMethod |
tMethod := ccg methodNamed:
#methodWithNeverUsedLocalsFromBlockasArguments.
tMethod prepareMethodIn: ccg.

ccg prepareMethods.
ccg doBasicInlining: true.

sLDeadCodeElimination currentMethod: tMethod.
Expand Down Expand Up @@ -1920,7 +1922,9 @@ SLDeadCodeEliminationTest >> testMethodWithOnlyComment [
| translation tMethod |
tMethod := ccg methodNamed: #methodWithOnlyComment.

ccg prepareMethods.
ccg doBasicInlining: true.

sLDeadCodeElimination currentMethod: tMethod.
sLDeadCodeElimination removeDeadCodeInCurrentMethod.

Expand Down Expand Up @@ -5192,7 +5196,8 @@ SLDeadCodeEliminationTest >> testSwitchWithOnlyCommentNoSendInReceiver [

| translation tMethod |
tMethod := ccg methodNamed: #switchWithOnlyCommentNoSendInReceiver:.
tMethod prepareMethodIn: ccg.

ccg prepareMethods.
ccg doBasicInlining: true.

sLDeadCodeElimination currentMethod: tMethod.
Expand All @@ -5207,7 +5212,7 @@ SLDeadCodeEliminationTest >> testSwitchWithOnlyCommentNoSendInReceiver [
equals:
'/* SLDeadCodeEliminationTestClass>>#switchWithOnlyCommentNoSendInReceiver: */
static void
switchWithOnlyCommentNoSendInReceiver(SLDeadCodeEliminationTestClass * self_in_switchWithOnlyCommentNoSendInReceiver, sqInt anInt)
switchWithOnlyCommentNoSendInReceiver(SLDeadCodeEliminationTestClass * self_in_switchWithOnlyCommentNoSendInReceiver, sqInt _anInt)
{
{
return;
Expand All @@ -5221,7 +5226,8 @@ SLDeadCodeEliminationTest >> testSwitchWithOnlyCommentSendInReceiver [

| translation tMethod |
tMethod := ccg methodNamed: #switchWithOnlyCommentSendInReceiver.
tMethod prepareMethodIn: ccg.

ccg prepareMethods.
ccg doBasicInlining: true.

sLDeadCodeElimination currentMethod: tMethod.
Expand Down
296 changes: 296 additions & 0 deletions smalltalksrc/Slang-Tests/SLMockInliningTestClass.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,296 @@
Class {
#name : 'SLMockInliningTestClass',
#superclass : 'SlangClass',
#category : 'Slang-Tests',
#package : 'Slang-Tests'
}

{ #category : 'helpers' }
SLMockInliningTestClass >> emptyMethod: arg [


]

{ #category : 'inlining-arguments' }
SLMockInliningTestClass >> emptyMethodAWithSimpleArgumentsInlined [

self emptyMethod: self methodBAlwaysInlined
]

{ #category : 'inlining-simple' }
SLMockInliningTestClass >> methodA [

1 + 1.
self methodB
]

{ #category : 'inlining-assignment-helpers' }
SLMockInliningTestClass >> methodAAssignOnReturn [

1 + 1.
^ self methodBAssignOnReturn
]

{ #category : 'inlining-assignment' }
SLMockInliningTestClass >> methodAInlineIfFalseReturningIfTrueInAssignement [

| a |
a := self methodBIfFalseReturningIfTrue
]

{ #category : 'inlining-returning-conditional' }
SLMockInliningTestClass >> methodAInlineIfFalseReturningIfTrueInReturn [

^ self methodBIfFalseReturningIfTrue
]

{ #category : 'inlining-assignment' }
SLMockInliningTestClass >> methodAInlineMultipleIfFalseReturningIfTrueInAssignment [

| a |
a := self methodB
ifFalse: [ self methodBIfFalseReturningIfTrue ]
ifTrue: [
5.
self methodBIfFalseReturningIfTrue ]
]

{ #category : 'inlining-assignment' }
SLMockInliningTestClass >> methodAInlineReturningIfTrueIfFalseInAssignment [

| a |
a := self methodBReturningIfTrueIfFalse
]

{ #category : 'inlining-returning-conditional' }
SLMockInliningTestClass >> methodAInlineReturningIfTrueIfFalseInReturn [

^ self methodBReturningIfTrueIfFalse
]

{ #category : 'inlining-assignment' }
SLMockInliningTestClass >> methodAInlineReturningIfTrueInAssignment [

| a |
a := self methodBReturningIfTrue
]

{ #category : 'inlining-returning-conditional' }
SLMockInliningTestClass >> methodAInlineReturningIfTrueInReturn [

^ self methodBReturningIfTrue
]

{ #category : 'inlining-assignment' }
SLMockInliningTestClass >> methodAInlineReturningInlinedIfTrueInAssignment [

| a |
a := self methodBReturningInlinedIfTrue
]

{ #category : 'inlining-jump' }
SLMockInliningTestClass >> methodAMultipleReturn [

self methodBMultipleReturn.
^ 1 + 1
]

{ #category : 'inlining-jump' }
SLMockInliningTestClass >> methodAMultipleReturnAsAssignmentExpression [

| x |
x := self methodBMultipleReturn
]

{ #category : 'inlining-jump' }
SLMockInliningTestClass >> methodAMultipleReturnAsReturnExpression [

^ self methodBMultipleReturn
]

{ #category : 'inlining-jump' }
SLMockInliningTestClass >> methodAMultipleReturnExpression [

self methodBMultipleReturn.
^ 1 + 1
]

{ #category : 'inlining-assignment' }
SLMockInliningTestClass >> methodAReturnAssignment [

| a |
^ a := self methodB
]

{ #category : 'inlining-assignment-helpers' }
SLMockInliningTestClass >> methodAReturnOnAssignment [

| var |
1 + 1.
^ self methodBReturnOnAssignment: [ :x |
var := x.
]
]

{ #category : 'inlining-jump' }
SLMockInliningTestClass >> methodASimpleReturn [

self methodBSimpleReturn.
^ 1 + 1
]

{ #category : 'inlining-arguments' }
SLMockInliningTestClass >> methodAWithArgumentsInlined [

^ self methodB: self methodCAlwaysInlined
]

{ #category : 'inlining-arguments' }
SLMockInliningTestClass >> methodAWithReturningSendArgumentsInlined [

^ self methodB: self methodCAlwaysInlined
]

{ #category : 'inlining-arguments' }
SLMockInliningTestClass >> methodAWithSimpleArgumentsInlined [

self methodB: self methodBAlwaysInlined
]

{ #category : 'inlining-simple-helpers' }
SLMockInliningTestClass >> methodB [

2 + 2
]

{ #category : 'inlining-arguments-helpers' }
SLMockInliningTestClass >> methodB: anArg [

<inline: #never>
^ anArg
]

{ #category : 'inlining-arguments-helpers' }
SLMockInliningTestClass >> methodBAlwaysInlined [

<inline: #always>
2 + 2
]

{ #category : 'inlining-assignment-helpers' }
SLMockInliningTestClass >> methodBAssignOnReturn [

^ 2 + 2
]

{ #category : 'inlining-returning-conditional-helpers' }
SLMockInliningTestClass >> methodBIfFalseReturningIfTrue [

self methodB
ifFalse: [ true ]
ifTrue: [ ^ false ].
^ true
]

{ #category : 'inlining-jump-helpers' }
SLMockInliningTestClass >> methodBMultipleReturn [

self methodB ifTrue: [ ^ 0 ].
self methodCMultipleReturn.
^ 2 + 2
]

{ #category : 'inlining-assignment-helpers' }
SLMockInliningTestClass >> methodBReturnOnAssignment [

| var |
var := 2 + 2
]

{ #category : 'inlining-assignment-helpers' }
SLMockInliningTestClass >> methodBReturnOnAssignment: aBlock [

| var |
var := 2 + 2.
^ aBlock value: var
]

{ #category : 'inlining-returning-conditional-helpers' }
SLMockInliningTestClass >> methodBReturningIfTrue [

^ self methodB ifTrue: [ true ]
]

{ #category : 'inlining-returning-conditional-helpers' }
SLMockInliningTestClass >> methodBReturningIfTrueIfFalse [

^ self methodB ifTrue: [ 1 ] ifFalse: [ 2 ]
]

{ #category : 'inlining-returning-conditional-helpers' }
SLMockInliningTestClass >> methodBReturningInlinedIfTrue [

^ self methodB ifTrue: [ self methodB ]
]

{ #category : 'inlining-jump-helpers' }
SLMockInliningTestClass >> methodBSimpleReturn [

self methodCSimpleReturn.
^ 2 + 2
]

{ #category : 'inlining-simple-helpers' }
SLMockInliningTestClass >> methodC [

3 + 3.
self methodA
]

{ #category : 'inlining-arguments-helpers' }
SLMockInliningTestClass >> methodCAlwaysInlined [

<inline: #always>
3 + 3.
self methodA
]

{ #category : 'inlining-assignment' }
SLMockInliningTestClass >> methodCAssignOnReturn [

| a |
3 + 3.
a := self methodAAssignOnReturn
]

{ #category : 'inlining-jump-helpers' }
SLMockInliningTestClass >> methodCMultipleReturn [

self methodC ifTrue: [ ^ 1 ].
^ 3 + 3
]

{ #category : 'inlining-assignment' }
SLMockInliningTestClass >> methodCReturnOnAssignment [

3 + 3.
^ self methodAReturnOnAssignment
]

{ #category : 'inlining-jump-helpers' }
SLMockInliningTestClass >> methodCSimpleReturn [

^ 3 + 3
]

{ #category : 'collect-statements-for-inlining' }
SLMockInliningTestClass >> methodWithAvoidedSelectors [

self cCode: [ ] inSmalltalk: [ ].
self cCall: 'method'.
self cCall: 'method' withArguments: { 1. 2. 3 }.
self cppIf: ['cppCond'. true] ifTrue: [ 'in cppIfTrue'. false ] ifFalse: [ 'in cppIfFalse'. true ].
[ 'and receiver'. true ] and: [ 'and argument'. false ].
[ 'or receiver' . false ] or: [ 'or argument'. true ].
[ 'ifTrue receiver'. false ] ifTrue: ['ifTrue argument' . true ]
]
Loading