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

Reading of uninitialized local variables is broken #6

Open
smarr opened this issue Sep 26, 2016 · 4 comments
Open

Reading of uninitialized local variables is broken #6

smarr opened this issue Sep 26, 2016 · 4 comments
Labels

Comments

@smarr
Copy link
Member

smarr commented Sep 26, 2016

Reading of uninitialized variables in methods is likely broken. At least it is in SOMns.

The following test fails with an assertion, because the read evaluates to null:

class Test usingPlatform: platform = Value ()(
  protected foo = (
    | a |
    a println.
    a := 1.
    a println.
  )

  public main: args = (
    foo.
    foo.
    ^ 0
  )
)

A fix could be:

diff --git a/src/som/compiler/MethodBuilder.java b/src/som/compiler/MethodBuilder.java
index 1598a2b..20e8757 100644
--- a/src/som/compiler/MethodBuilder.java
+++ b/src/som/compiler/MethodBuilder.java
@@ -101,7 +102,8 @@ public final class MethodBuilder {
     MethodScope outer = (outerBuilder != null)
         ? outerBuilder.getCurrentMethodScope()
         : null;
-    this.currentScope   = new MethodScope(new FrameDescriptor(), outer, clsScope);
+    assert Nil.nilObject != null;
+    this.currentScope   = new MethodScope(new FrameDescriptor(Nil.nilObject), outer, clsScope);

     accessesVariablesOfOuterScope = false;
     throwsNonLocalReturn          = false;

/cc @charig

@smarr smarr added the bug label Sep 26, 2016
@charig
Copy link

charig commented Sep 26, 2016

Stefan, good catch, same happens in TruffleMate and I guess in TruffleSOM. But, have you tried the proposed patch? Anyway, my impression is that each LocalVarNode* should have its own Slot (clone the slot at creation time) while they are sharing it right now.

@smarr
Copy link
Member Author

smarr commented Sep 26, 2016

The patch is for SOMns, it fixed the example above. I haven't tested it beyond that.

I am not sure exactly what you are referring to with the LocalVarNode* and having their own slot.
The slot represents the memory for a local variable. The LocalVarNode*s are there to access them. Cloning the slots does not make sense to me. What would that achieve? That would be similar to duplicating a field in an object for each place it is accessed, no?

The frame is actually tracking whether the slot is set. It has an array of tags. That could potentially also be used to mark a variable as unwritten again (for issue #5).

@charig
Copy link

charig commented Sep 26, 2016

Yes. What I said was complete nonsense. It would even be incorrect. What I was trying to think is something like this: protected foo = ( | a | a := nil. a println. a := 1. a println. )
The second LocalVarNode specializes to object because the FrameSlotKind is already set to object by nil. While debugging your example, I was thinking in a workaround to try to optimize this case but clearly duplicating FrameSlots is not the solution, sorry for the noise.

@charig
Copy link

charig commented Sep 26, 2016

If you want to update TruffleSOM it is quite straightforward but just in case I attach the commit and its regression test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants