Skip to content

Commit

Permalink
Version 2.18.0-114.0.dev
Browse files Browse the repository at this point in the history
Merge commit 'f6dd05939d273004aa5fc22e235cd72022113f22' into 'dev'
  • Loading branch information
Dart CI committed May 14, 2022
2 parents 00a9662 + f6dd059 commit c23ec46
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 42 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ vars = {
"fixnum_rev": "3bfc2ed1eea7e7acb79ad4f17392f92c816fc5ce",
"glob_rev": "e10eb2407c58427144004458ef85c9bbf7286e56",
"html_rev": "f108bce59d136c584969fd24a5006914796cf213",
"http_io_rev": "2fa188caf7937e313026557713f7feffedd4978b",
"http_io_rev": "405fc79233b4a3d4bb079ebf438bb2caf2f49355",
"http_multi_server_rev": "34bf7f04b61cce561f47f7f275c2cc811534a05a",
"http_parser_rev": "9126ee04e77fd8e4e2e6435b503ee4dd708d7ddc",
"http_rev": "2c9b418f5086f999c150d18172d2eec1f963de7b",
Expand Down
65 changes: 32 additions & 33 deletions pkg/compiler/lib/src/ir/annotations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
// 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.

// @dart = 2.10

import 'package:kernel/ast.dart' as ir;
import 'package:kernel/type_environment.dart' as ir;
import '../common/names.dart';
import 'modular.dart';
import 'modular_migrated.dart';

class IrAnnotationData {
final Map<ir.Class, String> _nativeClassNames = {};
Expand All @@ -25,13 +23,13 @@ class IrAnnotationData {
{};

// Returns the text from the `@Native(<text>)` annotation of [node], if any.
String getNativeClassName(ir.Class node) => _nativeClassNames[node];
String? getNativeClassName(ir.Class node) => _nativeClassNames[node];

// Returns `true` if [node] has a native body, as in `method() native;`.
bool hasNativeBody(ir.Member node) => _nativeMembers.contains(node);

// Returns the text from the `@JSName(<text>)` annotation of [node], if any.
String getNativeMemberName(ir.Member node) => _nativeMemberNames[node];
String? getNativeMemberName(ir.Member node) => _nativeMemberNames[node];

// Returns a list of the text from the `@Creates(<text>)` annotation of
// [node].
Expand All @@ -44,18 +42,18 @@ class IrAnnotationData {
_returnsAnnotations[node] ?? const [];

// Returns the text from the `@JS(<text>)` annotation of [node], if any.
String getJsInteropLibraryName(ir.Library node) =>
String? getJsInteropLibraryName(ir.Library node) =>
_jsInteropLibraryNames[node];

// Returns the text from the `@JS(<text>)` annotation of [node], if any.
String getJsInteropClassName(ir.Class node) => _jsInteropClassNames[node];
String? getJsInteropClassName(ir.Class node) => _jsInteropClassNames[node];

// Returns `true` if [node] is annotated with `@anonymous`.
bool isAnonymousJsInteropClass(ir.Class node) =>
_anonymousJsInteropClasses.contains(node);

// Returns the text from the `@JS(<text>)` annotation of [node], if any.
String getJsInteropMemberName(ir.Member node) => _jsInteropMemberNames[node];
String? getJsInteropMemberName(ir.Member node) => _jsInteropMemberNames[node];

// Returns a list of the `@pragma('dart2js:<suffix>')` annotations on [node].
List<PragmaAnnotationData> getMemberPragmaAnnotationData(ir.Member node) =>
Expand All @@ -76,7 +74,7 @@ class IrAnnotationData {
});
}

void forEachJsInteropMember(void Function(ir.Member, String) f) {
void forEachJsInteropMember(void Function(ir.Member, String?) f) {
_jsInteropLibraryNames.forEach((ir.Library library, _) {
for (ir.Member member in library.members) {
if (member.isExternal) {
Expand All @@ -87,7 +85,7 @@ class IrAnnotationData {
_jsInteropClassNames.forEach((ir.Class cls, _) {
for (ir.Member member in cls.members) {
if (member is ir.Field) continue;
String name = _jsInteropMemberNames[member];
String? name = _jsInteropMemberNames[member];
if (member.isExternal) {
name ??= member.name.text;
}
Expand Down Expand Up @@ -131,15 +129,15 @@ IrAnnotationData processAnnotations(ModularCore modularCore) {
void processMember(ir.Member member) {
ir.StaticTypeContext staticTypeContext = ir.StaticTypeContext(
member, modularCore.constantEvaluator.typeEnvironment);
List<PragmaAnnotationData> pragmaAnnotations;
List<String> createsAnnotations;
List<String> returnsAnnotations;
List<PragmaAnnotationData>? pragmaAnnotations;
List<String>? createsAnnotations;
List<String>? returnsAnnotations;
for (ir.Expression annotation in member.annotations) {
if (annotation is ir.ConstantExpression) {
ir.Constant constant = modularCore.constantEvaluator
.evaluate(staticTypeContext, annotation);

String jsName = _getJsInteropName(constant);
String? jsName = _getJsInteropName(constant);
if (jsName != null) {
data._jsInteropMemberNames[member] = jsName;
}
Expand All @@ -149,28 +147,28 @@ IrAnnotationData processAnnotations(ModularCore modularCore) {
data._nativeMembers.add(member);
}

String nativeName = _getNativeMemberName(constant);
String? nativeName = _getNativeMemberName(constant);
if (nativeName != null) {
data._nativeMemberNames[member] = nativeName;
}

String creates = _getCreatesAnnotation(constant);
String? creates = _getCreatesAnnotation(constant);
if (creates != null) {
if (createsAnnotations == null) {
data._createsAnnotations[member] = createsAnnotations = [];
}
createsAnnotations.add(creates);
}

String returns = _getReturnsAnnotation(constant);
String? returns = _getReturnsAnnotation(constant);
if (returns != null) {
if (returnsAnnotations == null) {
data._returnsAnnotations[member] = returnsAnnotations = [];
}
returnsAnnotations.add(returns);
}

PragmaAnnotationData pragmaAnnotation = _getPragmaAnnotation(constant);
PragmaAnnotationData? pragmaAnnotation = _getPragmaAnnotation(constant);
if (pragmaAnnotation != null) {
if (pragmaAnnotations == null) {
data._memberPragmaAnnotations[member] = pragmaAnnotations = [];
Expand All @@ -190,7 +188,7 @@ IrAnnotationData processAnnotations(ModularCore modularCore) {
ir.Constant constant = modularCore.constantEvaluator
.evaluate(staticTypeContext, annotation);

String jsName = _getJsInteropName(constant);
String? jsName = _getJsInteropName(constant);
if (jsName != null) {
data._jsInteropLibraryNames[library] = jsName;
}
Expand All @@ -202,12 +200,12 @@ IrAnnotationData processAnnotations(ModularCore modularCore) {
ir.Constant constant = modularCore.constantEvaluator
.evaluate(staticTypeContext, annotation);

String nativeClassName = _getNativeClassName(constant);
String? nativeClassName = _getNativeClassName(constant);
if (nativeClassName != null) {
data._nativeClassNames[cls] = nativeClassName;
}

String jsName = _getJsInteropName(constant);
String? jsName = _getJsInteropName(constant);
if (jsName != null) {
data._jsInteropClassNames[cls] = jsName;
}
Expand All @@ -229,15 +227,15 @@ IrAnnotationData processAnnotations(ModularCore modularCore) {
return data;
}

String _getNativeClassName(ir.Constant constant) {
String? _getNativeClassName(ir.Constant constant) {
if (constant is ir.InstanceConstant) {
// TODO(johnniwinther): Add an IrCommonElements for these queries; i.e.
// `commonElements.isNativeAnnotationClass(constant.classNode)`.
if (constant.classNode.name == 'Native' &&
constant.classNode.enclosingLibrary.importUri == Uris.dart__js_helper) {
if (constant.fieldValues.length == 1) {
ir.Constant fieldValue = constant.fieldValues.values.single;
String name;
String? name;
if (fieldValue is ir.StringConstant) {
name = fieldValue.value;
}
Expand All @@ -256,7 +254,7 @@ bool _isNativeMember(ir.Constant constant) {
constant.classNode.enclosingLibrary.importUri == Uris.dart__internal;
}

String _getNativeMemberName(ir.Constant constant) {
String? _getNativeMemberName(ir.Constant constant) {
if (constant is ir.InstanceConstant &&
constant.classNode.name == 'JSName' &&
constant.classNode.enclosingLibrary.importUri == Uris.dart__js_helper) {
Expand All @@ -269,7 +267,7 @@ String _getNativeMemberName(ir.Constant constant) {
return null;
}

String _getCreatesAnnotation(ir.Constant constant) {
String? _getCreatesAnnotation(ir.Constant constant) {
if (constant is ir.InstanceConstant &&
constant.classNode.name == 'Creates' &&
constant.classNode.enclosingLibrary.importUri == Uris.dart__js_helper) {
Expand All @@ -282,7 +280,7 @@ String _getCreatesAnnotation(ir.Constant constant) {
return null;
}

String _getReturnsAnnotation(ir.Constant constant) {
String? _getReturnsAnnotation(ir.Constant constant) {
if (constant is ir.InstanceConstant &&
constant.classNode.name == 'Returns' &&
constant.classNode.enclosingLibrary.importUri == Uris.dart__js_helper) {
Expand All @@ -295,7 +293,7 @@ String _getReturnsAnnotation(ir.Constant constant) {
return null;
}

String _getJsInteropName(ir.Constant constant) {
String? _getJsInteropName(ir.Constant constant) {
if (constant is ir.InstanceConstant &&
constant.classNode.name == 'JS' &&
(constant.classNode.enclosingLibrary.importUri == Uris.package_js ||
Expand Down Expand Up @@ -335,7 +333,7 @@ class PragmaAnnotationData {
String toString() => 'PragmaAnnotationData($name)';
}

PragmaAnnotationData _getPragmaAnnotation(ir.Constant constant) {
PragmaAnnotationData? _getPragmaAnnotation(ir.Constant constant) {
if (constant is! ir.InstanceConstant) return null;
ir.InstanceConstant value = constant;
ir.Class cls = value.classNode;
Expand All @@ -347,8 +345,8 @@ PragmaAnnotationData _getPragmaAnnotation(ir.Constant constant) {
return const PragmaAnnotationData('tryInline');
}
} else if (uri == Uris.dart_core && cls.name == 'pragma') {
ir.Constant nameValue;
ir.Constant optionsValue;
ir.Constant? nameValue;
ir.Constant? optionsValue;
value.fieldValues.forEach((ir.Reference reference, ir.Constant fieldValue) {
ir.Field field = reference.asField;
if (field.name.text == 'name') {
Expand All @@ -357,8 +355,9 @@ PragmaAnnotationData _getPragmaAnnotation(ir.Constant constant) {
optionsValue = fieldValue;
}
});
if (nameValue is! ir.StringConstant) return null;
ir.StringConstant stringValue = nameValue;
final nameValueFinal = nameValue;
if (nameValueFinal is! ir.StringConstant) return null;
ir.StringConstant stringValue = nameValueFinal;
String name = stringValue.value;
String prefix = 'dart2js:';
if (!name.startsWith(prefix)) return null;
Expand All @@ -377,7 +376,7 @@ List<PragmaAnnotationData> computePragmaAnnotationDataFromIr(ir.Member member) {
ir.Constant constant = constantExpression.constant;
assert(constant is! ir.UnevaluatedConstant,
"Unexpected unevaluated constant on $member: $metadata");
PragmaAnnotationData data = _getPragmaAnnotation(constant);
PragmaAnnotationData? data = _getPragmaAnnotation(constant);
if (data != null) {
annotations.add(data);
}
Expand Down
8 changes: 1 addition & 7 deletions pkg/compiler/lib/src/ir/modular.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,10 @@ import '../kernel/element_map.dart';
import '../serialization/serialization.dart';
import '../util/enumset.dart';
import 'annotations.dart';
import 'constants.dart';
import 'impact.dart';
import 'scope.dart';

class ModularCore {
final ir.Component component;
final Dart2jsConstantEvaluator constantEvaluator;

ModularCore(this.component, this.constantEvaluator);
}
export 'modular_migrated.dart';

class ModularMemberData {
final ScopeModel scopeModel;
Expand Down
10 changes: 10 additions & 0 deletions pkg/compiler/lib/src/ir/modular_migrated.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:compiler/src/ir/constants.dart';
import 'package:kernel/ast.dart' as ir;

// TODO(48820): Move this back to modular.dart
class ModularCore {
final ir.Component component;
final Dart2jsConstantEvaluator constantEvaluator;

ModularCore(this.component, this.constantEvaluator);
}
2 changes: 1 addition & 1 deletion tools/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ CHANNEL dev
MAJOR 2
MINOR 18
PATCH 0
PRERELEASE 113
PRERELEASE 114
PRERELEASE_PATCH 0

0 comments on commit c23ec46

Please sign in to comment.