-
Notifications
You must be signed in to change notification settings - Fork 107
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
refactor: pass along hash through eval context code cache callbacks #753
Merged
dsherret
merged 16 commits into
denoland:main
from
dsherret:code_cache_hash_eval_context
May 24, 2024
Merged
Changes from 12 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
12e49a0
refactor: pass hash into code cache
dsherret 5231fea
add export
dsherret 625d9f9
update prop name
dsherret 80f286c
update tests
dsherret e50e374
provide an owned specifier since we have it already
dsherret 31d0e22
Pass around hash for eval context's code cache
dsherret f9dfd62
Just pass this
dsherret 0f408cb
Merge branch 'main' into code_cache_hash_eval_context
dsherret 7f90723
remove local
dsherret 9d940b7
Merge branch 'main' into code_cache_hash_eval_context
dsherret bca537e
clippy
dsherret fef30da
fix tests and switch to providing Url
dsherret 3da80d3
Remove types in comment because they already got out of date
dsherret 98530ba
we can remove this now
dsherret e3c6ec3
Rename `ModuleSourceCodeCache` to `SourceCodeCacheInfo` because it ca…
dsherret 75d46bc
rust-analyzer missed these
dsherret File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -272,19 +272,20 @@ pub fn op_eval_context<'a>( | |
let tc_scope = &mut v8::TryCatch::new(scope); | ||
let source = v8::Local::<v8::String>::try_from(source) | ||
.map_err(|_| type_error("Invalid source"))?; | ||
let specifier = resolve_url(&specifier)?.to_string(); | ||
let specifier_v8 = v8::String::new(tc_scope, &specifier).unwrap(); | ||
let specifier = resolve_url(&specifier)?; | ||
let specifier_v8 = v8::String::new(tc_scope, specifier.as_str()).unwrap(); | ||
let origin = script_origin(tc_scope, specifier_v8); | ||
|
||
let (script, try_store_code_cache) = state | ||
let (maybe_script, maybe_code_cache_hash) = state | ||
.eval_context_get_code_cache_cb | ||
.as_ref() | ||
.and_then(|cb| { | ||
cb(&specifier).unwrap().map(|code_cache| { | ||
.map(|cb| { | ||
let code_cache = cb(&specifier, &source).unwrap(); | ||
if let Some(code_cache_data) = &code_cache.data { | ||
let mut source = v8::script_compiler::Source::new_with_cached_data( | ||
source, | ||
Some(&origin), | ||
v8::CachedData::new(&code_cache), | ||
v8::CachedData::new(code_cache_data), | ||
); | ||
let script = v8::script_compiler::compile( | ||
tc_scope, | ||
|
@@ -297,12 +298,19 @@ pub fn op_eval_context<'a>( | |
Some(cached_data) => cached_data.rejected(), | ||
_ => true, | ||
}; | ||
(script, rejected) | ||
}) | ||
let maybe_code_cache_hash = if rejected { | ||
Some(code_cache.hash) // recreate the cache | ||
} else { | ||
None | ||
}; | ||
(Some(script), maybe_code_cache_hash) | ||
} else { | ||
(None, Some(code_cache.hash)) | ||
} | ||
}) | ||
.unwrap_or_else(|| { | ||
(v8::Script::compile(tc_scope, source, Some(&origin)), true) | ||
}); | ||
.unwrap_or_else(|| (None, None)); | ||
let script = maybe_script | ||
.unwrap_or_else(|| v8::Script::compile(tc_scope, source, Some(&origin))); | ||
|
||
let null = v8::null(tc_scope); | ||
let script = match script { | ||
|
@@ -322,13 +330,13 @@ pub fn op_eval_context<'a>( | |
} | ||
}; | ||
|
||
if try_store_code_cache { | ||
if let Some(code_cache_hash) = maybe_code_cache_hash { | ||
if let Some(cb) = state.eval_context_code_cache_ready_cb.as_ref() { | ||
let unbound_script = script.get_unbound_script(tc_scope); | ||
let code_cache = unbound_script.create_code_cache().ok_or_else(|| { | ||
type_error("Unable to get code cache from unbound module script") | ||
})?; | ||
cb(&specifier, &code_cache); | ||
cb(specifier, code_cache_hash, &code_cache); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please focus on this function to ensure this is correct. |
||
|
||
|
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.
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.
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.
Since
v8::String
is hashable, we can just pass this along.