Skip to content
This repository has been archived by the owner on Feb 25, 2025. It is now read-only.

Commit

Permalink
Version 2.14.0-367.0.dev
Browse files Browse the repository at this point in the history
Merge commit 'f5a98e7676030e96f55263ff987c0acb39f5256f' into 'dev'
  • Loading branch information
Dart CI committed Jul 30, 2021
2 parents 6e821af + f5a98e7 commit a325ab0
Show file tree
Hide file tree
Showing 164 changed files with 6,088 additions and 7,451 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,16 @@ Updated the Linter to `1.8.0`, which includes changes that
[#46545]: https://github.com/dart-lang/sdk/issues/46545
[1]: https://dart.dev/faq#q-what-browsers-do-you-support-as-javascript-compilation-targets

#### Dart Dev Compiler (DDC)

- **Breaking Change** [#44154][]: Subtyping relations of `package:js` classes
have been changed to be more correct and consistent with Dart2JS.
Like `anonymous` classes, non-`anonymous` classes will no longer check the
underlying type in DDC. The internal type representation of these objects have
changed as well, which will affect the `toString` value of these types.

[#44154]: https://github.com/dart-lang/sdk/issues/44154

## 2.13.4 - 2021-06-28

This is a patch release that fixes:
Expand Down
4 changes: 0 additions & 4 deletions pkg/compiler/lib/src/compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ abstract class Compiler {
ImpactCacheDeleter get impactCacheDeleter => _impactCacheDeleter;

final Environment environment;
// TODO(sigmund): delete once we migrate the rest of the compiler to use
// `environment` directly.
@deprecated
fromEnvironment(String name) => environment.valueOf(name);

Entity get currentElement => _reporter.currentElement;

Expand Down
2 changes: 2 additions & 0 deletions pkg/compiler/test/codegen/data_2/unused_empty_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// ignore_for_file: unused_local_variable

@pragma('dart2js:noInline')
// No code to construct unused map.
/*member: foo1:function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void main() {

var mainOutputUnit = closedWorld.outputUnitData.mainOutputUnit;
var backendStrategy = compiler.backendStrategy;
// ignore: deprecated_member_use_from_same_package
var classes = backendStrategy.emitterTask.neededClasses;
var inputElement = classes.where((e) => e.name == 'InputElement').single;
dynamic lib1 = lookupLibrary("memory:lib1.dart");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ abstract class DiagnosticReporterWrapper extends DiagnosticReporter {
@override
void reportInfoMessage(Spannable node, MessageKind errorCode,
[Map<String, String> arguments = const {}]) {
// ignore: deprecated_member_use_from_same_package
reporter.reportInfoMessage(node, errorCode, arguments);
}

Expand Down
93 changes: 51 additions & 42 deletions pkg/compiler/test/end_to_end/library_env_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,48 +85,57 @@ class CustomCompiler extends CompilerImpl {
}

runTest() async {
var compiler = new CustomCompiler([], {});

await compiler.setupSdk();

// Core libraries are always present.
Expect.equals("true", compiler.fromEnvironment("dart.library.collection"));
// Non-existing entries in the environment return 'null'.
Expect.isNull(compiler.fromEnvironment("not in env"));
// Check for client libraries (default if there are no flags to the compiler).
Expect.equals("true", compiler.fromEnvironment("dart.library.mock.client"));
Expect.equals("true", compiler.fromEnvironment("dart.library.html"));
// Check for shared libraries..
Expect.equals("true", compiler.fromEnvironment("dart.library.mock.shared"));
// Check server libraries are not present.
Expect.equals(null, compiler.fromEnvironment("dart.library.mock.server"));
Expect.equals(null, compiler.fromEnvironment("dart.library.io"));

compiler = new CustomCompiler([Flags.serverMode], {});

await compiler.setupSdk();

// Core libraries are always present.
Expect.equals("true", compiler.fromEnvironment("dart.library.collection"));
// Non-existing entries in the environment return 'null'.
Expect.isNull(compiler.fromEnvironment("not in env"));
// Check client libraries are not present.
Expect.equals(null, compiler.fromEnvironment("dart.library.mock.client"));
Expect.equals(null, compiler.fromEnvironment("dart.library.html"));
// Check for shared libraries..
Expect.equals("true", compiler.fromEnvironment("dart.library.mock.shared"));
// Check for server libraries.
Expect.equals("true", compiler.fromEnvironment("dart.library.mock.server"));
Expect.equals("true", compiler.fromEnvironment("dart.library.io"));

// Check that user-defined env-variables win.
compiler = new CustomCompiler([],
{'dart.library.collection': "false", 'dart.library.mock.client': "foo"});

await compiler.setupSdk();

Expect.equals("false", compiler.fromEnvironment("dart.library.collection"));
Expect.equals("foo", compiler.fromEnvironment("dart.library.mock.client"));
{
final compiler = new CustomCompiler([], {});

await compiler.setupSdk();
final lookup = compiler.environment.valueOf;

// Core libraries are always present.
Expect.equals("true", lookup("dart.library.collection"));
// Non-existing entries in the environment return 'null'.
Expect.isNull(lookup("not in env"));
// Check for client libraries (default if there are no flags to the compiler).
Expect.equals("true", lookup("dart.library.mock.client"));
Expect.equals("true", lookup("dart.library.html"));
// Check for shared libraries..
Expect.equals("true", lookup("dart.library.mock.shared"));
// Check server libraries are not present.
Expect.equals(null, lookup("dart.library.mock.server"));
Expect.equals(null, lookup("dart.library.io"));
}
{
final compiler = new CustomCompiler([Flags.serverMode], {});

await compiler.setupSdk();
final lookup = compiler.environment.valueOf;

// Core libraries are always present.
Expect.equals("true", lookup("dart.library.collection"));
// Non-existing entries in the environment return 'null'.
Expect.isNull(lookup("not in env"));
// Check client libraries are not present.
Expect.equals(null, lookup("dart.library.mock.client"));
Expect.equals(null, lookup("dart.library.html"));
// Check for shared libraries..
Expect.equals("true", lookup("dart.library.mock.shared"));
// Check for server libraries.
Expect.equals("true", lookup("dart.library.mock.server"));
Expect.equals("true", lookup("dart.library.io"));
}
{
// Check that user-defined env-variables win.
final compiler = new CustomCompiler([], {
'dart.library.collection': "false",
'dart.library.mock.client': "foo"
});

await compiler.setupSdk();
final lookup = compiler.environment.valueOf;

Expect.equals("false", lookup("dart.library.collection"));
Expect.equals("foo", lookup("dart.library.mock.client"));
}
}

main() {
Expand Down
8 changes: 6 additions & 2 deletions pkg/dev_compiler/lib/src/kernel/command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -748,13 +748,17 @@ ModuleSymbols _emitSymbols(ProgramCompiler compiler, String moduleName,
for (var e in compiler.classIdentifiers.entries)
e.key: identifierNames[e.value],
};
var procedureJsNames = <Procedure, String>{
for (var e in compiler.procedureIdentifiers.entries)
e.key: identifierNames[e.value],
};
var variableJsNames = <VariableDeclaration, String>{
for (var e in compiler.variableIdentifiers.entries)
e.key: identifierNames[e.value],
};

return ModuleSymbolsCollector(
moduleName, classJsNames, compiler.memberNames, variableJsNames)
return ModuleSymbolsCollector(moduleName, classJsNames, compiler.memberNames,
procedureJsNames, variableJsNames)
.collectSymbolInfo(component);
}

Expand Down
71 changes: 35 additions & 36 deletions pkg/dev_compiler/lib/src/kernel/compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
/// module.
final memberNames = <Member, String>{};

/// Maps each `Procedure` node compiled in the module to the `Identifier`s
/// used to name the class in JavaScript.
///
/// This mapping is used when generating the symbol information for the
/// module.
final procedureIdentifiers = <Procedure, js_ast.Identifier>{};

/// Maps each `VariableDeclaration` node compiled in the module to the name
/// used for the variable in JavaScript.
///
Expand Down Expand Up @@ -1670,7 +1677,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
ctorFields = ctor.initializers
.map((c) => c is FieldInitializer ? c.field : null)
.toSet()
..remove(null);
..remove(null);
}

var body = <js_ast.Statement>[];
Expand Down Expand Up @@ -2368,8 +2375,9 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
Class memberClass}) {
// Static members skip the rename steps and may require JS interop renames.
if (isStatic) {
// TODO(nshahan) Record the name for this member in memberNames.
return _emitStaticMemberName(name, member);
var memberName = _emitStaticMemberName(name, member);
memberNames[member] = memberName.valueWithoutQuotes;
return memberName;
}

// We allow some (illegal in Dart) member names to be used in our private
Expand All @@ -2379,6 +2387,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
var runtimeName = _jsExportName(member);
if (runtimeName != null) {
var parts = runtimeName.split('.');
// TODO(nshahan) Record the name for this member in memberNames.
if (parts.length < 2) return propertyName(runtimeName);

js_ast.Expression result = _emitIdentifier(parts[0]);
Expand Down Expand Up @@ -2652,8 +2661,9 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
_currentUri = node.fileUri;

var name = node.name.text;
memberNames[node] = name;
var result = js_ast.Method(
propertyName(name), _emitFunction(node.function, node.name.text),
propertyName(name), _emitFunction(node.function, name),
isGetter: node.isGetter, isSetter: node.isSetter)
..sourceInformation = _nodeEnd(node.fileEndOffset);

Expand All @@ -2678,8 +2688,10 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>

var nameExpr = _emitTopLevelName(p);
var jsName = _safeFunctionNameForSafari(p.name.text, fn);
body.add(js.statement('# = #',
[nameExpr, js_ast.NamedFunction(_emitTemporaryId(jsName), fn)]));
var functionName = _emitTemporaryId(jsName);
procedureIdentifiers[p] = functionName;
body.add(js.statement(
'# = #', [nameExpr, js_ast.NamedFunction(functionName, fn)]));

_currentUri = savedUri;
_staticTypeContext.leaveMember(p);
Expand Down Expand Up @@ -2872,27 +2884,15 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
js_ast.Expression typeRep;

// Type parameters don't matter as JS interop types cannot be reified.
// We have to use lazy JS types because until we have proper module
// loading for JS libraries bundled with Dart libraries, we will sometimes
// need to load Dart libraries before the corresponding JS libraries are
// actually loaded.
// Given a JS type such as:
// @JS('google.maps.Location')
// class Location { ... }
// We can't emit a reference to MyType because the JS library that defines
// it may be loaded after our code. So for now, we use a special lazy type
// object to represent MyType.
// Anonymous JS types do not have a corresponding concrete JS type so we
// have to use a helper to define them.
if (isJSAnonymousType(c)) {
typeRep = runtimeCall(
'anonymousJSType(#)', [js.escapedString(getLocalClassName(c))]);
} else {
var jsName = _emitJsNameWithoutGlobal(c);
if (jsName != null) {
typeRep = runtimeCall('lazyJSType(() => #, #)',
[_emitJSInteropForGlobal(jsName), js.escapedString(jsName)]);
}
// package:js types fall under either named or anonymous types. Named types
// are used to correspond to JS types that exist, but we do not use the
// underlying type for type checks, so they operate virtually the same as
// anonymous types. We represent package:js types with a corresponding type
// object.
var jsName = isJSAnonymousType(c) ?
getLocalClassName(c) : _emitJsNameWithoutGlobal(c);
if (jsName != null) {
typeRep = runtimeCall('packageJSType(#)', [js.escapedString(jsName)]);
}

if (typeRep != null) {
Expand Down Expand Up @@ -3605,7 +3605,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
}

for (var p in f.positionalParameters) {
var jsParam = _emitVariableDef(p);
var jsParam = _emitVariableRef(p);
if (_checkParameters) {
initParameter(p, jsParam);
}
Expand Down Expand Up @@ -4510,21 +4510,19 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
var name = v.name;
if (name == null || name.startsWith('#')) {
name = name == null ? 't${_tempVariables.length}' : name.substring(1);
// TODO(nshahan) Record the Identifier for this variable in
// variableIdentifiers.
return _tempVariables.putIfAbsent(v, () => _emitTemporaryId(name));
}
var identifier = _emitIdentifier(name);
variableIdentifiers[v] = identifier;
return identifier;
return _emitIdentifier(name);
}

/// Emits the declaration of a variable.
///
/// This is similar to [_emitVariableRef] but it also attaches source
/// location information, so hover will work as expected.
js_ast.Identifier _emitVariableDef(VariableDeclaration v) {
return _emitVariableRef(v)..sourceInformation = _nodeStart(v);
var identifier = _emitVariableRef(v)..sourceInformation = _nodeStart(v);
variableIdentifiers[v] = identifier;
return identifier;
}

js_ast.Statement _initLetVariables() {
Expand Down Expand Up @@ -6403,8 +6401,9 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
Library library, String className, Member member,
[js_ast.TemporaryId id]) {
var name = '$className.${member.name.text}';
// Names used in the symbols for the public fields
// memberNames[member] = 'Symbol($name)';
// Wrap the name as a symbol here so it matches what you would find at
// runtime when you get all properties and symbols from an instance.
memberNames[member] = 'Symbol($name)';
return emitPrivateNameSymbol(library, name, id);
}

Expand Down
29 changes: 25 additions & 4 deletions pkg/dev_compiler/lib/src/kernel/module_symbols_collector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,23 @@ class ModuleSymbolsCollector extends RecursiveVisitor {
/// The first scope added to the stack should always be the library scope. The
/// last element in the list represents the current scope.
final _scopes = <ScopeSymbol>[];

final ModuleSymbols _moduleSymbols;
final Map<Class, String> _classJsNames;
final Map<Member, String> _memberJsNames;
final Map<Procedure, String> _procedureJsNames;
final Map<VariableDeclaration, String> _variableJsNames;

ModuleSymbolsCollector(String moduleName, this._classJsNames,
this._memberJsNames, this._variableJsNames)
this._memberJsNames, this._procedureJsNames, this._variableJsNames)
: _moduleSymbols = ModuleSymbols(
version: ModuleSymbols.current.version,
moduleName: moduleName,
libraries: <LibrarySymbol>[],
scripts: <Script>[],
classes: <ClassSymbol>[],
// TODO(nshahan) functionTypes
// TODO(nshahan) functions
functions: <FunctionSymbol>[],
// TODO(nshahan) scopes
variables: <VariableSymbol>[]);

Expand Down Expand Up @@ -142,8 +144,27 @@ class ModuleSymbolsCollector extends RecursiveVisitor {
// Legacy libraries contain procedures with no bodies for all Object methods
// in every class. We can ignore these unless they actually contain a body.
if (node.function.body == null) return;
// TODO(nshahan) implement visitProcedure
super.visitProcedure(node);
var functionSymbol = FunctionSymbol(
name: node.name.text,
// TODO(nshahan) typeId - probably should canonicalize but keep original
// type argument names.
isStatic: node.isStatic,
isConst: node.isConst,
localId: _memberJsNames[node] ?? _procedureJsNames[node],
scopeId: _scopes.last.id,
variableIds: <String>[],
scopeIds: <String>[],
location: SourceLocation(
scriptId: _scriptId(node.location.file),
tokenPos: node.fileOffset,
endTokenPos: node.fileEndOffset));

_scopes.add(functionSymbol);
node.visitChildren(this);
_scopes
..removeLast()
..last.scopeIds.add(functionSymbol.id);
_moduleSymbols.functions.add(functionSymbol);
}

@override
Expand Down
Loading

0 comments on commit a325ab0

Please sign in to comment.