Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opal: DefiningContext should be looked up by scope #4696

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 5 additions & 6 deletions src/OpalCompiler-Core/OCAbstractMethodScope.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,12 @@ OCAbstractMethodScope >> localTemps [
]

{ #category : #lookup }
OCAbstractMethodScope >> lookupDefiningContextFor: name startingFrom: aContext [
"We lookup a variable in a context. If it not in this context, we look in the outer context using the corresponding outer scope. If found, we return the context"
OCAbstractMethodScope >> lookupDefiningContextForVariable: var startingFrom: aContext [
"Is this the definition context for var? If it not, we look in the outer context using the corresponding outer scope. If found, we return the context"

self
variableNamed: name
ifAbsent: [ ^self outerScope lookupDefiningContextFor: name startingFrom: (self nextOuterScopeContextOf: aContext)].
^aContext
^self = var scope
ifFalse: [ self outerScope lookupDefiningContextForVariable: var startingFrom: (self nextOuterScopeContextOf: aContext) ]
ifTrue: [ aContext ]
]

{ #category : #lookup }
Expand Down
5 changes: 2 additions & 3 deletions src/OpalCompiler-Core/OCCopyingTempVariable.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,11 @@ OCCopyingTempVariable >> tempVectorForTempStoringIt [
OCCopyingTempVariable >> writeFromContext: aContext scope: contextScope value: aValue [

| definitionContext |
definitionContext := contextScope lookupDefiningContextFor: name startingFrom: aContext.

definitionContext := contextScope lookupDefiningContextForVariable: self startingFrom: aContext.
originalVar writeFromContext: aContext scope: contextScope value: aValue.

self flag: #FIXME.
"we need to change all the copies and the original, too"
"we need to change all the copies, too"

^definitionContext
tempAt: self indexFromIR
Expand Down
4 changes: 2 additions & 2 deletions src/OpalCompiler-Core/OCTempVariable.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ OCTempVariable >> markWrite [
{ #category : #debugging }
OCTempVariable >> readFromContext: aContext scope: contextScope [
| definitionContext |
definitionContext := contextScope lookupDefiningContextFor: name startingFrom: aContext.
definitionContext := contextScope lookupDefiningContextForVariable: self startingFrom: aContext.
^ self readFromLocalContext: definitionContext
]

Expand All @@ -149,7 +149,7 @@ OCTempVariable >> readFromLocalContext: aContext [
OCTempVariable >> writeFromContext: aContext scope: contextScope value: aValue [

| definitionContext |
definitionContext := contextScope lookupDefiningContextFor: name startingFrom: aContext.
definitionContext := contextScope lookupDefiningContextForVariable: self startingFrom: aContext.

^definitionContext
tempAt: self indexFromIR
Expand Down
6 changes: 3 additions & 3 deletions src/OpalCompiler-Tests/MethodMapTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ MethodMapTest >> testExampleTempNamedPutCopying [

{ #category : #'testing - temp access' }
MethodMapTest >> testExampleTempNamedPutCopying2 [
"modifying a copied temp variable will *not* modify the value in the outer context.
(See other test case OCClosureCompilerTest>>#testDebuggerTempAccess and notes on fogbugz issue 17702"
self assert: (self compileAndRunExample: #exampleTempNamedPutCopying2) equals: 1
"modifying a copied temp variable will modify the value in the outer context"

self assert: (self compileAndRunExample: #exampleTempNamedPutCopying2) equals: 2
]

{ #category : #'testing - temp access' }
Expand Down
6 changes: 3 additions & 3 deletions src/OpalCompiler-Tests/OCClosureCompilerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,9 @@ OCClosureCompilerTest >> doTestDebuggerTempAccessWith: one with: two [
self evaluate: 'local1 := 25' in: thisContext to: self.
self assert: local1 = 25.
{ r1. r2. r3. r4 } "placate the compiler"].
self assert: local1 = -3.0.
"this is not 25 as the var is a local, non escaping variable that was copied into the block,
If the compiler would have known about the write, it would have made the var escaping".
self assert: local1 = 25.
"this is 25 even though the var is a local, non escaping variable that was copied into the block.
But the DoIt compiles temp acces using #namedTempAt:put:, which updates the copies and the original".
self assert: remote1 = (6/7)
]

Expand Down