api: Flatten and simplify Servo preferences (#34966)

Flatten and simplify Servo's preferences code. In addition, have both
preferences and options passed in as arguments to `Servo::new()` and
make sure not to use the globally set preferences in `servoshell` (as
much as possible now).

Instead of a complex procedural macro to generate preferences, just
expose a very simple derive macro that adds string based getters and
setters.

- All command-line parsing is moved to servoshell.
- There is no longer the concept of a missing preference.
- Preferences no longer have to be part of the resources bundle because
  they now have reasonable default values.
- servoshell specific preferences are no longer part of the preferences
  exposed by the Servo API.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2025-01-14 14:54:06 +01:00 committed by GitHub
parent c4c85affb5
commit 0e616e0c5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
316 changed files with 2088 additions and 3235 deletions

View file

@ -615,24 +615,24 @@ impl Runtime {
JS_SetGlobalJitCompilerOption(
cx,
JSJitCompilerOption::JSJITCOMPILER_BASELINE_INTERPRETER_ENABLE,
pref!(js.baseline_interpreter.enabled) as u32,
pref!(js_baseline_interpreter_enabled) as u32,
);
JS_SetGlobalJitCompilerOption(
cx,
JSJitCompilerOption::JSJITCOMPILER_BASELINE_ENABLE,
pref!(js.baseline_jit.enabled) as u32,
pref!(js_baseline_jit_enabled) as u32,
);
JS_SetGlobalJitCompilerOption(
cx,
JSJitCompilerOption::JSJITCOMPILER_ION_ENABLE,
pref!(js.ion.enabled) as u32,
pref!(js_ion_enabled) as u32,
);
cx_opts.compileOptions_.asmJSOption_ = if pref!(js.asmjs.enabled) {
cx_opts.compileOptions_.asmJSOption_ = if pref!(js_asmjs_enabled) {
AsmJSOption::Enabled
} else {
AsmJSOption::DisabledByAsmJSPref
};
let wasm_enabled = pref!(js.wasm.enabled);
let wasm_enabled = pref!(js_wasm_enabled);
cx_opts.set_wasm_(wasm_enabled);
if wasm_enabled {
// If WASM is enabled without setting the buildIdOp,
@ -640,20 +640,20 @@ impl Runtime {
// https://dxr.mozilla.org/mozilla-central/source/js/src/wasm/WasmTypes.cpp#458
SetProcessBuildIdOp(Some(servo_build_id));
}
cx_opts.set_wasmBaseline_(pref!(js.wasm.baseline.enabled));
cx_opts.set_wasmIon_(pref!(js.wasm.ion.enabled));
cx_opts.set_wasmBaseline_(pref!(js_wasm_baseline_enabled));
cx_opts.set_wasmIon_(pref!(js_wasm_ion_enabled));
// TODO: handle js.throw_on_asmjs_validation_failure (needs new Spidermonkey)
JS_SetGlobalJitCompilerOption(
cx,
JSJitCompilerOption::JSJITCOMPILER_NATIVE_REGEXP_ENABLE,
pref!(js.native_regex.enabled) as u32,
pref!(js_native_regex_enabled) as u32,
);
JS_SetParallelParsingEnabled(cx, pref!(js.parallel_parsing.enabled));
JS_SetOffthreadIonCompilationEnabled(cx, pref!(js.offthread_compilation.enabled));
JS_SetParallelParsingEnabled(cx, pref!(js_parallel_parsing_enabled));
JS_SetOffthreadIonCompilationEnabled(cx, pref!(js_offthread_compilation_enabled));
JS_SetGlobalJitCompilerOption(
cx,
JSJitCompilerOption::JSJITCOMPILER_BASELINE_WARMUP_TRIGGER,
if pref!(js.baseline_jit.unsafe_eager_compilation.enabled) {
if pref!(js_baseline_jit_unsafe_eager_compilation_enabled) {
0
} else {
u32::MAX
@ -662,7 +662,7 @@ impl Runtime {
JS_SetGlobalJitCompilerOption(
cx,
JSJitCompilerOption::JSJITCOMPILER_ION_NORMAL_WARMUP_TRIGGER,
if pref!(js.ion.unsafe_eager_compilation.enabled) {
if pref!(js_ion_unsafe_eager_compilation_enabled) {
0
} else {
u32::MAX
@ -676,7 +676,7 @@ impl Runtime {
JS_SetGCParameter(
cx,
JSGCParamKey::JSGC_MAX_BYTES,
in_range(pref!(js.mem.max), 1, 0x100)
in_range(pref!(js_mem_max), 1, 0x100)
.map(|val| (val * 1024 * 1024) as u32)
.unwrap_or(u32::MAX),
);
@ -684,49 +684,49 @@ impl Runtime {
JS_SetGCParameter(
cx,
JSGCParamKey::JSGC_INCREMENTAL_GC_ENABLED,
pref!(js.mem.gc.incremental.enabled) as u32,
pref!(js_mem_gc_incremental_enabled) as u32,
);
JS_SetGCParameter(
cx,
JSGCParamKey::JSGC_PER_ZONE_GC_ENABLED,
pref!(js.mem.gc.per_zone.enabled) as u32,
pref!(js_mem_gc_per_zone_enabled) as u32,
);
if let Some(val) = in_range(pref!(js.mem.gc.incremental.slice_ms), 0, 100_000) {
if let Some(val) = in_range(pref!(js_mem_gc_incremental_slice_ms), 0, 100_000) {
JS_SetGCParameter(cx, JSGCParamKey::JSGC_SLICE_TIME_BUDGET_MS, val as u32);
}
JS_SetGCParameter(
cx,
JSGCParamKey::JSGC_COMPACTING_ENABLED,
pref!(js.mem.gc.compacting.enabled) as u32,
pref!(js_mem_gc_compacting_enabled) as u32,
);
if let Some(val) = in_range(pref!(js.mem.gc.high_frequency_time_limit_ms), 0, 10_000) {
if let Some(val) = in_range(pref!(js_mem_gc_high_frequency_time_limit_ms), 0, 10_000) {
JS_SetGCParameter(cx, JSGCParamKey::JSGC_HIGH_FREQUENCY_TIME_LIMIT, val as u32);
}
if let Some(val) = in_range(pref!(js.mem.gc.low_frequency_heap_growth), 0, 10_000) {
if let Some(val) = in_range(pref!(js_mem_gc_low_frequency_heap_growth), 0, 10_000) {
JS_SetGCParameter(cx, JSGCParamKey::JSGC_LOW_FREQUENCY_HEAP_GROWTH, val as u32);
}
if let Some(val) = in_range(pref!(js.mem.gc.high_frequency_heap_growth_min), 0, 10_000) {
if let Some(val) = in_range(pref!(js_mem_gc_high_frequency_heap_growth_min), 0, 10_000) {
JS_SetGCParameter(
cx,
JSGCParamKey::JSGC_HIGH_FREQUENCY_LARGE_HEAP_GROWTH,
val as u32,
);
}
if let Some(val) = in_range(pref!(js.mem.gc.high_frequency_heap_growth_max), 0, 10_000) {
if let Some(val) = in_range(pref!(js_mem_gc_high_frequency_heap_growth_max), 0, 10_000) {
JS_SetGCParameter(
cx,
JSGCParamKey::JSGC_HIGH_FREQUENCY_SMALL_HEAP_GROWTH,
val as u32,
);
}
if let Some(val) = in_range(pref!(js.mem.gc.high_frequency_low_limit_mb), 0, 10_000) {
if let Some(val) = in_range(pref!(js_mem_gc_high_frequency_low_limit_mb), 0, 10_000) {
JS_SetGCParameter(cx, JSGCParamKey::JSGC_SMALL_HEAP_SIZE_MAX, val as u32);
}
if let Some(val) = in_range(pref!(js.mem.gc.high_frequency_high_limit_mb), 0, 10_000) {
if let Some(val) = in_range(pref!(js_mem_gc_high_frequency_high_limit_mb), 0, 10_000) {
JS_SetGCParameter(cx, JSGCParamKey::JSGC_LARGE_HEAP_SIZE_MIN, val as u32);
}
/*if let Some(val) = in_range(pref!(js.mem.gc.allocation_threshold_factor), 0, 10_000) {
/*if let Some(val) = in_range(pref!(js_mem_gc_allocation_threshold_factor), 0, 10_000) {
JS_SetGCParameter(cx, JSGCParamKey::JSGC_NON_INCREMENTAL_FACTOR, val as u32);
}*/
/*
@ -736,10 +736,10 @@ impl Runtime {
// JSGC_LARGE_HEAP_INCREMENTAL_LIMIT
pref("javascript.options.mem.gc_large_heap_incremental_limit", 110);
*/
if let Some(val) = in_range(pref!(js.mem.gc.empty_chunk_count_min), 0, 10_000) {
if let Some(val) = in_range(pref!(js_mem_gc_empty_chunk_count_min), 0, 10_000) {
JS_SetGCParameter(cx, JSGCParamKey::JSGC_MIN_EMPTY_CHUNK_COUNT, val as u32);
}
if let Some(val) = in_range(pref!(js.mem.gc.empty_chunk_count_max), 0, 10_000) {
if let Some(val) = in_range(pref!(js_mem_gc_empty_chunk_count_max), 0, 10_000) {
JS_SetGCParameter(cx, JSGCParamKey::JSGC_MAX_EMPTY_CHUNK_COUNT, val as u32);
}
@ -911,11 +911,11 @@ unsafe extern "C" fn servo_build_id(build_id: *mut BuildIdCharVector) -> bool {
unsafe fn set_gc_zeal_options(cx: *mut RawJSContext) {
use js::jsapi::SetGCZeal;
let level = match pref!(js.mem.gc.zeal.level) {
let level = match pref!(js_mem_gc_zeal_level) {
level @ 0..=14 => level as u8,
_ => return,
};
let frequency = match pref!(js.mem.gc.zeal.frequency) {
let frequency = match pref!(js_mem_gc_zeal_frequency) {
frequency if frequency >= 0 => frequency as u32,
// https://searchfox.org/mozilla-esr128/source/js/public/GCAPI.h#1392
_ => 5000,