refactor: break up ProcState (#18707)

1. Breaks up functionality within `ProcState` into several other structs
to break out the responsibilities (`ProcState` is only a data struct
now).
2. Moves towards being able to inject dependencies more easily and have
functionality only require what it needs.
3. Exposes `Arc<T>` around the "service structs" instead of it being
embedded within them. The idea behind embedding them was to reduce the
verbosity of needing to pass around `Arc<...>`, but I don't think it was
exactly working and as we move more of these structs to be more
injectable I don't think the extra verbosity will be a big deal.
This commit is contained in:
David Sherret 2023-04-14 16:22:33 -04:00 committed by GitHub
parent a411144219
commit 136dce67ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 1506 additions and 1285 deletions

View file

@ -12,10 +12,9 @@ use deno_graph::Module;
use deno_graph::ModuleGraph;
use std::sync::Arc;
#[derive(Clone)]
pub struct Emitter {
emit_cache: EmitCache,
parsed_source_cache: ParsedSourceCache,
parsed_source_cache: Arc<ParsedSourceCache>,
emit_options: deno_ast::EmitOptions,
// cached hash of the emit options
emit_options_hash: u64,
@ -24,7 +23,7 @@ pub struct Emitter {
impl Emitter {
pub fn new(
emit_cache: EmitCache,
parsed_source_cache: ParsedSourceCache,
parsed_source_cache: Arc<ParsedSourceCache>,
emit_options: deno_ast::EmitOptions,
) -> Self {
let emit_options_hash = FastInsecureHasher::new()
@ -64,6 +63,16 @@ impl Emitter {
Ok(())
}
/// Gets a cached emit if the source matches the hash found in the cache.
pub fn maybed_cached_emit(
&self,
specifier: &ModuleSpecifier,
source: &str,
) -> Option<String> {
let source_hash = self.get_source_hash(source);
self.emit_cache.get_emit_code(specifier, source_hash)
}
pub fn emit_parsed_source(
&self,
specifier: &ModuleSpecifier,
@ -97,7 +106,7 @@ impl Emitter {
/// A hashing function that takes the source code and uses the global emit
/// options then generates a string hash which can be stored to
/// determine if the cached emit is valid or not.
pub fn get_source_hash(&self, source_text: &str) -> u64 {
fn get_source_hash(&self, source_text: &str) -> u64 {
FastInsecureHasher::new()
.write_str(source_text)
.write_u64(self.emit_options_hash)