Commit 5a202cce authored by adamk's avatar adamk Committed by Commit bot

Remove --harmony-modules flag and let embedder decide when modules are used

Modules already have a separate entrypoint into the engine (at the moment,
this is v8::ScriptCompiler::CompileModule, though that will change to
something like ParseModule). This meant that requiring a commandline flag
simply added an extra complexity burden on embedders. By removing the v8
flag, this lets embedders use their own flagging mechanism (such as d8's
"--module", or Blink's RuntimeEnabledFeatures) to control whether
modules are to be used.

Also remove old modules tests that were being skipped (since they test
very old, pre-ES2015 modules syntax).

R=littledan@chromium.org
BUG=v8:1569, chromium:594639
LOG=y

Review URL: https://codereview.chromium.org/1804693002

Cr-Commit-Position: refs/heads/master@{#34764}
parent f3568ca4
......@@ -1853,7 +1853,6 @@ Local<Script> ScriptCompiler::Compile(
MaybeLocal<Script> ScriptCompiler::CompileModule(Local<Context> context,
Source* source,
CompileOptions options) {
CHECK(i::FLAG_harmony_modules);
auto isolate = context->GetIsolate();
TRACE_EVENT_SCOPED_CONTEXT("V8", "Isolate", isolate);
auto maybe = CompileUnboundInternal(isolate, source, options, true);
......
......@@ -2260,7 +2260,6 @@ void Bootstrapper::ExportExperimentalFromRuntime(Isolate* isolate,
#define EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(id) \
void Genesis::InitializeGlobal_##id() {}
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_modules)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy_function)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy_let)
......@@ -2946,7 +2945,6 @@ bool Genesis::InstallNatives(GlobalContextType context_type) {
bool Genesis::InstallExperimentalNatives() {
static const char* harmony_proxies_natives[] = {"native proxy.js", nullptr};
static const char* harmony_modules_natives[] = {nullptr};
static const char* harmony_regexps_natives[] = {"native harmony-regexp.js",
nullptr};
static const char* harmony_iterator_close_natives[] = {nullptr};
......
......@@ -1650,7 +1650,7 @@ Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript(
Zone zone;
ParseInfo parse_info(&zone, script);
CompilationInfo info(&parse_info);
if (FLAG_harmony_modules && is_module) {
if (is_module) {
parse_info.set_module();
} else {
parse_info.set_global();
......
......@@ -1983,8 +1983,6 @@ bool Shell::SetOptions(int argc, char* argv[]) {
v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
bool enable_harmony_modules = false;
// Set up isolated source groups.
options.isolate_sources = new SourceGroup[options.num_isolates];
SourceGroup* current = options.isolate_sources;
......@@ -1997,7 +1995,6 @@ bool Shell::SetOptions(int argc, char* argv[]) {
current->Begin(argv, i + 1);
} else if (strcmp(str, "--module") == 0) {
// Pass on to SourceGroup, which understands this option.
enable_harmony_modules = true;
} else if (strncmp(argv[i], "--", 2) == 0) {
printf("Warning: unknown flag %s.\nTry --help for options\n", argv[i]);
} else if (strcmp(str, "-e") == 0 && i + 1 < argc) {
......@@ -2013,10 +2010,6 @@ bool Shell::SetOptions(int argc, char* argv[]) {
SetFlagsFromString("--nologfile_per_isolate");
}
if (enable_harmony_modules) {
SetFlagsFromString("--harmony-modules");
}
return true;
}
......
......@@ -200,7 +200,6 @@ DEFINE_IMPLICATION(es_staging, harmony_tailcalls)
// Features that are still work in progress (behind individual flags).
#define HARMONY_INPROGRESS(V) \
V(harmony_object_observe, "harmony Object.observe") \
V(harmony_modules, "harmony modules") \
V(harmony_function_sent, "harmony function.sent") \
V(harmony_sharedarraybuffer, "harmony sharedarraybuffer") \
V(harmony_simd, "harmony simd") \
......
......@@ -362,7 +362,6 @@ class ParserBase : public Traits {
Scope* NewScope(Scope* parent, ScopeType scope_type, FunctionKind kind) {
DCHECK(ast_value_factory());
DCHECK(scope_type != MODULE_SCOPE || FLAG_harmony_modules);
Scope* result = new (zone())
Scope(zone(), parent, scope_type, ast_value_factory(), kind);
result->Initialize();
......
......@@ -1902,12 +1902,9 @@ void RunModuleParserSyncTest(const char* context_data[][2],
int always_true_len = 0,
const ParserFlag* always_false_flags = NULL,
int always_false_len = 0) {
bool flag = i::FLAG_harmony_modules;
i::FLAG_harmony_modules = true;
RunParserSyncTest(context_data, statement_data, result, flags, flags_len,
always_true_flags, always_true_len, always_false_flags,
always_false_len, true);
i::FLAG_harmony_modules = flag;
}
......@@ -5579,8 +5576,6 @@ TEST(ComputedPropertyNameShorthandError) {
TEST(BasicImportExportParsing) {
i::FLAG_harmony_modules = true;
// clang-format off
const char* kSources[] = {
"export let x = 0;",
......@@ -5679,8 +5674,6 @@ TEST(BasicImportExportParsing) {
TEST(ImportExportParsingErrors) {
i::FLAG_harmony_modules = true;
// clang-format off
const char* kErrorSources[] = {
"export {",
......@@ -5770,8 +5763,6 @@ TEST(ImportExportParsingErrors) {
TEST(ModuleParsingInternals) {
i::FLAG_harmony_modules = true;
i::Isolate* isolate = CcTest::i_isolate();
i::Factory* factory = isolate->factory();
v8::HandleScope handles(CcTest::isolate());
......
// Copyright 2012 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony-modules
// Test basic module linking and initialization.
"use strict";
module R {
// At this point, only functions and modules are initialized.
assertEquals(undefined, v)
assertEquals(undefined, vv)
assertEquals(undefined, R.v)
assertEquals(undefined, M.v)
assertEquals(undefined, MM.v)
assertEquals(undefined, F.v)
assertEquals(undefined, G.v)
assertThrows(function() { l }, ReferenceError)
assertThrows(function() { ll }, ReferenceError)
assertThrows(function() { R.l }, ReferenceError)
assertThrows(function() { M.l }, ReferenceError)
assertThrows(function() { MM.l }, ReferenceError)
assertThrows(function() { F.l }, ReferenceError)
assertThrows(function() { G.l }, ReferenceError)
assertThrows(function() { c }, ReferenceError)
assertThrows(function() { cc }, ReferenceError)
assertThrows(function() { R.c }, ReferenceError)
assertThrows(function() { M.c }, ReferenceError)
assertThrows(function() { MM.c }, ReferenceError)
assertThrows(function() { F.c }, ReferenceError)
assertThrows(function() { G.c }, ReferenceError)
assertEquals(4, f())
assertEquals(24, ff())
assertEquals(4, R.f())
assertEquals(14, M.f())
assertEquals(34, MM.f())
assertEquals(44, F.f())
assertEquals(14, G.f())
// All properties should already exist on the instance objects, though.
assertTrue("v" in R)
assertTrue("v" in RR)
assertTrue("v" in M)
assertTrue("v" in MM)
assertTrue("v" in F)
assertTrue("v" in G)
assertTrue("l" in R)
assertTrue("l" in RR)
assertTrue("l" in M)
assertTrue("l" in MM)
assertTrue("l" in F)
assertTrue("l" in G)
assertTrue("c" in R)
assertTrue("c" in RR)
assertTrue("c" in M)
assertTrue("c" in MM)
assertTrue("c" in F)
assertTrue("c" in G)
assertTrue("f" in R)
assertTrue("f" in RR)
assertTrue("f" in M)
assertTrue("f" in MM)
assertTrue("f" in F)
assertTrue("f" in G)
assertTrue("M" in R)
assertTrue("M" in RR)
assertTrue("RR" in R)
assertTrue("RR" in RR)
// And aliases should be identical.
assertSame(R, RR)
assertSame(R, R.RR)
assertSame(M, R.M)
assertSame(M, G)
// We can only assign to var.
assertEquals(-1, v = -1)
assertEquals(-2, R.v = -2)
assertEquals(-2, v)
assertEquals(-2, R.v)
assertThrows(function() { l = -1 }, ReferenceError)
assertThrows(function() { R.l = -2 }, ReferenceError)
assertThrows(function() { l }, ReferenceError)
assertThrows(function() { R.l }, ReferenceError)
assertThrows(function() { eval("c = -1") }, TypeError)
assertThrows(function() { R.c = -2 }, TypeError)
// Initialize first bunch of variables.
export var v = 1
export let l = 2
export const c = 3
export function f() { return 4 }
assertEquals(1, v)
assertEquals(1, R.v)
assertEquals(2, l)
assertEquals(2, R.l)
assertEquals(3, c)
assertEquals(3, R.c)
assertEquals(-3, v = -3)
assertEquals(-4, R.v = -4)
assertEquals(-3, l = -3)
assertEquals(-4, R.l = -4)
assertThrows(function() { eval("c = -3") }, TypeError)
assertThrows(function() { R.c = -4 }, TypeError)
assertEquals(-4, v)
assertEquals(-4, R.v)
assertEquals(-4, l)
assertEquals(-4, R.l)
assertEquals(3, c)
assertEquals(3, R.c)
// Initialize nested module.
export module M {
export var v = 11
export let l = 12
export const c = 13
export function f() { return 14 }
}
assertEquals(11, M.v)
assertEquals(11, G.v)
assertEquals(12, M.l)
assertEquals(12, G.l)
assertEquals(13, M.c)
assertEquals(13, G.c)
// Initialize non-exported variables.
var vv = 21
let ll = 22
const cc = 23
function ff() { return 24 }
assertEquals(21, vv)
assertEquals(22, ll)
assertEquals(23, cc)
// Initialize non-exported module.
module MM {
export var v = 31
export let l = 32
export const c = 33
export function f() { return 34 }
}
assertEquals(31, MM.v)
assertEquals(32, MM.l)
assertEquals(33, MM.c)
// Recursive self reference.
export module RR = R
}
// Initialize sibling module that was forward-used.
module F {
assertEquals(undefined, v)
assertEquals(undefined, F.v)
assertThrows(function() { l }, ReferenceError)
assertThrows(function() { F.l }, ReferenceError)
assertThrows(function() { c }, ReferenceError)
assertThrows(function() { F.c }, ReferenceError)
export var v = 41
export let l = 42
export const c = 43
export function f() { return 44 }
assertEquals(41, v)
assertEquals(41, F.v)
assertEquals(42, l)
assertEquals(42, F.l)
assertEquals(43, c)
assertEquals(43, F.c)
}
// Define recursive module alias.
module G = R.M
// Second test with side effects and more module nesting.
let log = "";
export let x = (log += "1");
export module B = A.B
export module A {
export let x = (log += "2");
let y = (log += "3");
export function f() { log += "5" };
export module B {
module BB = B;
export BB, x;
let x = (log += "4");
f();
let y = (log += "6");
}
export let z = (log += "7");
export module C {
export let z = (log += "8");
export module D = B
export module C = A.C
}
module D {}
}
export module M1 {
export module A2 = M2;
export let x = (log += "9");
}
export module M2 {
export module A1 = M1;
export let x = (log += "0");
}
assertEquals("object", typeof A);
assertTrue('x' in A);
assertFalse('y' in A);
assertTrue('f' in A);
assertTrue('B' in A);
assertTrue('z' in A);
assertTrue('C' in A);
assertFalse('D' in A);
assertEquals("object", typeof B);
assertTrue('BB' in B);
assertTrue('x' in B);
assertFalse('y' in B);
assertEquals("object", typeof A.B);
assertTrue('BB' in A.B);
assertTrue('x' in A.B);
assertFalse('y' in A.B);
assertEquals("object", typeof A.B.BB);
assertTrue('BB' in A.B.BB);
assertTrue('x' in A.B.BB);
assertFalse('y' in A.B.BB);
assertEquals("object", typeof A.C);
assertTrue('z' in A.C);
assertTrue('D' in A.C);
assertTrue('C' in A.C);
assertEquals("object", typeof M1);
assertEquals("object", typeof M2);
assertTrue('A2' in M1);
assertTrue('A1' in M2);
assertEquals("object", typeof M1.A2);
assertEquals("object", typeof M2.A1);
assertTrue('A1' in M1.A2);
assertTrue('A2' in M2.A1);
assertEquals("object", typeof M1.A2.A1);
assertEquals("object", typeof M2.A1.A2);
assertSame(B, A.B);
assertSame(B, B.BB);
assertSame(B, A.C.D);
assertSame(A.C, A.C.C);
assertFalse(A.D === A.C.D);
assertSame(M1, M2.A1);
assertSame(M2, M1.A2);
assertSame(M1, M1.A2.A1);
assertSame(M2, M2.A1.A2);
assertEquals("1234567890", log);
......@@ -25,8 +25,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony-modules
// Check that import/export declarations are rejected in eval or local scope.
assertThrows("export let x;", SyntaxError);
assertThrows("import x from 'http://url';", SyntaxError);
......
// Copyright 2012 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony-modules
// Test that potential recompilation of the global scope does not screw up.
"use strict";
var N = 1e5; // Number of loop iterations that trigger optimization.
module A {
export var x = 1
export function f() { return x }
}
var f = A.f
assertEquals(1, A.x)
assertEquals(1, A.f())
assertEquals(1, f())
A.x = 2
assertEquals(2, A.x)
assertEquals(2, A.f())
assertEquals(2, f())
for (var i = 0; i < N; i++) {
if (i > N) print("impossible");
}
assertEquals(2, A.x)
assertEquals(2, A.f())
assertEquals(2, f())
// Same test with loop inside a module.
module B {
module A {
export var x = 1
export function f() { return x }
}
var f = A.f
assertEquals(1, A.x)
assertEquals(1, A.f())
assertEquals(1, f())
A.x = 2
assertEquals(2, A.x)
assertEquals(2, A.f())
assertEquals(2, f())
for (var i = 0; i < N; i++) {
if (i > N) print("impossible");
}
assertEquals(2, A.x)
assertEquals(2, A.f())
assertEquals(2, f())
}
// Copyright 2012 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony-modules
// Test basic module interface inference.
"use strict";
print("begin.")
export let x = print("0")
export module B = A.B
export module A {
export let x = print("1")
export let f = function() { return B.x }
export module B {
module BB = B
export BB, x
let x = print("2")
var y = print("3")
let Ax = A.x
try { A.y } catch (e) {} // throws
let Az = A.z // undefined
let Az2 = z // undefined
A.g() // hoisted
g() // hoisted
let ABx = A.B.x
let ABy = A.B.y
let Bx = B.x
let By = B.y
let BBx = BB.x
let BBy = BB.y
let Af = A.f
function f(x,y) { return x }
}
export let y = print("4")
export var z = print("4.1")
export function g() {}
let Ax = A.x
let Bx = B.x
let ABx = A.B.x
module C {
export let z = print("5")
export module D = B
// TODO(rossberg): turn these into proper negative test cases once we have
// suitable error messages.
// import C.z // multiple declarations
import x from B
}
module D {
// TODO(rossberg): Handle import *.
// import A.* // invalid forward import
}
module M {}
// TODO(rossberg): Handle import *.
// import M.* // invalid forward import
let Cz = C.z
let CDx = C.D.x
}
export module Imports {
module A1 {
export module A2 {}
}
module B {
// TODO(rossberg): Handle import *.
// import A1.*
// import A2.* // unbound variable A2
}
}
export module E {
export let xx = x
export y, B
let Bx = B.x
// TODO(rossberg): Handle import *.
// import A.*
module B = A.B
let y = A.y
}
export module M1 {
export module A2 = M2
}
export module M2 {
export module A1 = M1
}
// TODO(rossberg): turn these into proper negative test cases once we have
// suitable error messages.
// module W1 = W2.W
// module W2 = { export module W = W3 }
// module W3 = W1 // cyclic module definition
// module W1 = W2.W3
// module W2 = {
// export module W3 = W4
// export module W4 = W1
// } // cyclic module definition
// TODO(rossberg): Handle import *.
//module M3B = M3.B
//export module M3 {
// export module B { export let x = "" }
// module C1 = { import M3.* }
// module C2 = { import M3.B.* }
// module C3 = { import M3B.* }
// module C4 = { export x import B.* }
//// TODO(rossberg): turn these into proper negative test cases once we have
//// suitable error messages.
//// export module C5 = { import C5.* } // invalid forward import
//// export module C6 = { import M3.C6.* } // invalid forward import
//}
export module External at "external.js"
export module External1 = External
//export module ExternalA = External.A
export module InnerExternal {
export module E at "external.js"
}
export module External2 = InnerExternal.E
//export let xxx = InnerExternal.E.A.x
print("end.")
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-modules --expose-debug-as=debug
(function () { // Scope for utility functions.
escaping_function = function(object) {
// Argument must not be null or undefined.
var string = Object.prototype.toString.call(object);
// String has format [object <ClassName>].
return string.substring(8, string.length - 1);
}
})();
module B {
var stuff = 3
}
var __v_0 = {};
var __v_4 = debug.MakeMirror(__v_0);
print(__v_4.referencedBy().length); // core dump here if not fixed.
......@@ -83,12 +83,6 @@
'regress/regress-2185-2': [PASS, NO_VARIANTS],
'regress/regress-2612': [PASS, NO_VARIANTS],
# Modules are busted
'harmony/module-linking': [SKIP],
'harmony/module-recompile': [SKIP],
'harmony/module-resolution': [SKIP],
'harmony/regress/regress-343928': [SKIP],
# Issue 3660: Replacing activated TurboFan frames by unoptimized code does
# not work, but we expect it to not crash.
'debug-step-turbofan': [PASS, FAIL],
......
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