Skip to content

Commit

Permalink
chore: bump deno_core (#22596)
Browse files Browse the repository at this point in the history
Migrations:

 - snapshot code updated
 - runtime stats API tweaks
  • Loading branch information
mmastrac authored Feb 27, 2024
1 parent f1a6912 commit 47c2a63
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 63 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ repository = "https://github.com/denoland/deno"

[workspace.dependencies]
deno_ast = { version = "0.34.0", features = ["transpiling"] }
deno_core = { version = "0.264.0", features = ["snapshot_data_bincode"] }
deno_core = { version = "0.265.0", features = ["snapshot_data_bincode"] }

deno_bench_util = { version = "0.133.0", path = "./bench_util" }
deno_lockfile = "0.19.0"
Expand Down
44 changes: 19 additions & 25 deletions cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mod ts {
use deno_runtime::deno_node::SUPPORTED_BUILTIN_NODE_MODULES;
use serde::Serialize;
use std::collections::HashMap;
use std::io::Write;
use std::path::Path;
use std::path::PathBuf;

Expand Down Expand Up @@ -266,10 +267,6 @@ mod ts {
)
.unwrap();

let snapshot_to_file = SnapshotFileSerializer::new(
std::fs::File::create(snapshot_path).unwrap(),
);

let output = create_snapshot(
CreateSnapshotOptions {
cargo_manifest_dir: env!("CARGO_MANIFEST_DIR"),
Expand All @@ -279,33 +276,30 @@ mod ts {
build_libs,
path_dts,
)],
// NOTE(bartlomieju): Compressing the TSC snapshot in debug build took
// ~45s on M1 MacBook Pro; without compression it took ~1s.
// Thus we're not not using compressed snapshot, trading off
// a lot of build time for some startup time in debug build.
#[cfg(debug_assertions)]
serializer: Box::new(snapshot_to_file),

#[cfg(not(debug_assertions))]
serializer: Box::new(SnapshotBulkCompressingSerializer::new(
snapshot_to_file,
|snapshot| {
eprintln!("Compressing TSC snapshot...");
let mut vec = Vec::with_capacity(snapshot.len());
vec.extend((snapshot.len() as u32).to_le_bytes());
vec.extend_from_slice(
&zstd::bulk::compress(&snapshot, 22)
.expect("snapshot compression failed"),
);
Ok(vec)
},
)),
with_runtime_cb: None,
skip_op_registration: false,
},
None,
)
.unwrap();

// NOTE(bartlomieju): Compressing the TSC snapshot in debug build took
// ~45s on M1 MacBook Pro; without compression it took ~1s.
// Thus we're not not using compressed snapshot, trading off
// a lot of build time for some startup time in debug build.
let mut file = std::fs::File::create(snapshot_path).unwrap();
if cfg!(debug_assertions) {
file.write_all(&output.output).unwrap();
} else {
let mut vec = Vec::with_capacity(output.output.len());
vec.extend((output.output.len() as u32).to_le_bytes());
vec.extend_from_slice(
&zstd::bulk::compress(&output.output, 22)
.expect("snapshot compression failed"),
);
file.write_all(&vec).unwrap();
}

for path in output.files_loaded_during_snapshot {
println!("cargo:rerun-if-changed={}", path.display());
}
Expand Down
5 changes: 2 additions & 3 deletions cli/js.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

use deno_core::Snapshot;
use log::debug;

#[cfg(not(feature = "__runtime_js_sources"))]
static CLI_SNAPSHOT: &[u8] =
include_bytes!(concat!(env!("OUT_DIR"), "/CLI_SNAPSHOT.bin"));

pub fn deno_isolate_init() -> Option<Snapshot> {
pub fn deno_isolate_init() -> Option<&'static [u8]> {
debug!("Deno isolate init with snapshots.");
#[cfg(not(feature = "__runtime_js_sources"))]
{
Some(Snapshot::Static(CLI_SNAPSHOT))
Some(CLI_SNAPSHOT)
}
#[cfg(feature = "__runtime_js_sources")]
{
Expand Down
20 changes: 12 additions & 8 deletions cli/tools/test/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use deno_core::stats::RuntimeActivity;
use deno_core::stats::RuntimeActivityDiff;
use deno_core::stats::RuntimeActivityTrace;
use deno_core::stats::RuntimeActivityType;
use phf::phf_map;
use std::borrow::Cow;
Expand Down Expand Up @@ -165,16 +166,19 @@ fn format_sanitizer_accum(

fn format_sanitizer_accum_item(
activity: RuntimeActivity,
) -> (RuntimeActivityType, Cow<'static, str>, Option<String>) {
) -> (
RuntimeActivityType,
Cow<'static, str>,
Option<RuntimeActivityTrace>,
) {
let activity_type = activity.activity();
match activity {
// TODO(mmastrac): OpCallTrace needs to be Eq
RuntimeActivity::AsyncOp(_, name, trace) => {
(activity_type, name.into(), trace.map(|x| x.to_string()))
RuntimeActivity::AsyncOp(_, trace, name) => {
(activity_type, name.into(), trace)
}
RuntimeActivity::Interval(_) => (activity_type, "".into(), None),
RuntimeActivity::Resource(_, name) => (activity_type, name.into(), None),
RuntimeActivity::Timer(_) => (activity_type, "".into(), None),
RuntimeActivity::Interval(..) => (activity_type, "".into(), None),
RuntimeActivity::Resource(.., name) => (activity_type, name.into(), None),
RuntimeActivity::Timer(..) => (activity_type, "".into(), None),
}
}

Expand Down Expand Up @@ -354,7 +358,7 @@ mod tests {

// https://github.com/denoland/deno/issues/13729
// https://github.com/denoland/deno/issues/13938
leak_format_test!(op_unknown, true, [RuntimeActivity::AsyncOp(0, "op_unknown", None)],
leak_format_test!(op_unknown, true, [RuntimeActivity::AsyncOp(0, None, "op_unknown")],
" - An async call to op_unknown was started in this test, but never completed.\n\
To get more details where ops were leaked, run again with --trace-ops flag.\n");
}
16 changes: 6 additions & 10 deletions cli/tools/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ async fn test_specifier_inner(
if options.trace_ops {
worker.execute_script_static(
located_script_name!(),
"Deno[Deno.internal].core.setOpCallTracingEnabled(true);",
"Deno[Deno.internal].core.setLeakTracingEnabled(true);",
)?;
}

Expand Down Expand Up @@ -740,7 +740,7 @@ fn preprocess_timer_activity(activities: &mut Vec<RuntimeActivity>) {

// First, search for any timer resources which will indicate that we have an interval leak
activities.retain(|activity| {
if let RuntimeActivity::Resource(_, name) = activity {
if let RuntimeActivity::Resource(.., name) = activity {
if name == "timer" {
timer_resource_leaked = true;
return false;
Expand All @@ -753,7 +753,7 @@ fn preprocess_timer_activity(activities: &mut Vec<RuntimeActivity>) {
// them.
if !timer_resource_leaked {
activities.retain(|activity| {
if let RuntimeActivity::AsyncOp(_, op, _) = activity {
if let RuntimeActivity::AsyncOp(.., op) = activity {
*op != "op_sleep_interval"
} else {
true
Expand All @@ -775,7 +775,7 @@ async fn wait_for_activity_to_stabilize(
let mut diff = RuntimeActivityStats::diff(&before, &after);
preprocess_timer_activity(&mut diff.appeared);
preprocess_timer_activity(&mut diff.disappeared);
if diff.appeared.is_empty() && diff.disappeared.is_empty() {
if diff.is_empty() {
// No activity, so we return early
return Ok(None);
}
Expand All @@ -792,7 +792,7 @@ async fn wait_for_activity_to_stabilize(
diff = RuntimeActivityStats::diff(&before, &after);
preprocess_timer_activity(&mut diff.appeared);
preprocess_timer_activity(&mut diff.disappeared);
if diff.appeared.is_empty() && diff.disappeared.is_empty() {
if diff.is_empty() {
return Ok(None);
}
}
Expand All @@ -814,11 +814,7 @@ async fn wait_for_activity_to_stabilize(
.retain(|activity| !matches!(activity, RuntimeActivity::Resource(..)));
}

Ok(if diff.appeared.is_empty() && diff.disappeared.is_empty() {
None
} else {
Some(diff)
})
Ok(if diff.is_empty() { None } else { Some(diff) })
}

fn extract_files_from_regex_blocks(
Expand Down
5 changes: 2 additions & 3 deletions cli/tsc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use deno_core::JsRuntime;
use deno_core::ModuleSpecifier;
use deno_core::OpState;
use deno_core::RuntimeOptions;
use deno_core::Snapshot;
use deno_graph::GraphKind;
use deno_graph::Module;
use deno_graph::ModuleGraph;
Expand Down Expand Up @@ -140,8 +139,8 @@ fn get_asset_texts_from_new_runtime() -> Result<Vec<AssetText>, AnyError> {
Ok(serde_v8::from_v8::<Vec<AssetText>>(scope, local)?)
}

pub fn compiler_snapshot() -> Snapshot {
Snapshot::Static(&COMPILER_SNAPSHOT)
pub fn compiler_snapshot() -> &'static [u8] {
&COMPILER_SNAPSHOT
}

macro_rules! inc {
Expand Down
7 changes: 4 additions & 3 deletions runtime/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use deno_core::snapshot::*;
use deno_core::v8;
use deno_core::Extension;
use deno_http::DefaultHttpPropertyExtractor;
use std::io::Write;
use std::path::Path;
use std::path::PathBuf;
use std::sync::Arc;
Expand Down Expand Up @@ -270,9 +271,6 @@ pub fn create_runtime_snapshot(
cargo_manifest_dir: env!("CARGO_MANIFEST_DIR"),
startup_snapshot: None,
extensions,
serializer: Box::new(SnapshotFileSerializer::new(
std::fs::File::create(snapshot_path).unwrap(),
)),
with_runtime_cb: Some(Box::new(|rt| {
let isolate = rt.v8_isolate();
let scope = &mut v8::HandleScope::new(isolate);
Expand All @@ -285,6 +283,9 @@ pub fn create_runtime_snapshot(
None,
)
.unwrap();
let mut snapshot = std::fs::File::create(snapshot_path).unwrap();
snapshot.write_all(&output.output).unwrap();

for path in output.files_loaded_during_snapshot {
println!("cargo:rerun-if-changed={}", path.display());
}
Expand Down
3 changes: 1 addition & 2 deletions runtime/web_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ use deno_core::OpMetricsSummaryTracker;
use deno_core::PollEventLoopOptions;
use deno_core::RuntimeOptions;
use deno_core::SharedArrayBufferStore;
use deno_core::Snapshot;
use deno_core::SourceMapGetter;
use deno_cron::local::LocalCronHandler;
use deno_fs::FileSystem;
Expand Down Expand Up @@ -336,7 +335,7 @@ pub struct WebWorker {
pub struct WebWorkerOptions {
pub bootstrap: BootstrapOptions,
pub extensions: Vec<Extension>,
pub startup_snapshot: Option<Snapshot>,
pub startup_snapshot: Option<&'static [u8]>,
pub unsafely_ignore_certificate_errors: Option<Vec<String>>,
pub root_cert_store_provider: Option<Arc<dyn RootCertStoreProvider>>,
pub seed: Option<u64>,
Expand Down
3 changes: 1 addition & 2 deletions runtime/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use deno_core::OpMetricsSummaryTracker;
use deno_core::PollEventLoopOptions;
use deno_core::RuntimeOptions;
use deno_core::SharedArrayBufferStore;
use deno_core::Snapshot;
use deno_core::SourceMapGetter;
use deno_cron::local::LocalCronHandler;
use deno_fs::FileSystem;
Expand Down Expand Up @@ -128,7 +127,7 @@ pub struct WorkerOptions {
pub extensions: Vec<Extension>,

/// V8 snapshot that should be loaded on startup.
pub startup_snapshot: Option<Snapshot>,
pub startup_snapshot: Option<&'static [u8]>,

/// Should op registration be skipped?
pub skip_op_registration: bool,
Expand Down
13 changes: 13 additions & 0 deletions tests/integration/repl_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1119,3 +1119,16 @@ fn pty_promise_was_collected_regression_test() {
assert_contains!(out, "Uint8Array(67108864)");
assert!(err.is_empty());
}

#[test]
fn eval_file_promise_error() {
let (out, err) = util::run_and_collect_output_with_args(
true,
vec!["repl", "--eval-file=./repl/promise_rejection.ts"],
None,
None,
false,
);
assert_contains!(out, "Uncaught undefined");
assert!(err.is_empty());
}
6 changes: 6 additions & 0 deletions tests/testdata/repl/promise_rejection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Regression test for https://github.com/denoland/deno/issues/22592
// deno-lint-ignore require-await
async function rejects() {
return Promise.reject();
}
await rejects();

0 comments on commit 47c2a63

Please sign in to comment.