Skip to content

Commit 45efccb

Browse files
rakudramaCommit Queue
authored and
Commit Queue
committed
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. TEST=ci Change-Id: I4ffaf3ae2c4e75ca06e7ba0bf19187b6376f3888 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/297100 Reviewed-by: Brian Quinlan <[email protected]> Reviewed-by: Nate Bosch <[email protected]> Reviewed-by: Sigmund Cherem <[email protected]> Commit-Queue: Stephen Adams <[email protected]>
1 parent 69f71e9 commit 45efccb

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
@@ -1107,14 +1107,6 @@ class KCommonElements extends CommonElements {
11071107
class JCommonElements extends CommonElements {
11081108
JCommonElements(super.dartTypes, super.env);
11091109

1110-
/// Returns `true` if [element] is the unnamed constructor of `List`.
1111-
///
1112-
/// This will not resolve the constructor if it hasn't been seen yet during
1113-
/// compilation.
1114-
bool isUnnamedListConstructor(ConstructorEntity element) =>
1115-
(element.name == '' && element.enclosingClass == listClass) ||
1116-
(element.name == 'list' && element.enclosingClass == jsArrayClass);
1117-
11181110
/// Returns `true` if [element] is the named constructor of `List`,
11191111
/// e.g. `List.of`.
11201112
///

pkg/compiler/lib/src/inferrer/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/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
@@ -4256,27 +4256,6 @@ class KernelSsaGraphBuilder extends ir.Visitor<void> with ir.VisitorVoidMixin {
42564256
AbstractValue typeMask,
42574257
List<HInstruction> arguments,
42584258
SourceInformation? sourceInformation) {
4259-
// Recognize `List()` and `List(n)`.
4260-
if (_commonElements.isUnnamedListConstructor(function)) {
4261-
if (invocation.arguments.named.isEmpty) {
4262-
int argumentCount = invocation.arguments.positional.length;
4263-
if (argumentCount == 0) {
4264-
// `List()` takes no arguments, `JSArray.list()` takes a sentinel.
4265-
assert(arguments.length == 0 || arguments.length == 1,
4266-
'\narguments: $arguments\n');
4267-
_handleInvokeLegacyGrowableListFactoryConstructor(
4268-
invocation, function, typeMask, arguments, sourceInformation);
4269-
return;
4270-
}
4271-
if (argumentCount == 1) {
4272-
assert(arguments.length == 1);
4273-
_handleInvokeLegacyFixedListFactoryConstructor(
4274-
invocation, function, typeMask, arguments, sourceInformation);
4275-
return;
4276-
}
4277-
}
4278-
}
4279-
42804259
// Recognize `JSArray<E>.typed(allocation)`.
42814260
if (function == _commonElements.jsArrayTypedConstructor) {
42824261
if (invocation.arguments.named.isEmpty) {
@@ -4400,98 +4379,6 @@ class KernelSsaGraphBuilder extends ir.Visitor<void> with ir.VisitorVoidMixin {
44004379
stack.add(_setListRuntimeTypeInfoIfNeeded(pop(), type, sourceInformation));
44014380
}
44024381

4403-
/// Handle the legacy `List<T>()` constructor.
4404-
void _handleInvokeLegacyGrowableListFactoryConstructor(
4405-
ir.StaticInvocation invocation,
4406-
ConstructorEntity function,
4407-
AbstractValue typeMask,
4408-
List<HInstruction> arguments,
4409-
SourceInformation? sourceInformation) {
4410-
// `List<T>()` is essentially the same as `<T>[]`.
4411-
push(_buildLiteralList([]));
4412-
HInstruction allocation = pop();
4413-
var inferredType = globalInferenceResults.typeOfNewList(invocation);
4414-
if (inferredType != null) {
4415-
allocation.instructionType = inferredType;
4416-
}
4417-
InterfaceType type = _elementMap.createInterfaceType(
4418-
invocation.target.enclosingClass!, invocation.arguments.types);
4419-
stack.add(
4420-
_setListRuntimeTypeInfoIfNeeded(allocation, type, sourceInformation));
4421-
}
4422-
4423-
/// Handle the `JSArray<T>.list(length)` and legacy `List<T>(length)`
4424-
/// constructors.
4425-
void _handleInvokeLegacyFixedListFactoryConstructor(
4426-
ir.StaticInvocation invocation,
4427-
ConstructorEntity function,
4428-
AbstractValue typeMask,
4429-
List<HInstruction> arguments,
4430-
SourceInformation? sourceInformation) {
4431-
assert(
4432-
// Arguments may include the type.
4433-
arguments.length == 1 || arguments.length == 2,
4434-
failedAt(
4435-
function,
4436-
"Unexpected arguments. "
4437-
"Expected 1-2 argument, actual: $arguments."));
4438-
HInstruction lengthInput = arguments.first;
4439-
if (lengthInput.isNumber(_abstractValueDomain).isPotentiallyFalse) {
4440-
HPrimitiveCheck conversion = HPrimitiveCheck(
4441-
_commonElements.numType,
4442-
HPrimitiveCheck.ARGUMENT_TYPE_CHECK,
4443-
_abstractValueDomain.numType,
4444-
lengthInput,
4445-
sourceInformation);
4446-
add(conversion);
4447-
lengthInput = conversion;
4448-
}
4449-
js.Template code = js.js.parseForeignJS('new Array(#)');
4450-
var behavior = NativeBehavior();
4451-
4452-
DartType expectedType = _getStaticType(invocation).type;
4453-
behavior.typesInstantiated.add(expectedType);
4454-
behavior.typesReturned.add(expectedType);
4455-
4456-
// The allocation can throw only if the given length is a double or
4457-
// outside the unsigned 32 bit range.
4458-
// TODO(sra): Array allocation should be an instruction so that canThrow
4459-
// can depend on a length type discovered in optimization.
4460-
bool canThrow = true;
4461-
if (lengthInput.isUInt32(_abstractValueDomain).isDefinitelyTrue) {
4462-
canThrow = false;
4463-
}
4464-
4465-
var resultType = globalInferenceResults.typeOfNewList(invocation) ??
4466-
_abstractValueDomain.fixedListType;
4467-
4468-
HForeignCode foreign = HForeignCode(code, resultType, [lengthInput],
4469-
nativeBehavior: behavior,
4470-
throwBehavior:
4471-
canThrow ? NativeThrowBehavior.MAY : NativeThrowBehavior.NEVER)
4472-
..sourceInformation = sourceInformation;
4473-
push(foreign);
4474-
js.Template fixedLengthMarker =
4475-
js.js.parseForeignJS(r'#.fixed$length = Array');
4476-
// We set the instruction as [canThrow] to avoid it being dead code.
4477-
// We need a finer grained side effect.
4478-
add(HForeignCode(
4479-
fixedLengthMarker, _abstractValueDomain.nullType, [stack.last],
4480-
throwBehavior: NativeThrowBehavior.MAY));
4481-
4482-
HInstruction newInstance = stack.last;
4483-
4484-
// If we inlined a constructor the call-site-specific type from type
4485-
// inference (e.g. a container type) will not be on the node. Store the
4486-
// more specialized type on the allocation.
4487-
newInstance.instructionType = resultType;
4488-
graph.allocatedFixedLists.add(newInstance);
4489-
4490-
InterfaceType type = _elementMap.createInterfaceType(
4491-
invocation.target.enclosingClass!, invocation.arguments.types);
4492-
stack.add(_setListRuntimeTypeInfoIfNeeded(pop(), type, sourceInformation));
4493-
}
4494-
44954382
/// Replace calls to `extractTypeArguments` with equivalent code. Returns
44964383
/// `true` if `extractTypeArguments` is handled.
44974384
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)