-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix compiler issue with stale artifacts for Resolvers in watch mode (#…
…4415) Summary: The Issue: When running the compiler in watch mode, the compiler may produce artifacts for relay resolvers. For example: ``` /** RelayResolver MyType */ ``` This code would create fragments for the model resolver, including an identifier, a model instance fragment, etc. However, a problem arises in watch mode when we rename the type to: ``` /** RelayResolver MyNewType */ ``` In this case, the old artifacts are not automatically deleted. The issue lies in the compiler's inability to establish a connection between the resolver definition code and the artifacts it produces. To resolve this, we need to establish that connection. The solution: The relationship between the source documents (fragments, queries, and now resolvers) and the generated artifacts is represented in the artifact_map. In this map, the key corresponds to the document's name (fragment or query), and the value is a list of the generated artifacts. For resolvers, we will use the resolver's hash (MD5 of the source) as the key in the map, and the associated value will be the list of generated artifacts. The solution involves passing this hash to the artifact generation *place* and ensuring the proper handling of the removal of outdated artifacts. Pull Request resolved: #4415 Test Plan: **Watch mode** - Add new resolver /** RelayResolver MyType **/ - New files are created for the resolver (id, model_instance) - Change the name to /** RelayResolver MyNewType **/ - New files are created, files for MyType are deleted. --- **Non-watch Compilation (no saved state)** Run 1: - Add new resolver /** RelayResolver MyType **/ - New files are created for the resolver (id, model_instance) Rename - Change the name to /** RelayResolver MyNewType **/ Run 2: - New files are created, files for MyType are deleted. --- **Non-watch Compilation (with saved-state)** Pre-run: - Add new resolver /** RelayResolver MyType **/ - New files are created for the resolver (id, model_instance) - Commit changes. Run compiler and create saved state: ``` ./scripts/compiler.sh xplat build --export-state=/tmp/compiler-state ``` Run compiler with saved state ``` ./scripts/compiler.sh xplat build --import-state=/tmp/compiler-state ``` - No changes, quick compilation. - Update file: Change the name to /** RelayResolver MyNewType **/ Run compiler with the saved state: Old files deleted, new files created: {F1076577864} --- **Build with saved-state + dirty resolvers artifact** See the same steps for for preparation of the saved-state. Also run: - Update/Remove generated artifact for the Resolver - Run compiler with saved-state - Artifacts are restored to the correct version. Reviewed By: captbaritone Differential Revision: D48588439 Pulled By: alunyov fbshipit-source-id: 72fbebbf79eed0d512d24575601b203c3aee85a1
- Loading branch information
1 parent
7945157
commit 15c2715
Showing
68 changed files
with
477 additions
and
132 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
37 changes: 37 additions & 0 deletions
37
compiler/crates/docblock-shared/src/resolver_source_hash.rs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
use intern::string_key::Intern; | ||
use intern::string_key::StringKey; | ||
use md5::Digest; | ||
use md5::Md5; | ||
use serde::Deserialize; | ||
use serde::Serialize; | ||
|
||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, Eq, PartialEq, Hash)] | ||
|
||
pub struct ResolverSourceHash(StringKey); | ||
|
||
impl ResolverSourceHash { | ||
pub fn new(source: &str) -> Self { | ||
Self(md5(source).intern()) | ||
} | ||
|
||
pub fn from_raw(source: StringKey) -> Self { | ||
Self(source) | ||
} | ||
|
||
pub fn value(&self) -> StringKey { | ||
self.0 | ||
} | ||
} | ||
|
||
fn md5(data: &str) -> String { | ||
let mut md5 = Md5::new(); | ||
md5.update(data); | ||
hex::encode(md5.finalize()) | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,7 @@ DocblockAST { | |
}, | ||
), | ||
], | ||
source_hash: ResolverSourceHash( | ||
"4595a2a06568991a6d7594afbbe370ab", | ||
), | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,7 @@ DocblockAST { | |
}, | ||
), | ||
], | ||
source_hash: ResolverSourceHash( | ||
"b408df07614b47f8b522bf4e528448d3", | ||
), | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,7 @@ DocblockAST { | |
}, | ||
), | ||
], | ||
source_hash: ResolverSourceHash( | ||
"a49d092bbb5fbad6582962e62fac5d2c", | ||
), | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,4 +36,7 @@ DocblockAST { | |
}, | ||
), | ||
], | ||
source_hash: ResolverSourceHash( | ||
"c8f9872da22c679b3a9385d453c2d7d8", | ||
), | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,7 @@ DocblockAST { | |
}, | ||
), | ||
], | ||
source_hash: ResolverSourceHash( | ||
"39bf0ba989cb8ca55688669aa89f1f43", | ||
), | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.