-
Couldn't load subscription status.
- Fork 301
Disable cell-segmentation of import paths with buckconfig #1100
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
base: main
Are you sure you want to change the base?
Conversation
|
@facebook-github-bot has imported this pull request. If you are a Meta employee, you can view this in D83033385. (Because this pull request was imported automatically, there will not be any future comments.) |
351fb34 to
58cf47a
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
3978603 to
6202ba3
Compare
03d687f to
ae5a8f0
Compare
|
@facebook-github-bot has imported this pull request. If you are a Meta employee, you can view this in D83033385. (Because this pull request was imported automatically, there will not be any future comments.) |
| ImportPath::new_with_build_file_cells( | ||
| path, | ||
| self.build_file_cell, | ||
| self.cell_segmentation, |
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.
Right above this code is where we first check if the path is in the prelude and use ImportPath::new_same_cell(). When cell segmentation is disabled, ImportPath::new_with_build_file_cells behaves exactly like this.
ff0a85f to
fd0a1ce
Compare
|
Draft because basically this breaks some usages of # one//:bfc.bzl
# returns one, only evaluated once
ACTIVE_CELL = native.get_cell_name()
def macro():
# works
return native.get_cell_name()
# two//BUCK
load("one//:bfc.bzl", "macro", "ACTIVE_CELL")
# if you import ACTIVE_CELL, you get "one".
# but if you call the macro, it returns "two"
# works
macro()So we just have to fix some usages like ACTIVE_CELL to be like macro(). |
fd0a1ce to
4789797
Compare
This comment was marked as duplicate.
This comment was marked as duplicate.
This is needed sometimes in tests. You can just use `(&self.root_config).xxx()` but this is hard to discover. We could also implement the LegacyBuckConfigView directly on LegacyBuckConfig but you generally want to prohibit mutating it, hence implementing on &T in the first place.
ImportPath::new_with_build_file_cells takes a flag `cell_segmentation` and suppresses the effect of build_file_cell if it is false. We then plumb this boolean through buckconfig and dice to all the locations it is needed to construct an ImportPath. Ultimately if `buck2.disable_cell_segmentation` is true, then ImportPath becomes a redundant wrapper around CellPath.
This helps avoid having to add more cell_segmentation parameters by reducing the public API of ImportPath.
Needed to change the original test when experimenting with making disable_cell_segmentation the default on OSS. So may as well test the actual cell_segmentation behaviour.
This lets buck build itself again. These were top level get_cell_name/read_config calls that can simply be moved into the macro call.
The comment explains why. This will cause some breakage because there is code in prelude relying on read_config being inlined. Fortunately we have this behind a buckconfig flag.
Previously worked because of #[starlark(speculative_exec_safe)]. Move to top level instead of calling during analysis.
5a4fabe to
6328b14
Compare
Fixes #683 if you enable the config.
Also fixes #890.
This is achieved by ignoring dropping the build_file_cell during ImportPath construction. I can confirm this fixes the test case on that issue (https://github.com/cormacrelf/buck2-tset-bug).
This is a big improvement for users outside of Meta because previously it was practically impossible to use transitive sets. I have been writing some rules and have had to emulate the feature with regular starlark sets.
Previous version of this PR had cfg flags; now I made a buckconfig for it. Because it does break some things.
This will break any code that reads
read_config/get_cell_nameat the top level of a BZL file outside of the prelude. It will also break code that usesread_config/get_cell_nameduring analysis (which should never have worked). It is therefore not activated for anyone by default. However it is not super difficult to migrate. To test it, you can useBreakage (behind buckconfig)
Before (non-prelude cell)
After
For the prelude specifically
No change, the "after" is already how it works in the prelude.
read_configduring analysis is no longer acceptedPreviously this was unofficially and perhaps accidentally supported:
The reason being that
read_configwas#[starlark(speculative_exec_safe)], so it was actually being inlined when the entire file was parsed. It can no longer be inlined so this no longer works. It fails withReview questions
IsOk I changed it toparser.cell_segmentationthe best buckconfig name? Almost every other config is in thebuck2section but this is one of those rare occasions that maybe parser is right? Feel free to change it inapp/buck2_interpreter/src/import_paths.rs. You can call the config whatever you like, just fix the tests, or I am happy to change it. I suppose it doesn't matter since it's a temporary thing anyway.buck2.disable_cell_segmentation.