Skip to content

Commit be064bd

Browse files
lrhnsigmundch
authored andcommitted
[CP][beta] Remove left-over patch declarations for List constructor.
This CL replaces https://dart-review.googlesource.com/c/sdk/+/296900 The `List` constructor is removed in Dart 3.0. Some of the `@patch` implementations were not removed. This is *high priority*. It seems the left-over `@patch factory List` constructor did not cause any errors, instead it *added* a constructor to `List` that can be used in web compiled code. Even if `List` doesn't have such a constructor in the SDK code proper. The VM and analyzer will say the invocation is an error, but dart2js happily compiles it and runs. (It used to be that patches couldn't add public members, that security seems to have been removed.) Also removes code which tries to detect "the unnamed List constructor", which is no longer a thing, and a number of invocations of the constructor, where it's not clear that the test is aware that the constructor no longer exists, and is not marked as `@dart=2.x` with x < 12. Tested: ci Cherry-Pick: https://dart-review.googlesource.com/c/sdk/+/297100 Change-Id: I2340ab7f68be50fe22f9940bcaaf45c3ff6dc5ca Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/297461 Reviewed-by: Sigmund Cherem <sigmund@google.com> Reviewed-by: Kevin Chisholm <kevinjchisholm@google.com> Reviewed-by: Nate Bosch <nbosch@google.com>
1 parent 458a723 commit be064bd

31 files changed

+68
-261
lines changed

pkg/compiler/lib/src/common/elements.dart

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,14 +1095,6 @@ class KCommonElements extends CommonElements {
10951095
class JCommonElements extends CommonElements {
10961096
JCommonElements(super.dartTypes, super.env);
10971097

1098-
/// Returns `true` if [element] is the unnamed constructor of `List`.
1099-
///
1100-
/// This will not resolve the constructor if it hasn't been seen yet during
1101-
/// compilation.
1102-
bool isUnnamedListConstructor(ConstructorEntity element) =>
1103-
(element.name == '' && element.enclosingClass == listClass) ||
1104-
(element.name == 'list' && element.enclosingClass == jsArrayClass);
1105-
11061098
/// Returns `true` if [element] is the named constructor of `List`,
11071099
/// e.g. `List.of`.
11081100
///

pkg/compiler/lib/src/inferrer/builder.dart

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,24 +1380,6 @@ class KernelTypeGraphBuilder extends ir.Visitor<TypeInformation?>
13801380

13811381
var commonElements = _elementMap.commonElements;
13821382

1383-
if (commonElements.isUnnamedListConstructor(constructor)) {
1384-
// We have `new List(...)`.
1385-
if (arguments.positional.isEmpty && arguments.named.isEmpty) {
1386-
// We have `new List()`.
1387-
return _inferrer.concreteTypes.putIfAbsent(
1388-
node,
1389-
() => _types.allocateList(_types.growableListType, node,
1390-
_analyzedMember, _types.nonNullEmpty(), 0));
1391-
} else {
1392-
// We have `new List(len)`.
1393-
final length = _findLength(arguments);
1394-
return _inferrer.concreteTypes.putIfAbsent(
1395-
node,
1396-
() => _types.allocateList(_types.fixedListType, node,
1397-
_analyzedMember, _types.nullType, length));
1398-
}
1399-
}
1400-
14011383
if (commonElements.isNamedListConstructor('filled', constructor)) {
14021384
// We have something like `List.filled(len, fill)`.
14031385
final length = _findLength(arguments);

pkg/compiler/lib/src/inferrer_experimental/builder.dart

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,24 +1385,6 @@ class KernelTypeGraphBuilder extends ir.Visitor<TypeInformation?>
13851385

13861386
var commonElements = _elementMap.commonElements;
13871387

1388-
if (commonElements.isUnnamedListConstructor(constructor)) {
1389-
// We have `new List(...)`.
1390-
if (arguments.positional.isEmpty && arguments.named.isEmpty) {
1391-
// We have `new List()`.
1392-
return _inferrer.concreteTypes.putIfAbsent(
1393-
node,
1394-
() => _types.allocateList(_types.growableListType, node,
1395-
_analyzedMember, _types.nonNullEmpty(), 0));
1396-
} else {
1397-
// We have `new List(len)`.
1398-
final length = _findLength(arguments);
1399-
return _inferrer.concreteTypes.putIfAbsent(
1400-
node,
1401-
() => _types.allocateList(_types.fixedListType, node,
1402-
_analyzedMember, _types.nullType, length));
1403-
}
1404-
}
1405-
14061388
if (commonElements.isNamedListConstructor('filled', constructor)) {
14071389
// We have something like `List.filled(len, fill)`.
14081390
final length = _findLength(arguments);

pkg/compiler/lib/src/ssa/builder.dart

Lines changed: 0 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -4185,27 +4185,6 @@ class KernelSsaGraphBuilder extends ir.Visitor<void> with ir.VisitorVoidMixin {
41854185
AbstractValue typeMask,
41864186
List<HInstruction> arguments,
41874187
SourceInformation? sourceInformation) {
4188-
// Recognize `List()` and `List(n)`.
4189-
if (_commonElements.isUnnamedListConstructor(function)) {
4190-
if (invocation.arguments.named.isEmpty) {
4191-
int argumentCount = invocation.arguments.positional.length;
4192-
if (argumentCount == 0) {
4193-
// `List()` takes no arguments, `JSArray.list()` takes a sentinel.
4194-
assert(arguments.length == 0 || arguments.length == 1,
4195-
'\narguments: $arguments\n');
4196-
_handleInvokeLegacyGrowableListFactoryConstructor(
4197-
invocation, function, typeMask, arguments, sourceInformation);
4198-
return;
4199-
}
4200-
if (argumentCount == 1) {
4201-
assert(arguments.length == 1);
4202-
_handleInvokeLegacyFixedListFactoryConstructor(
4203-
invocation, function, typeMask, arguments, sourceInformation);
4204-
return;
4205-
}
4206-
}
4207-
}
4208-
42094188
// Recognize `JSArray<E>.typed(allocation)`.
42104189
if (function == _commonElements.jsArrayTypedConstructor) {
42114190
if (invocation.arguments.named.isEmpty) {
@@ -4329,98 +4308,6 @@ class KernelSsaGraphBuilder extends ir.Visitor<void> with ir.VisitorVoidMixin {
43294308
stack.add(_setListRuntimeTypeInfoIfNeeded(pop(), type, sourceInformation));
43304309
}
43314310

4332-
/// Handle the legacy `List<T>()` constructor.
4333-
void _handleInvokeLegacyGrowableListFactoryConstructor(
4334-
ir.StaticInvocation invocation,
4335-
ConstructorEntity function,
4336-
AbstractValue typeMask,
4337-
List<HInstruction> arguments,
4338-
SourceInformation? sourceInformation) {
4339-
// `List<T>()` is essentially the same as `<T>[]`.
4340-
push(_buildLiteralList([]));
4341-
HInstruction allocation = pop();
4342-
var inferredType = globalInferenceResults.typeOfNewList(invocation);
4343-
if (inferredType != null) {
4344-
allocation.instructionType = inferredType;
4345-
}
4346-
InterfaceType type = _elementMap.createInterfaceType(
4347-
invocation.target.enclosingClass!, invocation.arguments.types);
4348-
stack.add(
4349-
_setListRuntimeTypeInfoIfNeeded(allocation, type, sourceInformation));
4350-
}
4351-
4352-
/// Handle the `JSArray<T>.list(length)` and legacy `List<T>(length)`
4353-
/// constructors.
4354-
void _handleInvokeLegacyFixedListFactoryConstructor(
4355-
ir.StaticInvocation invocation,
4356-
ConstructorEntity function,
4357-
AbstractValue typeMask,
4358-
List<HInstruction> arguments,
4359-
SourceInformation? sourceInformation) {
4360-
assert(
4361-
// Arguments may include the type.
4362-
arguments.length == 1 || arguments.length == 2,
4363-
failedAt(
4364-
function,
4365-
"Unexpected arguments. "
4366-
"Expected 1-2 argument, actual: $arguments."));
4367-
HInstruction lengthInput = arguments.first;
4368-
if (lengthInput.isNumber(_abstractValueDomain).isPotentiallyFalse) {
4369-
HPrimitiveCheck conversion = HPrimitiveCheck(
4370-
_commonElements.numType,
4371-
HPrimitiveCheck.ARGUMENT_TYPE_CHECK,
4372-
_abstractValueDomain.numType,
4373-
lengthInput,
4374-
sourceInformation);
4375-
add(conversion);
4376-
lengthInput = conversion;
4377-
}
4378-
js.Template code = js.js.parseForeignJS('new Array(#)');
4379-
var behavior = NativeBehavior();
4380-
4381-
DartType expectedType = _getStaticType(invocation).type;
4382-
behavior.typesInstantiated.add(expectedType);
4383-
behavior.typesReturned.add(expectedType);
4384-
4385-
// The allocation can throw only if the given length is a double or
4386-
// outside the unsigned 32 bit range.
4387-
// TODO(sra): Array allocation should be an instruction so that canThrow
4388-
// can depend on a length type discovered in optimization.
4389-
bool canThrow = true;
4390-
if (lengthInput.isUInt32(_abstractValueDomain).isDefinitelyTrue) {
4391-
canThrow = false;
4392-
}
4393-
4394-
var resultType = globalInferenceResults.typeOfNewList(invocation) ??
4395-
_abstractValueDomain.fixedListType;
4396-
4397-
HForeignCode foreign = HForeignCode(code, resultType, [lengthInput],
4398-
nativeBehavior: behavior,
4399-
throwBehavior:
4400-
canThrow ? NativeThrowBehavior.MAY : NativeThrowBehavior.NEVER)
4401-
..sourceInformation = sourceInformation;
4402-
push(foreign);
4403-
js.Template fixedLengthMarker =
4404-
js.js.parseForeignJS(r'#.fixed$length = Array');
4405-
// We set the instruction as [canThrow] to avoid it being dead code.
4406-
// We need a finer grained side effect.
4407-
add(HForeignCode(
4408-
fixedLengthMarker, _abstractValueDomain.nullType, [stack.last],
4409-
throwBehavior: NativeThrowBehavior.MAY));
4410-
4411-
HInstruction newInstance = stack.last;
4412-
4413-
// If we inlined a constructor the call-site-specific type from type
4414-
// inference (e.g. a container type) will not be on the node. Store the
4415-
// more specialized type on the allocation.
4416-
newInstance.instructionType = resultType;
4417-
graph.allocatedFixedLists.add(newInstance);
4418-
4419-
InterfaceType type = _elementMap.createInterfaceType(
4420-
invocation.target.enclosingClass!, invocation.arguments.types);
4421-
stack.add(_setListRuntimeTypeInfoIfNeeded(pop(), type, sourceInformation));
4422-
}
4423-
44244311
/// Replace calls to `extractTypeArguments` with equivalent code. Returns
44254312
/// `true` if `extractTypeArguments` is handled.
44264313
bool _handleExtractTypeArguments(

pkg/compiler/test/codegen/builtin_interceptor_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ foo() {
2020

2121
const String TEST_THREE = r"""
2222
foo() {
23-
return List().add(2);
23+
return [].add(2);
2424
}
2525
""";
2626

pkg/compiler/test/codegen/gvn_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void foo(bar) {
1919
// GVN'ing the length of [:list:].
2020
const String TEST_TWO = r"""
2121
void foo(a) {
22-
var list = List<int>();
22+
var list = <int>[];
2323
list[0] = list[0 % a];
2424
list[1] = list[1 % a];
2525
}

pkg/compiler/test/codegen/list_tracer_length_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ main() {
2626
}
2727

2828
const String TEST3 = r"""
29-
var a = List(42);
29+
var a = List.filled(42, null);
3030
main() {
3131
return a[0];
3232
}
3333
""";
3434

3535
const String TEST4 = r"""
36-
var a = List(0);
36+
var a = List.filled(0, null);
3737
main() {
3838
return a[0];
3939
}
@@ -75,15 +75,15 @@ main() {
7575

7676
const String TEST8 = r"""
7777
var b = int.parse('42');
78-
var a = List(b);
78+
var a = List.filled(b, null);
7979
main() {
8080
return a[1];
8181
}
8282
""";
8383

8484
const String TEST9 = r"""
8585
const b = 42;
86-
var a = List(b);
86+
var a = List.filled(b, null);
8787
main() {
8888
return a[1];
8989
}

pkg/compiler/test/codegen/list_tracer_node_type_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ main() {
1515

1616
const String TEST2 = r"""
1717
main() {
18-
var a = List();
18+
var a = [];
1919
a.add(42);
2020
a.add(null);
2121
return a[0] + 42;
@@ -24,7 +24,7 @@ main() {
2424

2525
const String TEST3 = r"""
2626
main() {
27-
var a = List(42);
27+
var a = List<dynamic>.filled(42, null);
2828
a[a.length - 1] = 42;
2929
return a[0] + 42;
3030
}

pkg/compiler/test/codegen/value_range3_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var a = [42];
1616
main() {
1717
var value = a[0];
1818
if (value < 42) {
19-
return List(42)[value];
19+
return List.filled(42, null)[value];
2020
}
2121
}
2222
''',

0 commit comments

Comments
 (0)