Commit ce9e7738 authored by verwaest's avatar verwaest Committed by Commit bot

Get rid of PropagateScopeInfo, update asm_function in set_asm_module instead.

The last user was propagating asm_module_ to inner function scopes as asm_function_. asm_function_ is already set upon scope creation when the outer scope IsAsmModule(). With default parameter it's possible that inner scopes are created before set_asm_module() is called. To keep current behavior we'll eagerly mark inner scopes as asm_function_ upon set_asm_module().

There's only one special case that used to be marked asm_function_ which is now no longer marked as such: asm functions in block scopes that are 'Finalized'. PropagateScopeInfo used to mark them as asm_function_ as well, whereas the new version would not mark them upon construction of the inner scope.

I presume both above cornercases aren't actually intended valid asm.js use-cases anyway. The second we can now easily identify in the verifier and mark as invalid asm, since we'll have an asm module with non-asm-function inner functions. If we want to disallow the first, we can also not mark them as asm_functions_ (by removing the loop I added in set_asm_module), which will reveal this structure to the validator.

BUG=v8:5209

Review-Url: https://codereview.chromium.org/2270743003
Cr-Commit-Position: refs/heads/master@{#39039}
parent 06451354
...@@ -251,6 +251,16 @@ bool Scope::HasSimpleParameters() { ...@@ -251,6 +251,16 @@ bool Scope::HasSimpleParameters() {
return !scope->is_function_scope() || scope->has_simple_parameters(); return !scope->is_function_scope() || scope->has_simple_parameters();
} }
void DeclarationScope::set_asm_module() {
asm_module_ = true;
// Mark any existing inner function scopes as asm function scopes.
for (Scope* inner = inner_scope_; inner != nullptr; inner = inner->sibling_) {
if (inner->is_function_scope()) {
inner->AsDeclarationScope()->set_asm_function();
}
}
}
bool Scope::IsAsmModule() const { bool Scope::IsAsmModule() const {
return is_function_scope() && AsDeclarationScope()->asm_module(); return is_function_scope() && AsDeclarationScope()->asm_module();
} }
...@@ -329,7 +339,6 @@ Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone, ...@@ -329,7 +339,6 @@ Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone,
if (innermost_scope == nullptr) return script_scope; if (innermost_scope == nullptr) return script_scope;
script_scope->AddInnerScope(current_scope); script_scope->AddInnerScope(current_scope);
script_scope->PropagateScopeInfo();
return innermost_scope; return innermost_scope;
} }
...@@ -878,7 +887,6 @@ Declaration* Scope::CheckLexDeclarationsConflictingWith( ...@@ -878,7 +887,6 @@ Declaration* Scope::CheckLexDeclarationsConflictingWith(
} }
void DeclarationScope::AllocateVariables(ParseInfo* info, AnalyzeMode mode) { void DeclarationScope::AllocateVariables(ParseInfo* info, AnalyzeMode mode) {
PropagateScopeInfo();
ResolveVariablesRecursively(info); ResolveVariablesRecursively(info);
AllocateVariablesRecursively(); AllocateVariablesRecursively();
AllocateScopeInfosRecursively(info->isolate(), mode); AllocateScopeInfosRecursively(info->isolate(), mode);
...@@ -981,9 +989,6 @@ Handle<StringSet> DeclarationScope::CollectNonLocals( ...@@ -981,9 +989,6 @@ Handle<StringSet> DeclarationScope::CollectNonLocals(
void DeclarationScope::AnalyzePartially(DeclarationScope* migrate_to, void DeclarationScope::AnalyzePartially(DeclarationScope* migrate_to,
AstNodeFactory* ast_node_factory) { AstNodeFactory* ast_node_factory) {
// Gather info from inner scopes.
PropagateScopeInfo();
// Try to resolve unresolved variables for this Scope and migrate those which // Try to resolve unresolved variables for this Scope and migrate those which
// cannot be resolved inside. It doesn't make sense to try to resolve them in // cannot be resolved inside. It doesn't make sense to try to resolve them in
// the outer Scopes here, because they are incomplete. // the outer Scopes here, because they are incomplete.
...@@ -1403,16 +1408,6 @@ VariableProxy* Scope::FetchFreeVariables(DeclarationScope* max_outer_scope, ...@@ -1403,16 +1408,6 @@ VariableProxy* Scope::FetchFreeVariables(DeclarationScope* max_outer_scope,
return stack; return stack;
} }
void Scope::PropagateScopeInfo() {
for (Scope* inner = inner_scope_; inner != nullptr; inner = inner->sibling_) {
inner->PropagateScopeInfo();
if (IsAsmModule() && inner->is_function_scope()) {
inner->AsDeclarationScope()->set_asm_function();
}
}
}
bool Scope::MustAllocate(Variable* var) { bool Scope::MustAllocate(Variable* var) {
DCHECK(var->location() != VariableLocation::MODULE); DCHECK(var->location() != VariableLocation::MODULE);
// Give var a read/write use if there is a chance it might be accessed // Give var a read/write use if there is a chance it might be accessed
......
...@@ -531,9 +531,6 @@ class Scope: public ZoneObject { ...@@ -531,9 +531,6 @@ class Scope: public ZoneObject {
ParseInfo* info = nullptr, ParseInfo* info = nullptr,
VariableProxy* stack = nullptr); VariableProxy* stack = nullptr);
// Scope analysis.
void PropagateScopeInfo();
// Predicates. // Predicates.
bool MustAllocate(Variable* var); bool MustAllocate(Variable* var);
bool MustAllocateInContext(Variable* var); bool MustAllocateInContext(Variable* var);
...@@ -624,7 +621,7 @@ class DeclarationScope : public Scope { ...@@ -624,7 +621,7 @@ class DeclarationScope : public Scope {
} }
bool asm_module() const { return asm_module_; } bool asm_module() const { return asm_module_; }
void set_asm_module() { asm_module_ = true; } void set_asm_module();
bool asm_function() const { return asm_function_; } bool asm_function() const { return asm_function_; }
void set_asm_function() { asm_module_ = true; } void set_asm_function() { asm_module_ = true; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment