Skip to content

Conversation

tomstuart
Copy link
Contributor

Module#const_source_location is one of the methods we need to implement for Ruby 2.7 support. This PR gets all but two of its associated Ruby specs passing.

On the remaining failures:

  • I don’t understand why the “calls #to_str to convert the given name to a String” test is still failing. The #to_str assertion is working fine, but when I debugged this I could see that none of the constants in ConstantSpecs::ClassA had a sourceSection and I don’t know why.
  • I think we should try to match MRI’s current behaviour for constants awaiting autoload. I don’t know how to get this working for the corresponding test (“autoload returns the autoload location while not resolved”) because the constant’s sourceSection points to the file to be autoloaded, not the autoload call site — the latter doesn’t appear to be stored anywhere.

Shopify#1

@tomstuart tomstuart changed the title Implement Module#const_source_location Implement Module#const_source_location Jan 7, 2021
@eregon eregon self-requested a review January 7, 2021 13:51
Copy link
Member

@eregon eregon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • That seems because the SourceSection is not passed correctly, in rubyClass.fields.getAdoptedByLexicalParent(context, lexicalParent, name, null);. That would be good to fix (not needed in this PR), probably by passing the Node from DefineClassNode and other callers, otherwise all module/class defined with class/module Foo won't have a const_source_location. Might be good to also have a spec more explicit about testing that case, as it has nothing to do with to_str.
  • The constant for the autoload should have the proper information, but we should pass the caller node (CallStackManager#getCallerNodeIgnoringSend) and not just this in AutoloadNode.

@tomstuart tomstuart force-pushed the const-source-location branch from f22d70a to 1fb978d Compare January 13, 2021 13:50
@eregon eregon self-requested a review January 14, 2021 17:44
@tomstuart tomstuart force-pushed the const-source-location branch 2 times, most recently from 0779188 to 17c3a06 Compare January 22, 2021 16:13
tomstuart and others added 9 commits January 22, 2021 17:44
We don’t know how to actually implement this yet, so we’re just
returning `nil`.

For the sake of simplicity, we are casting the `name` argument to a Java
`String`. This means we don’t currently have access to the original
`RubySymbol` object if the method was called with a `name` that’s a
symbol. In future we may need to undo this cast if we discover that the
original `RubySymbol` is useful, e.g. for its object identity.

Co-authored-by: Maple Ong <maple.ong@shopify.com>
These tests were accidentally passing before, because they are all
expecting a `NameError`, which the previous `NoMethodError` happens to
be a subclass of. Now that we’ve introduced a dummy implementation of
the method, these tests have begun to correctly fail, since we haven’t
actually written any code to intentionally raise a `NameError`.

Co-authored-by: Maple Ong <maple.ong@shopify.com>
There are two different kinds of test which are now passing as a result
of our dummy `Module#const_source_location` implementation:

* the “raises a TypeError” test is now passing because we try to cast
  the `name` argument to a string, which will fail with a `TypeError` if
  that can’t be done; and

* all of the other untagged tests, which are expecting the result of
  calling `Module#const_source_location` in various circumstances to
  return `nil`, which is currently what it always does.

We’re untagging these tests now because we expect them to keep passing
as we continue fleshing out our implementation of
`Module#const_source_location`.

Co-authored-by: Maple Ong <maple.ong@shopify.com>
This doesn’t work for inherited or namespaced constants, but it makes a
lot of the tests pass.
…hInherit

As well as supporting inheritance, this checks that the string is a
valid (non-scoped) constant name, which makes several more tests pass.
Since e487b68 it’s important that we
pass `true` as the optional `checkName` argument to ensure we get the
latter behaviour.
We’ll need to reuse this part of `constSourceLocation()` when we split
it into two separate specialisations for strings and symbols.

Co-authored-by: Chris Seaton <chris.seaton@shopify.com>
…nd symbols

We need distinct implementations because `#const_source_location`
supports scoped lookup for string arguments but explicitly doesn’t
support it for symbols.

The string specialisation takes a guarded `Object` rather than a
`RubyString` so that `ImmutableRubyString` is also supported.
@tomstuart tomstuart force-pushed the const-source-location branch from 17c3a06 to 2dc1294 Compare January 22, 2021 18:17
@tomstuart
Copy link
Contributor Author

This branch needed rebasing so that it still worked with compatibility-breaking changes in e487b68. I believe it’s otherwise ready for review/merge unless it’s necessary to address the two remaining failing #const_source_location specs as part of this change.

@eregon eregon added the in-ci The PR is being tested in CI. Do not push new commits. label Jan 23, 2021
@eregon eregon added this to the 21.1.0 milestone Jan 23, 2021
graalvmbot pushed a commit that referenced this pull request Jan 25, 2021
@graalvmbot graalvmbot merged commit 2dc1294 into oracle:master Jan 25, 2021
@chrisseaton chrisseaton added the shopify Pull requests from Shopify label Feb 2, 2021
@chrisseaton chrisseaton deleted the const-source-location branch August 30, 2021 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in-ci The PR is being tested in CI. Do not push new commits. oca-signed shopify Pull requests from Shopify
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants