Properly use the VersionMarker in CachedFunc (#6062)

This commit is contained in:
bjorn3
2023-03-20 20:18:51 +01:00
committed by GitHub
parent dd7fa81b20
commit fc3c5d2414

View File

@@ -116,8 +116,10 @@ impl std::fmt::Display for CacheKeyHash {
#[derive(serde::Serialize, serde::Deserialize)]
struct CachedFunc {
stencil: CompiledCodeStencil,
// Note: The version marker must be first to ensure deserialization stops in case of a version
// mismatch before attempting to deserialize the actual compiled code.
version_marker: VersionMarker,
stencil: CompiledCodeStencil,
}
/// Key for caching a single function's compilation.
@@ -216,8 +218,8 @@ pub fn serialize_compiled(
result: CompiledCodeStencil,
) -> (CompiledCodeStencil, Result<Vec<u8>, bincode::Error>) {
let cached = CachedFunc {
stencil: result,
version_marker: VersionMarker,
stencil: result,
};
let result = bincode::serialize(&cached);
(cached.stencil, result)