Skip to content

Commit

Permalink
Reland "[cfe] Improve encoding of set/list literals for unified colle…
Browse files Browse the repository at this point in the history
…ctions"

Change-Id: I4f8098e110c9a5e5d6e102b8c6230e85c1575c6a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175040
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
  • Loading branch information
johnniwinther authored and commit-bot@chromium.org committed Dec 4, 2020
1 parent c7f3645 commit f7ae22a
Show file tree
Hide file tree
Showing 90 changed files with 8,916 additions and 8,109 deletions.
331 changes: 218 additions & 113 deletions pkg/front_end/lib/src/fasta/kernel/transform_collections.dart

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions pkg/front_end/lib/src/fasta/source/source_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1447,13 +1447,15 @@ class Iterable<E> {
Iterator<E> get iterator => null;
}
class List<E> extends Iterable {
class List<E> extends Iterable<E> {
factory List() => null;
factory List.unmodifiable(elements) => null;
factory List.filled(int length, E fill, {bool growable = false}) => null;
factory List.generate(int length, E generator(int index),
{bool growable = true}) => null;
void add(E) {}
factory List.of() => null;
void add(E element) {}
void addAll(Iterable<E> iterable) {}
E operator [](int index) => null;
}
Expand Down Expand Up @@ -1512,7 +1514,9 @@ class Symbol {}
class Set<E> {
factory Set() = Set<E>._fake;
external factory Set._fake();
void add(E) {}
external factory Set.of();
void add(E element) {}
void addAll(Iterable<E> iterable) {}
}
class Type {}
Expand Down
21 changes: 11 additions & 10 deletions pkg/front_end/test/fasta/bootstrap_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,17 @@ Future main() async {

Future runCompiler(Uri compiler, Uri input, Uri output) async {
Uri dartVm = Uri.base.resolveUri(new Uri.file(Platform.resolvedExecutable));
StdioProcess result = await StdioProcess.run(
dartVm.toFilePath(),
<String>[
compiler.toFilePath(),
"${Flags.compileSdk}=sdk/",
"${Flags.output}=${output.toFilePath()}",
Flags.verify,
input.toFilePath(),
],
suppressOutput: false);
String executable = dartVm.toFilePath();
List<String> arguments = <String>[
compiler.toFilePath(),
"${Flags.compileSdk}=sdk/",
"${Flags.output}=${output.toFilePath()}",
Flags.verify,
input.toFilePath(),
];
print('Running: $executable ${arguments.join(' ')}');
StdioProcess result =
await StdioProcess.run(executable, arguments, suppressOutput: false);
if (result.exitCode != 0) {
throw "Compilation failed:\n${result.output}";
}
Expand Down
18 changes: 4 additions & 14 deletions pkg/front_end/test/static_types/data/null_aware_spread.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,30 @@ nullAwareListSpread(List<String> list) {
/*cfe.List<String>*/
/*cfe:nnbd.List<String!>!*/
[
/*invoke: void*/
/*cfe.String*/
/*cfe:nnbd.String!*/
'foo',
/*invoke: void*/
/*cfe.current: String*/
/*cfe:nnbd.current: String!*/
...?
/*cfe.List<String>*/
/*cfe:nnbd.List<String!>!*/
list
/*invoke: void*/ list
];
}

nullAwareSetSpread(Set<String> set) {
/*cfe.update: Set<String>*/
/*cfe:nnbd.update: Set<String!>!*/
set =
/*cfe.invoke: LinkedHashSet<String>!*/
/*cfe:nnbd.invoke: LinkedHashSet<String!>!*/
/*cfe.<String>*/
/*cfe:nnbd.<String!>*/
/*cfe.Set<String>*/
/*cfe:nnbd.Set<String!>!*/
{
/*invoke: bool!*/
/*cfe.String*/
/*cfe:nnbd.String!*/
'foo',
/*invoke: bool!*/
/*cfe.current: String*/
/*cfe:nnbd.current: String!*/
...?
/*cfe.Set<String>*/
/*cfe:nnbd.Set<String!>!*/
set
/*invoke: void*/ set
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,5 @@ Errors: {
}
method /* from org-dartlang-debug:synthetic_debug_expression */ debugExpr() → dynamic
return block {
final dart.core::List<dart.core::String*>* #t1 = <dart.core::String*>[];
{
dart.core::Iterator<dart.core::String*>* :sync-for-iterator = main::listOfStrings.{dart.core::Iterable::iterator};
for (; :sync-for-iterator.{dart.core::Iterator::moveNext}(); ) {
final dart.core::String* #t2 = :sync-for-iterator.{dart.core::Iterator::current};
#t1.{dart.core::List::add}{Invariant}(#t2);
}
}
final dart.core::List<dart.core::String*>* #t1 = dart.core::List::of<dart.core::String*>(main::listOfStrings);
} =>#t1;
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,7 @@ static const field core::List<core::String*>* nullList = #C3;
static const field core::List<core::String*>* foo = #C8;
static const field core::List<core::String*>* bar = #C10;
static field core::List<core::String*>* barAsVar = block {
final core::List<core::String*>* #t1 = <core::String*>[];
for (final core::String* #t2 in #C8)
#t1.{core::List::add}{Invariant}(#t2);
final core::List<core::String*>* #t1 = core::List::of<core::String*>(#C8);
#t1.{core::List::add}{Invariant}("!");
} =>#t1;
static const field core::List<core::String*>* barWithNullSpread = invalid-expression "Null value during constant evaluation.";
Expand Down Expand Up @@ -481,9 +479,9 @@ static method main() → dynamic {
core::print(#C17);
core::print(#C22);
core::print( block {
final core::Set<core::String*>* #t3 = col::LinkedHashSet::•<core::String*>();
#t3.{core::Set::add}{Invariant}("hello");
} =>#t3);
final core::Set<core::String*>* #t2 = col::LinkedHashSet::•<core::String*>();
#t2.{core::Set::add}{Invariant}("hello");
} =>#t2);
core::print(#C26);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,7 @@ static const field core::List<core::String*>* nullList = #C3;
static const field core::List<core::String*>* foo = #C8;
static const field core::List<core::String*>* bar = #C10;
static field core::List<core::String*>* barAsVar = block {
final core::List<core::String*>* #t1 = <core::String*>[];
{
core::Iterator<core::String*>* :sync-for-iterator = (#C8).{core::Iterable::iterator};
for (; :sync-for-iterator.{core::Iterator::moveNext}(); ) {
final core::String* #t2 = :sync-for-iterator.{core::Iterator::current};
#t1.{core::List::add}{Invariant}(#t2);
}
}
final core::List<core::String*>* #t1 = core::List::of<core::String*>(#C8);
#t1.{core::List::add}{Invariant}("!");
} =>#t1;
static const field core::List<core::String*>* barWithNullSpread = invalid-expression "Null value during constant evaluation.";
Expand Down Expand Up @@ -486,9 +479,9 @@ static method main() → dynamic {
core::print(#C17);
core::print(#C22);
core::print( block {
final core::Set<core::String*>* #t3 = new col::_CompactLinkedHashSet::•<core::String*>();
#t3.{core::Set::add}{Invariant}("hello");
} =>#t3);
final core::Set<core::String*>* #t2 = new col::_CompactLinkedHashSet::•<core::String*>();
#t2.{core::Set::add}{Invariant}("hello");
} =>#t2);
core::print(#C26);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import "dart:collection" as col;

static method main() → dynamic {
final core::List<core::int*>* aList = block {
final core::List<core::int*>* #t1 = <core::int*>[];
#t1.{core::List::add}{Invariant}(1);
final core::List<core::int*>* #t1 = <core::int*>[1];
if(self::oracle() as{TypeError,ForDynamic} core::bool*)
#t1.{core::List::add}{Invariant}(2);
if(self::oracle() as{TypeError,ForDynamic} core::bool*)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import "dart:collection" as col;

static method main() → dynamic {
final core::List<core::int*>* aList = block {
final core::List<core::int*>* #t1 = <core::int*>[];
#t1.{core::List::add}{Invariant}(1);
final core::List<core::int*>* #t1 = <core::int*>[1];
if(self::oracle() as{TypeError,ForDynamic} core::bool*)
#t1.{core::List::add}{Invariant}(2);
if(self::oracle() as{TypeError,ForDynamic} core::bool*)
Expand Down Expand Up @@ -107,4 +106,4 @@ Evaluated: MethodInvocation @ org-dartlang-testcase:///control_flow_collection.d
Evaluated: MethodInvocation @ org-dartlang-testcase:///control_flow_collection.dart:18:26 -> IntConstant(-1)
Evaluated: MethodInvocation @ org-dartlang-testcase:///control_flow_collection.dart:27:29 -> IntConstant(-1)
Evaluated: MethodInvocation @ org-dartlang-testcase:///control_flow_collection.dart:27:33 -> IntConstant(-1)
Extra constant evaluation: evaluated: 160, effectively constant: 4
Extra constant evaluation: evaluated: 158, effectively constant: 4
Loading

0 comments on commit f7ae22a

Please sign in to comment.