-
Notifications
You must be signed in to change notification settings - Fork 194
Implement Module#const_source_location #2212
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Module#const_source_location
eregon
reviewed
Jan 7, 2021
There was a problem hiding this 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 withclass/module Foo
won't have aconst_source_location
. Might be good to also have a spec more explicit about testing that case, as it has nothing to do withto_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.
chrisseaton
reviewed
Jan 8, 2021
f22d70a
to
1fb978d
Compare
0779188
to
17c3a06
Compare
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.
17c3a06
to
2dc1294
Compare
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 |
eregon
approved these changes
Jan 23, 2021
graalvmbot
pushed a commit
that referenced
this pull request
Jan 25, 2021
PullRequest: truffleruby/2365
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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 inConstantSpecs::ClassA
had asourceSection
and I don’t know why.autoload returns the autoload location while not resolved
”) because the constant’ssourceSection
points to the file to be autoloaded, not theautoload
call site — the latter doesn’t appear to be stored anywhere.Shopify#1