-
Notifications
You must be signed in to change notification settings - Fork 565
--stripe-packages: Hide PackageSpecs from top-level namespace #5644
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
Conversation
BBB | ||
# ^^^ error: Unable to resolve constant `BBB` |
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.
Prior to this change, this would have resolved. That's the whole point of this change.
module ::Project | ||
end | ||
|
||
module ::Project::Foo | ||
end | ||
|
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.
I don't have a ton of context on the rbi gen stuf going on here, but this seems like effectively a noop. cc @aadi-stripe @jez
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.
Doesn't this just mean that because these symbols are not available at the top-level by default anymore (due to the re-namespacing), we end up generating the shims for them?
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.
seems fine to me, we can figure it out later if it's a problem
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.
Yep, that's my understanding.
We have a policy of testing changes to Sorbet against Stripe's codebase before Stripe employees can see the build results here: → https://go/builds/bui_LX17eQnRsMp3z6 |
6c27594
to
1b489c6
Compare
I got this passing on Stripe's codebase with some minor changes: |
st //test:test_{Packager,Pos}Tests/testdata/packager/namespace st is aliased to `bazel test --config=dbg --test_output=errors'
this is more accurate because dep does not exist anymore
1b489c6
to
adcc35a
Compare
(Rebased) |
packager/packager.cc
Outdated
@@ -1191,6 +1214,10 @@ struct PackageInfoFinder { | |||
|
|||
info->loc = ctx.locAt(classDef.loc); | |||
info->declLoc_ = ctx.locAt(classDef.declLoc); | |||
|
|||
// `class Foo < PackageSpace` -> `class <PackageSpecRegistry>::Foo < PackageSpec` |
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.
// `class Foo < PackageSpace` -> `class <PackageSpecRegistry>::Foo < PackageSpec` | |
// `class Foo < PackageSpec` -> `class <PackageSpecRegistry>::Foo < PackageSpec` |
packager/packager.cc
Outdated
auto *lastConstLit = &ast::cast_tree_nonnull<ast::UnresolvedConstantLit>(scope); | ||
while (auto constLit = ast::cast_tree<ast::UnresolvedConstantLit>(lastConstLit->scope)) { |
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.
Hm, why not just use pointers?
auto *lastConstLit = &ast::cast_tree_nonnull<ast::UnresolvedConstantLit>(scope); | |
while (auto constLit = ast::cast_tree<ast::UnresolvedConstantLit>(lastConstLit->scope)) { | |
auto lastConstLit = ast::cast_tree<ast::UnresolvedConstantLit>(scope); | |
ENFORCE(lastContLit != nullptr); | |
while (auto constLit = ast::cast_tree<ast::UnresolvedConstantLit>(lastConstLit->scope)) { |
(i try to avoid the address-of &
operator whenever possible)
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.
Couple small suggestions, but this looks great, thanks!
Wrap all package spec declarations so that they don't resolve at the top level. This is done by prefixing them with a symbol
<PackageSpecRegistry>
during packaging.Motivation
Referencing unimported packages should result in a constant resolution error. However, in cases, especially where the package had behavior at the top level, you could get confusing errors or no error at all. For example:
If you were to
include Unimported::Package
this would be a no-op and not result in any error.Test plan
Added tests.
See included automated tests.