Bug 1654312 - Support NullScriptThing. r=nbp

Differential Revision: https://phabricator.services.mozilla.com/D84388
This commit is contained in:
Tooru Fujisawa 2020-07-22 12:08:59 +00:00
Родитель 718c5dafae
Коммит fba1f29935
21 изменённых файлов: 4657 добавлений и 4335 удалений

Просмотреть файл

@ -30,7 +30,7 @@ rev = "61dcc364ac0d6d0816ab88a494bbf20d824b009b"
[source."https://github.com/mozilla-spidermonkey/jsparagus"]
git = "https://github.com/mozilla-spidermonkey/jsparagus"
replace-with = "vendored-sources"
rev = "e75748bec6ff2ebc9c0a7e66a2e824441b6787dd"
rev = "961aa6f7ad016f8a7f114a421ff11a95e1af0cb3"
[source."https://github.com/kvark/spirv_cross"]
branch = "wgpu3"

16
Cargo.lock сгенерированный
Просмотреть файл

@ -2371,7 +2371,7 @@ dependencies = [
[[package]]
name = "jsparagus"
version = "0.1.0"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=e75748bec6ff2ebc9c0a7e66a2e824441b6787dd#e75748bec6ff2ebc9c0a7e66a2e824441b6787dd"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=961aa6f7ad016f8a7f114a421ff11a95e1af0cb3#961aa6f7ad016f8a7f114a421ff11a95e1af0cb3"
dependencies = [
"jsparagus-ast",
"jsparagus-emitter",
@ -2385,7 +2385,7 @@ dependencies = [
[[package]]
name = "jsparagus-ast"
version = "0.1.0"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=e75748bec6ff2ebc9c0a7e66a2e824441b6787dd#e75748bec6ff2ebc9c0a7e66a2e824441b6787dd"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=961aa6f7ad016f8a7f114a421ff11a95e1af0cb3#961aa6f7ad016f8a7f114a421ff11a95e1af0cb3"
dependencies = [
"bumpalo",
"indexmap",
@ -2394,7 +2394,7 @@ dependencies = [
[[package]]
name = "jsparagus-emitter"
version = "0.1.0"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=e75748bec6ff2ebc9c0a7e66a2e824441b6787dd#e75748bec6ff2ebc9c0a7e66a2e824441b6787dd"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=961aa6f7ad016f8a7f114a421ff11a95e1af0cb3#961aa6f7ad016f8a7f114a421ff11a95e1af0cb3"
dependencies = [
"bumpalo",
"byteorder",
@ -2407,7 +2407,7 @@ dependencies = [
[[package]]
name = "jsparagus-generated-parser"
version = "0.1.0"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=e75748bec6ff2ebc9c0a7e66a2e824441b6787dd#e75748bec6ff2ebc9c0a7e66a2e824441b6787dd"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=961aa6f7ad016f8a7f114a421ff11a95e1af0cb3#961aa6f7ad016f8a7f114a421ff11a95e1af0cb3"
dependencies = [
"bumpalo",
"jsparagus-ast",
@ -2417,12 +2417,12 @@ dependencies = [
[[package]]
name = "jsparagus-json-log"
version = "0.1.0"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=e75748bec6ff2ebc9c0a7e66a2e824441b6787dd#e75748bec6ff2ebc9c0a7e66a2e824441b6787dd"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=961aa6f7ad016f8a7f114a421ff11a95e1af0cb3#961aa6f7ad016f8a7f114a421ff11a95e1af0cb3"
[[package]]
name = "jsparagus-parser"
version = "0.1.0"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=e75748bec6ff2ebc9c0a7e66a2e824441b6787dd#e75748bec6ff2ebc9c0a7e66a2e824441b6787dd"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=961aa6f7ad016f8a7f114a421ff11a95e1af0cb3#961aa6f7ad016f8a7f114a421ff11a95e1af0cb3"
dependencies = [
"arrayvec",
"bumpalo",
@ -2434,7 +2434,7 @@ dependencies = [
[[package]]
name = "jsparagus-scope"
version = "0.1.0"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=e75748bec6ff2ebc9c0a7e66a2e824441b6787dd#e75748bec6ff2ebc9c0a7e66a2e824441b6787dd"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=961aa6f7ad016f8a7f114a421ff11a95e1af0cb3#961aa6f7ad016f8a7f114a421ff11a95e1af0cb3"
dependencies = [
"indexmap",
"jsparagus-ast",
@ -2444,7 +2444,7 @@ dependencies = [
[[package]]
name = "jsparagus-stencil"
version = "0.1.0"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=e75748bec6ff2ebc9c0a7e66a2e824441b6787dd#e75748bec6ff2ebc9c0a7e66a2e824441b6787dd"
source = "git+https://github.com/mozilla-spidermonkey/jsparagus?rev=961aa6f7ad016f8a7f114a421ff11a95e1af0cb3#961aa6f7ad016f8a7f114a421ff11a95e1af0cb3"
dependencies = [
"jsparagus-ast",
]

Просмотреть файл

@ -279,6 +279,10 @@ bool ConvertGCThings(JSContext* cx, const SmooshResult& result,
SmooshGCThing& item = smooshStencil.gcthings.data[i];
switch (item.tag) {
case SmooshGCThing::Tag::Null: {
gcThings.infallibleAppend(NullScriptThing());
break;
}
case SmooshGCThing::Tag::Atom: {
gcThings.infallibleAppend(
mozilla::AsVariant(allAtoms[item.AsAtom()].get()));

Просмотреть файл

@ -12,12 +12,12 @@ log = "0.4"
# Disable regex feature for code size.
env_logger = {version = "0.6", default-features = false}
# For non-jsparagus developers.
jsparagus = { git = "https://github.com/mozilla-spidermonkey/jsparagus", rev = "e75748bec6ff2ebc9c0a7e66a2e824441b6787dd" }
jsparagus = { git = "https://github.com/mozilla-spidermonkey/jsparagus", rev = "961aa6f7ad016f8a7f114a421ff11a95e1af0cb3" }
# For local development, replace above with
# jsparagus = { path = "{path to jsparagus}" }
[build-dependencies]
# For non-jsparagus developers.
jsparagus = { git = "https://github.com/mozilla-spidermonkey/jsparagus", rev = "e75748bec6ff2ebc9c0a7e66a2e824441b6787dd" }
jsparagus = { git = "https://github.com/mozilla-spidermonkey/jsparagus", rev = "961aa6f7ad016f8a7f114a421ff11a95e1af0cb3" }
# For local development, replace above with
# jsparagus = { path = "{path to jsparagus}" }

Просмотреть файл

@ -72,6 +72,7 @@ pub struct SmooshCompileOptions {
#[repr(C, u8)]
pub enum SmooshGCThing {
Null,
Atom(usize),
Scope(usize),
RegExp(usize),
@ -80,6 +81,7 @@ pub enum SmooshGCThing {
impl From<GCThing> for SmooshGCThing {
fn from(item: GCThing) -> Self {
match item {
GCThing::Null => Self::Null,
GCThing::Atom(index) => Self::Atom(index.into()),
GCThing::Function(_index) => {
panic!("Not yet implemented");

Просмотреть файл

@ -1 +1 @@
{"files":{"Cargo.toml":"00c740f44b5681e3277e519d2e143e6edfbff186ca31a07ddce2eb46b803ddd7","src/array_emitter.rs":"bbc6528321f1d11d7c86c4f2bfdcfc9dced8f0b8b1c30c9f0a5355f300d196b6","src/ast_emitter.rs":"43686d1c8a7af3af9715a831ede7442e8ec1d82b84efff08a910b908a3b0b114","src/block_emitter.rs":"78965260d87a66c5324d6f3bdfea0f1938f8037f70adde148dbb2db599d1b2c0","src/compilation_info.rs":"32ca7cdae514501de0d0d667ff2b27a3abf736ae207a23009c42eacbdffbd5b3","src/control_structures.rs":"bdb186e98c14fa4e769b23b3dee4376683e6c6530af0856d55c055aff4398b84","src/dis.rs":"4a335d813fa965482ca0f20a7b9295a55ce7625b577d42bd8b33b156b81c6306","src/emitter.rs":"1108fb14184ce4d2eaf8c1daeab36d10140bb529f97c6c62056fe46d1fbfa3d0","src/emitter_scope.rs":"07a904b6973bd2dbc1f9395022c15f11f6befc9b0fb4f2f251ccfc3f09aff380","src/expression_emitter.rs":"f8e02785dffb179bbe9fe58e45bbfccc08adc3ad0a071a0073bed0feedc8ed9a","src/function_declaration_emitter.rs":"c2bbfe2c27e97a345d34c6da056c7ac45b48af45b6216a8dec114673320abe7e","src/lib.rs":"271d385beb1a507a9bbb8671a11f3ab8f072348ac03eebcfd41364b82410ef1a","src/object_emitter.rs":"998423b3d6ef8797fadef6763803627df72fde292b1b34d6a41b2e66a331a181","src/reference_op_emitter.rs":"4ead96ef4424e3937c3f73e22b4e103f97cee522b9926345caeddcf4643ff843","src/script_emitter.rs":"44a6be5ecdcde3c32d78d100a205d38be2591c7c2cc109967579af7393e09fe8"},"package":null}
{"files":{"Cargo.toml":"00c740f44b5681e3277e519d2e143e6edfbff186ca31a07ddce2eb46b803ddd7","src/array_emitter.rs":"bbc6528321f1d11d7c86c4f2bfdcfc9dced8f0b8b1c30c9f0a5355f300d196b6","src/ast_emitter.rs":"43686d1c8a7af3af9715a831ede7442e8ec1d82b84efff08a910b908a3b0b114","src/block_emitter.rs":"78965260d87a66c5324d6f3bdfea0f1938f8037f70adde148dbb2db599d1b2c0","src/compilation_info.rs":"32ca7cdae514501de0d0d667ff2b27a3abf736ae207a23009c42eacbdffbd5b3","src/control_structures.rs":"bdb186e98c14fa4e769b23b3dee4376683e6c6530af0856d55c055aff4398b84","src/dis.rs":"4a335d813fa965482ca0f20a7b9295a55ce7625b577d42bd8b33b156b81c6306","src/emitter.rs":"1108fb14184ce4d2eaf8c1daeab36d10140bb529f97c6c62056fe46d1fbfa3d0","src/emitter_scope.rs":"07a904b6973bd2dbc1f9395022c15f11f6befc9b0fb4f2f251ccfc3f09aff380","src/expression_emitter.rs":"f8e02785dffb179bbe9fe58e45bbfccc08adc3ad0a071a0073bed0feedc8ed9a","src/function_declaration_emitter.rs":"e69acd58c8db9eb77875000cce92240a38ad84482a5db7338c3bda75ce6430c2","src/lib.rs":"271d385beb1a507a9bbb8671a11f3ab8f072348ac03eebcfd41364b82410ef1a","src/object_emitter.rs":"998423b3d6ef8797fadef6763803627df72fde292b1b34d6a41b2e66a331a181","src/reference_op_emitter.rs":"4ead96ef4424e3937c3f73e22b4e103f97cee522b9926345caeddcf4643ff843","src/script_emitter.rs":"44a6be5ecdcde3c32d78d100a205d38be2591c7c2cc109967579af7393e09fe8"},"package":null}

Просмотреть файл

@ -11,6 +11,11 @@ pub struct LazyFunctionEmitter {
impl LazyFunctionEmitter {
pub fn emit(self, emitter: &mut AstEmitter) -> GCThingIndex {
emitter
.compilation_info
.functions
.get_mut(self.stencil_index)
.set_function_emitted();
emitter.emit.get_function_gcthing_index(self.stencil_index)
}
}

Просмотреть файл

@ -1 +1 @@
{"files":{"Cargo.toml":"553be3c198fe555913bbeb7473b24e0e1fff12e48890a2e399b311df8a97c814","src/ast_builder.rs":"ff3cd595b70e8359b4ce9ce78b066890a78572fee923fcd8cadd029b8fbc4d7a","src/context_stack.rs":"29331d03cd4c8ee9283cb426ebe893b7ba6ad6d8a69016399c4d92a81cb1363b","src/declaration_kind.rs":"fdfda2fe408cce1c637d17fee0813160619450472c6de9befc36ebeed892cc3c","src/early_error_checker.rs":"150a106a8f0901b72ae40581f0c12f785983514cbc9042404ed6cf4315693d60","src/early_errors.rs":"8674454af7ac5efe51eb6a8e2abe088aad5560e0a0bd88a3eae66c90f1527149","src/error.rs":"507e4dd9c66720f3da2db135c3024392d8aaac5ccdb90c7f7463ccb2eff7efa8","src/lib.rs":"b74105a84c4a141b880439f9ec724f7dc08224342be08a73490ac2c01410af08","src/parser_tables_generated.rs":"403e630c54088a55f2d348e7a817716bb54ef52f96f102d198e9aa7ffa5ea1bc","src/stack_value_generated.rs":"ce8567634ff2bb818593f56c0589b4ba2d508704db943eb0778d79dfd19cce36","src/token.rs":"479f4cb97d2e6bc654a70634f3809817cc73eaf749c845643beb3556b9ead383","src/traits/mod.rs":"ba74c71f7218027f8188247bc64df243117613fbc9893d40799402ef1e6dbf59"},"package":null}
{"files":{"Cargo.toml":"553be3c198fe555913bbeb7473b24e0e1fff12e48890a2e399b311df8a97c814","src/ast_builder.rs":"ff3cd595b70e8359b4ce9ce78b066890a78572fee923fcd8cadd029b8fbc4d7a","src/context_stack.rs":"29331d03cd4c8ee9283cb426ebe893b7ba6ad6d8a69016399c4d92a81cb1363b","src/declaration_kind.rs":"fdfda2fe408cce1c637d17fee0813160619450472c6de9befc36ebeed892cc3c","src/early_error_checker.rs":"150a106a8f0901b72ae40581f0c12f785983514cbc9042404ed6cf4315693d60","src/early_errors.rs":"8674454af7ac5efe51eb6a8e2abe088aad5560e0a0bd88a3eae66c90f1527149","src/error.rs":"507e4dd9c66720f3da2db135c3024392d8aaac5ccdb90c7f7463ccb2eff7efa8","src/lib.rs":"b74105a84c4a141b880439f9ec724f7dc08224342be08a73490ac2c01410af08","src/parser_tables_generated.rs":"4160b31222eadb359c28f84d6f1f8e8219c78619e4eb7589532632ca06537829","src/stack_value_generated.rs":"ce8567634ff2bb818593f56c0589b4ba2d508704db943eb0778d79dfd19cce36","src/token.rs":"479f4cb97d2e6bc654a70634f3809817cc73eaf749c845643beb3556b9ead383","src/traits/mod.rs":"ba74c71f7218027f8188247bc64df243117613fbc9893d40799402ef1e6dbf59"},"package":null}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1 +1 @@
{"files":{"Cargo.toml":"500dc18629fd32dd7019a7967535d6fc53bf94dc7e6c305be46f4040d47cac9e","src/builder.rs":"cccbb9f6d0a33bfb13b9362590e2266b172786beb784338eeca9cdbf2b936d13","src/data.rs":"a3cf1e7b1a96a619bcb8bd87f39bbd44dda0fc554c70a5d4d45b70eb03e69401","src/free_name_tracker.rs":"30c55b85d61bbcc43ce4ade4bdf93d01369b80e486589df89c3175445a491b2a","src/lib.rs":"16b1fe6659f977a547df15922b2864b81c4d452ad198409db4374e88c6df68bc","src/pass.rs":"2ae0c72e428932c9f1c5e6b37043e93fcf686dde0b9f26b60d1a710bcd73852d"},"package":null}
{"files":{"Cargo.toml":"500dc18629fd32dd7019a7967535d6fc53bf94dc7e6c305be46f4040d47cac9e","src/builder.rs":"d38bb005f01e9fce3a2904823a6e559998c3c50c07f61024edfcff3107e610de","src/data.rs":"a3cf1e7b1a96a619bcb8bd87f39bbd44dda0fc554c70a5d4d45b70eb03e69401","src/free_name_tracker.rs":"322228be4262d79d148f954a656b4f09fe953b324393fcc5925675c0e7777828","src/lib.rs":"16b1fe6659f977a547df15922b2864b81c4d452ad198409db4374e88c6df68bc","src/pass.rs":"2ae0c72e428932c9f1c5e6b37043e93fcf686dde0b9f26b60d1a710bcd73852d"},"package":null}

Просмотреть файл

@ -1046,6 +1046,8 @@ struct FunctionParametersScopeBuilder {
script_index: ScriptStencilIndex,
has_direct_eval: bool,
is_arrow: bool,
}
impl FunctionParametersScopeBuilder {
@ -1084,6 +1086,7 @@ impl FunctionParametersScopeBuilder {
scope_index,
script_index,
has_direct_eval: false,
is_arrow,
}
}
@ -1406,6 +1409,7 @@ impl FunctionParametersScopeBuilder {
function_max_var_names_count,
enclosing,
self.script_index,
self.is_arrow,
);
// FunctionDeclarationInstantiation ( func, argumentsList )
@ -1883,11 +1887,28 @@ impl ScopeKindStack {
#[derive(Debug)]
struct ScopeBuilderStack {
stack: Vec<ScopeBuilder>,
/// Stack of lists of names that is
/// 1. defined in the scope
/// 2. closed over by inner script
///
/// Each list is delimited by `None`, for each scope.
///
/// The order of scopes is depth-first post-order, and the order of names
/// inside each scope is in not defined.
///
/// When entering a function, empty list is pushed to this stack, and
/// when leaving each function, top-most list is popped, and
/// added to gcthings of the function, and this list is reset to empty.
closed_over_bindings_for_lazy: Vec<Vec<Option<SourceAtomSetIndex>>>,
}
impl ScopeBuilderStack {
fn new() -> Self {
Self { stack: Vec::new() }
Self {
stack: Vec::new(),
closed_over_bindings_for_lazy: Vec::new(),
}
}
fn innermost_var<'a>(&'a mut self) -> &'a mut ScopeBuilder {
@ -2013,6 +2034,18 @@ impl ScopeBuilderStack {
let inner_base = inner.base();
let outer_base = outer.base_mut();
match self.closed_over_bindings_for_lazy.last_mut() {
Some(bindings) => {
for name in inner_base.name_tracker.defined_and_closed_over_vars() {
bindings.push(Some(*name));
}
bindings.push(None);
}
None => {
// We're leaving lexical scope in top-level script.
}
}
// When construct such as `eval`, `with` and `delete` access
// name dynamically in inner scopes, we have to propagate this
// flag to the outer scope such that we prevent optimizations.
@ -2202,7 +2235,7 @@ impl FunctionScriptStencilBuilder {
{
let loc = params.get_loc();
let params_start = loc.start;
self.current_mut().set_to_string_starts(params_start);
self.current_mut().set_source_starts(params_start);
}
fn on_non_rest_parameter(&mut self) {
@ -2217,30 +2250,36 @@ impl FunctionScriptStencilBuilder {
fun.set_has_rest();
}
/// Add all closed over bindings of the current function,
/// that is calculated by `parameter_scope_builder`.
fn add_closed_over_bindings(
&mut self,
parameter_scope_builder: &FunctionParametersScopeBuilder,
mut closed_over_bindings_for_lazy: Vec<Option<SourceAtomSetIndex>>,
) {
let closed_over_freevars: HashSet<SourceAtomSetIndex> = parameter_scope_builder
.base
.name_tracker
.closed_over_freevars()
.cloned()
.collect();
let used_freevars: HashSet<SourceAtomSetIndex> = parameter_scope_builder
.base
.name_tracker
.used_freevars()
.cloned()
.collect();
let all_freevars = closed_over_freevars.union(&used_freevars);
// Remove trailing `None`s.
loop {
match closed_over_bindings_for_lazy.last() {
Some(Some(_)) => {
// The last item isn't None.
break;
}
Some(None) => {
// The last item is None, remove it
closed_over_bindings_for_lazy.pop();
}
None => {
// List is empty.
break;
}
}
}
let current = self.current_mut();
for name in all_freevars {
current.push_closed_over_bindings(*name);
for name in closed_over_bindings_for_lazy {
match name {
Some(name) => current.push_closed_over_bindings(name),
None => current.push_closed_over_bindings_delimiter(),
}
}
}
}
@ -2616,6 +2655,10 @@ impl ScopeDataMapBuilder {
where
T: SourceLocationAccessor + NodeTypeIdAccessor,
{
self.builder_stack
.closed_over_bindings_for_lazy
.push(Vec::new());
self.function_stencil_builder.on_function_parameters(params);
let index = self.scopes.allocate();
@ -2697,8 +2740,12 @@ impl ScopeDataMapBuilder {
let parameter_scope_builder = self.builder_stack.pop_function_parameters();
let enclosing = self.builder_stack.current_scope_index();
self.function_stencil_builder
.add_closed_over_bindings(&parameter_scope_builder);
self.function_stencil_builder.add_closed_over_bindings(
self.builder_stack
.closed_over_bindings_for_lazy
.pop()
.expect("Vector should be pushed by before_function_parameters"),
);
let function_scope_index = parameter_scope_builder.scope_index;
let var_scope_index = body_scope_builder.var_scope_index;

Просмотреть файл

@ -9,7 +9,7 @@
use ast::source_atom_set::SourceAtomSetIndex;
use std::collections::hash_map::RandomState;
use std::collections::hash_set::Difference;
use std::collections::hash_set::{Difference, Intersection};
use std::collections::HashSet;
/// Tracks free names in a scope.
@ -88,6 +88,13 @@ impl FreeNameTracker {
self.closed_over_names.difference(&self.def_names)
}
/// Names defined in this scope and closed over by inner script-scopes.
pub fn defined_and_closed_over_vars(
&self,
) -> Intersection<'_, SourceAtomSetIndex, RandomState> {
self.def_names.intersection(&self.closed_over_names)
}
/// Names used in this and inner non-script scopes, that's not yet defined.
pub fn used_freevars(&self) -> Difference<'_, SourceAtomSetIndex, RandomState> {
self.used_names.difference(&self.def_names)

Просмотреть файл

@ -1 +1 @@
{"files":{"Cargo.toml":"f5439990185662ab31de12c07ef0c842438e3207bdfecc4fa6a9e4d4bea8a0d3","src/bytecode_offset.rs":"2aa7ba8c3cfbbd832092e65b599ab1c5a28d784ccc65d9e351bba656421b9a69","src/copy/AsyncFunctionResolveKind.h":"3851ecbb4728257595dd6e900749d1d8e02558574c00424a7ff0e3ca007fa6ec","src/copy/BytecodeFormatFlags.h":"f495a25e113a92071514d17483fbd821c9e9b24b164cae1c6b5ad2dd7491a945","src/copy/CheckIsObjectKind.h":"8f0e112396d966c9221a743d353f62671e04cdace7dd49a59898d94ba0f621b7","src/copy/FunctionFlags.h":"e2578c5747f298d03d81fa2b248e4b36800ac8d42d9d6ef801ebb1bc13bc3960","src/copy/FunctionPrefixKind.h":"f540a5c646a519b2d61aa27e4be865e08a31438def00ad5ba4ba2982ad1f2275","src/copy/GeneratorAndAsyncKind.h":"301668ce705970a51abfa94f89fd5db29ef5f129525110860e9e9bf7586ef187","src/copy/GeneratorResumeKind.h":"9e3cd9dc9c7f50937c6c45d73ec092dbfd92c4b56818ae6d1504bcd77078d0a6","src/copy/Opcodes.h":"6663f2ae6251b341352c0f75bea2a2c27babd555768e74727ecf524b1e83563e","src/copy/SourceNotes.h":"1e467f4e63d6f40a428e257fecd210bd14664516adf75a45cb17ab02ccd65fd8","src/copy/StencilEnums.h":"e5a1db4af868fd65591ed97594f7aa9a4cde79194da0cabd62b34e950b3b10b4","src/copy/Symbol.h":"603985e8c92c94e021baf3a0114dd384035eda60827016d310f1507c8396a45e","src/copy/ThrowMsgKind.h":"da805756961d81a2b50aeb391a02fd59a0aa39a9e3eb6aae21b423b15875ab30","src/env_coord.rs":"0be36a1bd307f5586affe0f3046d8b2ab2f5382b41b7b7bfb364b97d16a7c410","src/frame_slot.rs":"b20c81d67c572f20d06d493b211cd3eaa0432a8294541583643b82df3af2f813","src/function.rs":"b841ba6f7ecee3a38a136ef9902fd1d4a3f6b0aa96d1e8d8340e7f26dead75d9","src/gcthings.rs":"e2cb24050e30f423d0fe7bdbf2295854c4b8d3d76a202d47ea4c4e5586c4db58","src/lib.rs":"b003e085344277d2987ef492dc513048e8ec83217850a22ba7ca06ac01bc9b5c","src/opcode.rs":"aabbeae9df11564d3275414497ff99499f3d297f6d062351180f77cb23e588a0","src/opcode_info.rs":"a27c6d5602f5ecdcc882a0167614bc7a7754d958124941b4c1c0cdc2b0a894f1","src/regexp.rs":"7436cf545b990bec7dcc51ff28d67deaca9d4ce894468fdad0dd44b25c571cf2","src/result.rs":"58a64e0619c4ba4c6b7d8834208698a8f1639ab1771f7ae22272f81fe3611d63","src/scope.rs":"0e6b287226d92b7cdb914dc2513865ceac8fc0bdd49d4a1806652cd28c466044","src/scope_notes.rs":"9947ba5aba3097321c76adcb5648a478e4a67e088fdc1e01511e51c4ad41a9f3","src/script.rs":"52f1e97bcf9d1d7c11bb6e42b52f0a2a4ced1059e8c0c0296e1dccb31de646c0"},"package":null}
{"files":{"Cargo.toml":"f5439990185662ab31de12c07ef0c842438e3207bdfecc4fa6a9e4d4bea8a0d3","src/bytecode_offset.rs":"2aa7ba8c3cfbbd832092e65b599ab1c5a28d784ccc65d9e351bba656421b9a69","src/copy/AsyncFunctionResolveKind.h":"3851ecbb4728257595dd6e900749d1d8e02558574c00424a7ff0e3ca007fa6ec","src/copy/BytecodeFormatFlags.h":"f495a25e113a92071514d17483fbd821c9e9b24b164cae1c6b5ad2dd7491a945","src/copy/CheckIsObjectKind.h":"8f0e112396d966c9221a743d353f62671e04cdace7dd49a59898d94ba0f621b7","src/copy/FunctionFlags.h":"e2578c5747f298d03d81fa2b248e4b36800ac8d42d9d6ef801ebb1bc13bc3960","src/copy/FunctionPrefixKind.h":"f540a5c646a519b2d61aa27e4be865e08a31438def00ad5ba4ba2982ad1f2275","src/copy/GeneratorAndAsyncKind.h":"301668ce705970a51abfa94f89fd5db29ef5f129525110860e9e9bf7586ef187","src/copy/GeneratorResumeKind.h":"9e3cd9dc9c7f50937c6c45d73ec092dbfd92c4b56818ae6d1504bcd77078d0a6","src/copy/Opcodes.h":"6663f2ae6251b341352c0f75bea2a2c27babd555768e74727ecf524b1e83563e","src/copy/SourceNotes.h":"1e467f4e63d6f40a428e257fecd210bd14664516adf75a45cb17ab02ccd65fd8","src/copy/StencilEnums.h":"e5a1db4af868fd65591ed97594f7aa9a4cde79194da0cabd62b34e950b3b10b4","src/copy/Symbol.h":"603985e8c92c94e021baf3a0114dd384035eda60827016d310f1507c8396a45e","src/copy/ThrowMsgKind.h":"da805756961d81a2b50aeb391a02fd59a0aa39a9e3eb6aae21b423b15875ab30","src/env_coord.rs":"0be36a1bd307f5586affe0f3046d8b2ab2f5382b41b7b7bfb364b97d16a7c410","src/frame_slot.rs":"b20c81d67c572f20d06d493b211cd3eaa0432a8294541583643b82df3af2f813","src/function.rs":"b841ba6f7ecee3a38a136ef9902fd1d4a3f6b0aa96d1e8d8340e7f26dead75d9","src/gcthings.rs":"baadc7284c01961a4aa44d464a6f5a0d0be427b6d099c949d4411846738d9a45","src/lib.rs":"b003e085344277d2987ef492dc513048e8ec83217850a22ba7ca06ac01bc9b5c","src/opcode.rs":"aabbeae9df11564d3275414497ff99499f3d297f6d062351180f77cb23e588a0","src/opcode_info.rs":"a27c6d5602f5ecdcc882a0167614bc7a7754d958124941b4c1c0cdc2b0a894f1","src/regexp.rs":"7436cf545b990bec7dcc51ff28d67deaca9d4ce894468fdad0dd44b25c571cf2","src/result.rs":"58a64e0619c4ba4c6b7d8834208698a8f1639ab1771f7ae22272f81fe3611d63","src/scope.rs":"57560a57ff8b07fff99185b894a950815069789a8e7f0c0a87c11bf56d15df8e","src/scope_notes.rs":"9947ba5aba3097321c76adcb5648a478e4a67e088fdc1e01511e51c4ad41a9f3","src/script.rs":"009679135ef4c3949121b96911720394fce06bc992bdcac13f8fc96e4649513f"},"package":null}

Просмотреть файл

@ -7,6 +7,7 @@ use ast::source_atom_set::SourceAtomSetIndex;
/// in m-c/js/src/frontend/BytecodeSection.h.
#[derive(Debug)]
pub enum GCThing {
Null,
Atom(SourceAtomSetIndex),
Function(ScriptStencilIndex),
RegExp(RegExpIndex),

Просмотреть файл

@ -473,6 +473,9 @@ pub struct FunctionScopeData {
pub enclosing: ScopeIndex,
pub function_index: ScriptStencilIndex,
/// True if the function is an arrow function.
pub is_arrow: bool,
}
impl FunctionScopeData {
@ -483,6 +486,7 @@ impl FunctionScopeData {
max_var_count: usize,
enclosing: ScopeIndex,
function_index: ScriptStencilIndex,
is_arrow: bool,
) -> Self {
let capacity = positional_parameter_count + non_positional_formal_start + max_var_count;
@ -495,6 +499,7 @@ impl FunctionScopeData {
first_frame_slot: FrameSlot::new(0),
enclosing,
function_index,
is_arrow,
}
}
}

Просмотреть файл

@ -247,24 +247,71 @@ impl SourceExtent {
/// Maps to js::frontend::ScriptStencil in m-c/js/src/frontend/Stencil.h.
#[derive(Debug)]
pub struct ScriptStencil {
// Fields for BaseScript.
// Used by:
// * Global script
// * Eval
// * Module
// * non-lazy Function (except asm.js module)
// * lazy Function (cannot be asm.js module)
/// See `BaseScript::immutableFlags_`.
pub immutable_flags: ImmutableScriptFlags,
/// For top level script and non-lazy function script,
/// this is a list of GC things referred by bytecode and scope.
///
/// For lazy function script, this is a list of inner functions and
/// closed over bindings.
/// For lazy function script, this contains the list of inner functions,
/// followed by the list of names defined and closed over by inner script.
/// The list of names are delimited by GCThing::Null for each scope.
///
/// The order of scopes are depth-first post-order, and names inside each
/// scope is in not defined.
///
/// Trailing scopes without any names are omitted for space efficiency.
pub gcthings: Vec<GCThing>,
/// See `BaseScript::sharedData_`.
pub immutable_script_data: Option<ImmutableScriptDataIndex>,
/// The location of this script in the source.
pub extent: SourceExtent,
// Fields for JSFunction.
// Used by:
// * non-lazy Function
// * lazy Function
// * asm.js module
/// The explicit or implicit name of the function. The FunctionFlags
/// indicate the kind of name.
pub fun_name: Option<SourceAtomSetIndex>,
/// See `JSFunction::nargs_`.
pub fun_nargs: u16,
/// See: `FunctionFlags`.
pub fun_flags: FunctionFlags,
/// If this ScriptStencil refers to a lazy child of the function being
/// compiled, this field holds the child's immediately enclosing scope's
/// index. Once compilation succeeds, we will store the scope pointed by
/// this in the child's BaseScript. (Debugger may become confused if lazy
/// scripts refer to partially initialized enclosing scopes, so we must
/// avoid storing the scope in the BaseScript until compilation has
/// completed successfully.)
pub lazy_function_enclosing_scope_index: Option<ScopeIndex>,
/// This function is a standalone function that is not syntactically part of
/// another script. Eg. Created by `new Function("")`.
pub is_standalone_function: bool,
/// This is set by the emitter of the enclosing script when a
/// reference to this function is generated.
pub was_function_emitted: bool,
/// This function should be marked as a singleton. It is expected to be
/// defined at most once. This is a heuristic only and does not affect
/// correctness.
pub is_singleton_function: bool,
}
impl ScriptStencil {
@ -282,6 +329,9 @@ impl ScriptStencil {
fun_nargs: 0,
fun_flags: FunctionFlags::empty(),
lazy_function_enclosing_scope_index: None,
is_standalone_function: false,
was_function_emitted: false,
is_singleton_function: false,
}
}
@ -310,6 +360,9 @@ impl ScriptStencil {
fun_nargs: 0,
fun_flags,
lazy_function_enclosing_scope_index: Some(lazy_function_enclosing_scope_index),
is_standalone_function: false,
was_function_emitted: false,
is_singleton_function: false,
}
}
@ -392,18 +445,26 @@ impl ScriptStencil {
self.fun_nargs += 1;
}
pub fn set_to_string_starts(&mut self, to_string_start: usize) {
self.extent.to_string_start = to_string_start as u32;
/// source_start should point the start of parameter for functions.
pub fn set_source_starts(&mut self, source_start: usize) {
self.extent.source_start = source_start as u32;
}
/// to_string_end should point the end of function body for function,
/// and the end of class for constructor.
pub fn set_to_string_end(&mut self, to_string_end: usize) {
self.extent.to_string_end = to_string_end as u32;
}
/// source_end should point the end of function body.
pub fn set_source_end(&mut self, source_end: usize) {
self.extent.source_end = source_end as u32;
}
pub fn set_function_emitted(&mut self) {
self.was_function_emitted = true;
}
pub fn push_inner_function(&mut self, fun: ScriptStencilIndex) {
self.immutable_flags
.set(ImmutableScriptFlagsEnum::HasInnerFunctions);
@ -414,6 +475,11 @@ impl ScriptStencil {
debug_assert!(self.is_lazy_function());
self.gcthings.push(GCThing::Atom(name));
}
pub fn push_closed_over_bindings_delimiter(&mut self) {
debug_assert!(self.is_lazy_function());
self.gcthings.push(GCThing::Null);
}
}
/// Index into ScriptStencilList.scripts.

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -0,0 +1,135 @@
name: Real JS Samples Benchmark
on:
pull_request:
types: [opened, synchronize, reopened]
push:
branches:
- master
jobs:
benchmark:
# This workflow relies on:
# - A specific hardware (benchmark-pool-1) in order to have a consistent
# and comparable results against multiple builds.
#
# - Some persistent data to reduce the time needed to checkout
# mozilla-central.
#
# To setup such host multiple things should be considered.
#
# In terms of security, the code which is executed on this hardware should
# not be trusted. As such, the Github Action jobs should run on a dedicated
# computer which is either isolated or containerized. Do not run this setup
# on a non-dedicated computer!
#
# It is best to create a dedicated user.
# $ mkdir /var/github-action-runner
# $ useradd -d /var/github-action-runner github-action-user
#
# Make sure this newly added user has no sudo capabilities.
#
# A checkout of Gecko should be present under /var/github-action-runner. The
# dependencies for building Gecko should as well be installed with `mach
# bootstrap`, which can be done using another user with sudo capabilities,
# and changing the HOME environment variable to match the github-action-user
# home.
#
# The file /var/github-action-runner/.profile contains:
#
# export PATH="$HOME/.cargo/bin:$PATH"
# export PATH="/var/github-action-runner/.mozbuild/git-cinnabar:$PATH"
#
# Which is used to add cargo in the path, as well as git-cinnabar, to keep
# the gecko clone up to date.
#
# To add this computer to the benchmark pool, follow the instruction
# provided by github, after clicking "Add runner" on this page:
# https://github.com/mozilla-spidermonkey/jsparagus/settings/actions
#
# "benchmark-pool-1" specification:
# /proc/cpuinfo:
# Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
# dmidecode --type 17:
# 2x Hynix/Hyundai HMT41GU6MFR8C-PB (DDR3, 8GB, 1600 MT/s)
#
runs-on: [self-hosted, benchmark-pool-1]
steps:
- name: Clean Work Directory
run: |
rm -rf *
- name: Checkout jsparagus
uses: actions/checkout@v2
with:
fetch-depth: 0
path: 'jsparagus'
- name: Checkout real-js-samples
uses: actions/checkout@v2
with:
repository: 'Yoric/real-js-samples'
path: 'real-js-samples'
fetch-depth: 0
- name: Checkout mozilla-central
run: |
# Pull mozilla-central changes
source /var/github-action-runner/.profile
git -C /var/github-action-runner/gecko pull --all
# Create a local clone of mozilla-central
git clone -l /var/github-action-runner/gecko mozilla-central
- name: Status of Checkouts
run: |
echo "mozilla-central: $(git -C mozilla-central show --oneline -s)"
echo "jsparagus: $(git -C jsparagus show --oneline -s)"
echo "real-js-samples: $(git -C real-js-samples show --oneline -s)"
- name: Setup venv
run: |
source /var/github-action-runner/.profile
cd jsparagus
make init
- name: Generate Files
run: |
source /var/github-action-runner/.profile
cd jsparagus
make all
# OS independant replace
sed -i.bak '/*_generated.rs/d' .gitignore && rm .gitignore.bak
- name: Apply gecko patches
run: |
source /var/github-action-runner/.profile
cd mozilla-central
cat ../jsparagus/gecko-patches.txt | while read PATCH_AND_BUG; do
PATCH=$(echo $PATCH_AND_BUG | cut -d : -f 1)
BUG=$(echo $PATCH_AND_BUG | cut -d : -f 2)
# Check bug status and skip if it's already landed.
STATUS=$(curl https://bugzilla.mozilla.org/rest/bug/$BUG | python3 -c 'import sys, json; print(json.load(sys.stdin)["bugs"][0]["status"])')
echo "Bug $BUG $STATUS"
if [ "x$STATUS" = "xRESOLVED" ]; then
continue
fi
# Apply the latest patch from phabricator.
PATCH_URL=https://phabricator.services.mozilla.com/${PATCH}?download=true
curl --location "$PATCH_URL" | git apply --index || git reset --hard
git status
git commit --allow-empty -m "Bug $BUG"
done
- name: Build Gecko
run: |
# Disable Opcodes.h check, as we only focus on parsing speed.
export JS_SMOOSH_DISABLE_OPCODE_CHECK=1
# Apply Bug 1640982 fix.
export CARGO_PROFILE_RELEASE_LTO=true
source /var/github-action-runner/.profile
cd jsparagus
cargo run --bin smoosh_tools build --opt
- name: Benchmark Real JS Samples
run: |
source /var/github-action-runner/.profile
cd jsparagus
cargo run --bin smoosh_tools bench --opt
- name: Post Checkout mozilla-central
if: ${{ always() }}
run: |
# Remove checked out repository.
rm -rf mozilla-central

1
third_party/rust/jsparagus/gecko-patches.txt поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
D84388:1654312

Просмотреть файл

@ -4,6 +4,8 @@ import json
import re
import unicodedata
import sys
import itertools
import collections
from contextlib import contextmanager
from ..runtime import (ERROR, ErrorToken, SPECIAL_CASE_TAG)
@ -88,6 +90,28 @@ def indent(writer):
yield None
writer.indent -= 1
def extract_ranges(iterator):
"""Given a sorted iterator of integer, yield the contiguous ranges"""
# Identify contiguous ranges of states.
ranges = collections.defaultdict(list)
# A sorted list of contiguous integers implies that elements are separated
# by 1, as well as their indexes. Thus we can categorize them into buckets
# of contiguous integers using the base, which is the value v from which we
# remove the index i.
for i, v in enumerate(iterator):
ranges[v - i].append(v)
for l in ranges.values():
yield (l[0], l[-1])
def rust_range(riter):
"""Prettify a list of tuple of (min, max) of matched ranges into Rust
syntax."""
def minmax_join(rmin, rmax):
if rmin == rmax:
return str(rmin)
else:
return "{}..={}".format(rmin, rmax)
return " | ".join(minmax_join(rmin, rmax) for rmin, rmax in riter)
class RustActionWriter:
"""Write epsilon state transitions for a given action function."""
@ -200,18 +224,40 @@ class RustActionWriter:
if len(state.epsilon) == 1:
# This is an attempt to avoid huge unending compilations.
_, dest = next(iter(state.epsilon), (None, None))
self.write("// parser.top_state() in [{}]", " | ".join(map(str, first_act.states)))
pattern = rust_range(extract_ranges(first_act.states))
self.write("// parser.top_state() in ({})", pattern)
self.write_epsilon_transition(dest)
else:
self.write("match parser.top_state() {")
with indent(self):
# Consider the branch which has the largest number of
# potential top-states to be most likely, and therefore the
# default branch to go to if all other fail to match.
default_weight = max(len(act.states) for act, dest in state.edges())
default_states = []
default_dest = None
for act, dest in state.edges():
assert first_act.check_same_variable(act)
self.write("{} => {{", " | ".join(map(str, act.states)))
if default_dest is None and default_weight == len(act.states):
# This range has the same weight as the default
# branch. Ignore it and use it as the default
# branch which would be generated at the end.
default_states = act.states
default_dest = dest
continue
pattern = rust_range(extract_ranges(act.states))
self.write("{} => {{", pattern)
with indent(self):
self.write_epsilon_transition(dest)
self.write("}")
self.write("_ => panic!(\"Unexpected state value.\")")
# Generate code for the default branch, which got skipped
# while producing the loop.
self.write("_ => {")
with indent(self):
pattern = rust_range(extract_ranges(default_states))
self.write("// {}", pattern)
self.write_epsilon_transition(default_dest)
self.write("}")
self.write("}")
else:
raise ValueError("Unexpected action type")

Просмотреть файл

@ -3,7 +3,7 @@ use std::env::{self, Args};
use std::fs::{create_dir_all, File};
use std::io::{Read, Write};
use std::path::{Path, PathBuf};
use std::process::{self, Command};
use std::process::{self, exit, Command};
use std::str::FromStr;
static USAGE_STRING: &'static str = r#"Tools for jsparagus + SmooshMonkey development
@ -938,6 +938,9 @@ fn main() {
match result {
Ok(_) => {}
Err(e) => e.dump(),
Err(e) => {
e.dump();
exit(1)
}
}
}