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

[Truffle] Multiple assignment error with Constants #2795

Closed
bjfish opened this issue Apr 2, 2015 · 3 comments
Closed

[Truffle] Multiple assignment error with Constants #2795

bjfish opened this issue Apr 2, 2015 · 3 comments
Assignees
Milestone

Comments

@bjfish
Copy link
Contributor

bjfish commented Apr 2, 2015

Error

$ bin/jruby -X+T -e 'STATUS_YET, STATUS_STARTED, STATUS_TERMINATED = 0, 1, 2; puts STATUS_YET'
-e:1:in `const_missing': uninitialized constant Object::STATUS_YET (NameError)
    from -e:1:in `<main>'

Expected

$ ruby  -e 'STATUS_YET, STATUS_STARTED, STATUS_TERMINATED = 0, 1, 2; puts STATUS_YET'
0
@bjfish
Copy link
Contributor Author

bjfish commented Apr 3, 2015

TODO: add getoptlong once this is fixed

@chrisseaton chrisseaton added this to the truffle-dev milestone Apr 3, 2015
@chrisseaton chrisseaton self-assigned this Apr 3, 2015
@chrisseaton
Copy link
Contributor

I'll take a look at this soon - getoptlong and optparse would be very useful, as lots of small utilities we could be running use them.

@chrisseaton
Copy link
Contributor

Fixed in dcb1551.

Here's how I debugged it.

I used the -Xtruffle.translator.print_asts=main option to print the Truffle AST for each top level method.

$ jt build truffle run -Xtruffle.translator.print_asts=main ../test.rb
(lots of stuff...)
../test.rb main
  SequenceNode
    body[0] = SetTopLevelBindingNode
    body[1] = TopLevelRaiseHandler
      body = SetMethodDeclarationContext
        child = CatchRetryAsErrorNode
          body = CatchReturnAsErrorNode
            body = CatchNextNode
              body = SequenceNode
                body[0] = TraceNode
                body[1] = AssignmentWrapperNode
                  child = ElidableResultNode
                    required = SequenceNode
                      body[0] = WriteLocalVariableUninitializedNode
                        rhs = IntegerFixnumLiteralNode
                      body[1] = WriteLocalVariableUninitializedNode
                        rhs = IntegerFixnumLiteralNode
                      body[2] = WriteLocalVariableUninitializedNode
                        rhs = IntegerFixnumLiteralNode
                      body[3] = WriteLocalVariableUninitializedNode
                        rhs = ReadLocalVariableUninitializedNode
                      body[4] = WriteLocalVariableUninitializedNode
                        rhs = ReadLocalVariableUninitializedNode
                      body[5] = WriteLocalVariableUninitializedNode
                        rhs = ReadLocalVariableUninitializedNode
                    elidableResult = UninitialisedArrayLiteralNode
                      values[0] = ReadLocalVariableUninitializedNode
                      values[1] = ReadLocalVariableUninitializedNode
                      values[2] = ReadLocalVariableUninitializedNode
                body[2] = TraceNode
                body[3] = RubyCallNode
                  receiver = SelfNode
                  dispatchHead = CallDispatchHeadNode
                    first = UnresolvedDispatchNode
                  respondToMissing = CallDispatchHeadNode
                    first = UnresolvedDispatchNode
                  respondToMissingCast = BooleanCastUninitializedNode
                  arguments[0] = ReadConstantNode
                    receiver = LexicalScopeNode
                    dispatch = DispatchHeadNode
                      first = UnresolvedDispatchNode

I can see where it passes the IntegerFixnumLiteralNode to WriteLocalVariableUninitializedNode nodes - this is doing temp0 = 0. Then I can see where it should be doing CONST = temp0, but it's actually using a WriteLocalVariableUninitializedNode instead of a WriteConstantNode. I fixed translateDummyAssignment, which I know is part of the multiple assignment translation, to handle constants and now the AST is this:

../test.rb main
  SequenceNode
    body[0] = SetTopLevelBindingNode
    body[1] = TopLevelRaiseHandler
      body = SetMethodDeclarationContext
        child = CatchRetryAsErrorNode
          body = CatchReturnAsErrorNode
            body = CatchNextNode
              body = SequenceNode
                body[0] = TraceNode
                body[1] = AssignmentWrapperNode
                  child = ElidableResultNode
                    required = SequenceNode
                      body[0] = WriteLocalVariableUninitializedNode
                        rhs = IntegerFixnumLiteralNode
                      body[1] = WriteLocalVariableUninitializedNode
                        rhs = IntegerFixnumLiteralNode
                      body[2] = WriteLocalVariableUninitializedNode
                        rhs = IntegerFixnumLiteralNode
                      body[3] = WriteConstantNode
                        module = LexicalScopeNode
                        rhs = ReadLocalVariableUninitializedNode
                      body[4] = WriteConstantNode
                        module = LexicalScopeNode
                        rhs = ReadLocalVariableUninitializedNode
                      body[5] = WriteConstantNode
                        module = LexicalScopeNode
                        rhs = ReadLocalVariableUninitializedNode
                    elidableResult = UninitialisedArrayLiteralNode
                      values[0] = ReadLocalVariableUninitializedNode
                      values[1] = ReadLocalVariableUninitializedNode
                      values[2] = ReadLocalVariableUninitializedNode
                body[2] = TraceNode
                body[3] = RubyCallNode
                  receiver = SelfNode
                  dispatchHead = CallDispatchHeadNode
                    first = UnresolvedDispatchNode
                  respondToMissing = CallDispatchHeadNode
                    first = UnresolvedDispatchNode
                  respondToMissingCast = BooleanCastUninitializedNode
                  arguments[0] = ReadConstantNode
                    receiver = LexicalScopeNode
                    dispatch = DispatchHeadNode
                      first = UnresolvedDispatchNode

@enebo enebo added this to the Non-Release milestone Dec 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants