Skip to content

Commit b7591ed

Browse files
scheglovCommit Queue
authored and
Commit Queue
committed
Update fieldNameNonPromotabilityInfo storing, element tests.
Change-Id: I9b0a87f5413084e8905c86175d2843e5bdad1633 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330947 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent c0a9368 commit b7591ed

File tree

5 files changed

+123
-45
lines changed

5 files changed

+123
-45
lines changed

pkg/analyzer/lib/src/dart/analysis/driver.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ import 'package:analyzer/src/utilities/uri_cache.dart';
8888
/// TODO(scheglov) Clean up the list of implicitly analyzed files.
8989
class AnalysisDriver implements AnalysisDriverGeneric {
9090
/// The version of data format, should be incremented on every format change.
91-
static const int DATA_VERSION = 312;
91+
static const int DATA_VERSION = 313;
9292

9393
/// The number of exception contexts allowed to write. Once this field is
9494
/// zero, we stop writing any new exception contexts in this process.

pkg/analyzer/lib/src/summary2/bundle_reader.dart

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -544,27 +544,18 @@ class LibraryElementLinkedData extends ElementLinkedData<LibraryElementImpl> {
544544

545545
Map<String, FieldNameNonPromotabilityInfo>?
546546
_readFieldNameNonPromotabilityInfo(ResolutionReader reader) {
547-
// The summary format for `LibraryElementImpl.fieldNameNonPromotabilityInfo`
548-
// is as follows:
549-
// - bool: `true` if field name non-promotability information is present,
550-
// `false` if not.
551-
// - If information is present:
552-
// - Uint30: number of entries in the map.
553-
// - For each map entry:
554-
// - String reference: key
555-
// - Element list: `FieldNameNonPromotabilityInfo.conflictingFields`
556-
// - Element list: `FieldNameNonPromotabilityInfo.conflictingGetters`
557-
// - Element list: `FieldNameNonPromotabilityInfo.conflictingNsmClasses`
558-
if (!reader.readBool()) return null;
559-
int length = reader.readUInt30();
560-
if (length == 0) return const {};
561-
return {
562-
for (int i = 0; i < length; i++)
563-
reader.readStringReference(): FieldNameNonPromotabilityInfo(
547+
return reader.readOptionalObject((_) {
548+
return reader.readMap(
549+
readKey: () => reader.readStringReference(),
550+
readValue: () {
551+
return FieldNameNonPromotabilityInfo(
564552
conflictingFields: reader.readElementList(),
565553
conflictingGetters: reader.readElementList(),
566-
conflictingNsmClasses: reader.readElementList())
567-
};
554+
conflictingNsmClasses: reader.readElementList(),
555+
);
556+
},
557+
);
558+
});
568559
}
569560

570561
void _readLibraryOrAugmentation(
@@ -1992,6 +1983,20 @@ class ResolutionReader {
19921983
return _reader.readTypedListCast<T>(readElement);
19931984
}
19941985

1986+
Map<K, V> readMap<K, V>({
1987+
required K Function() readKey,
1988+
required V Function() readValue,
1989+
}) {
1990+
final length = readUInt30();
1991+
if (length == 0) {
1992+
return const {};
1993+
}
1994+
1995+
return {
1996+
for (var i = 0; i < length; i++) readKey(): readValue(),
1997+
};
1998+
}
1999+
19952000
FunctionType? readOptionalFunctionType() {
19962001
var type = readType();
19972002
return type is FunctionType ? type : null;

pkg/analyzer/lib/src/summary2/bundle_writer.dart

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -396,28 +396,19 @@ class BundleWriter {
396396

397397
void _writeFieldNameNonPromotabilityInfo(
398398
Map<String, FieldNameNonPromotabilityInfo>? info) {
399-
// The summary format for `LibraryElementImpl.fieldNameNonPromotabilityInfo`
400-
// is as follows:
401-
// - bool: `true` if field name non-promotability information is present,
402-
// `false` if not.
403-
// - If information is present:
404-
// - Uint30: number of entries in the map.
405-
// - For each map entry:
406-
// - String reference: key
407-
// - Element list: `FieldNameNonPromotabilityInfo.conflictingFields`
408-
// - Element list: `FieldNameNonPromotabilityInfo.conflictingGetters`
409-
// - Element list: `FieldNameNonPromotabilityInfo.conflictingNsmClasses`
410-
_resolutionSink.writeBool(info != null);
411-
if (info == null) {
412-
return;
413-
}
414-
_resolutionSink.writeUInt30(info.length);
415-
for (var MapEntry(:key, :value) in info.entries) {
416-
_resolutionSink._writeStringReference(key);
417-
_resolutionSink._writeElementList(value.conflictingFields);
418-
_resolutionSink._writeElementList(value.conflictingGetters);
419-
_resolutionSink._writeElementList(value.conflictingNsmClasses);
420-
}
399+
_resolutionSink.writeOptionalObject(info, (info) {
400+
_resolutionSink.writeMap(
401+
info,
402+
writeKey: (key) {
403+
_resolutionSink._writeStringReference(key);
404+
},
405+
writeValue: (value) {
406+
_resolutionSink._writeElementList(value.conflictingFields);
407+
_resolutionSink._writeElementList(value.conflictingGetters);
408+
_resolutionSink._writeElementList(value.conflictingNsmClasses);
409+
},
410+
);
411+
});
421412
}
422413

423414
void _writeFunctionElement(FunctionElementImpl element) {
@@ -775,6 +766,18 @@ class ResolutionSink extends _SummaryDataWriter {
775766
}
776767
}
777768

769+
void writeMap<K, V>(
770+
Map<K, V> map, {
771+
required void Function(K key) writeKey,
772+
required void Function(V value) writeValue,
773+
}) {
774+
writeUInt30(map.length);
775+
for (final entry in map.entries) {
776+
writeKey(entry.key);
777+
writeValue(entry.value);
778+
}
779+
}
780+
778781
void writeOptionalTypeList(List<DartType>? types) {
779782
if (types != null) {
780783
writeBool(true);

pkg/analyzer/test/src/summary/element_text.dart

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:analyzer/dart/ast/ast.dart';
66
import 'package:analyzer/dart/element/element.dart';
77
import 'package:analyzer/dart/element/type.dart';
88
import 'package:analyzer/src/dart/element/element.dart';
9+
import 'package:analyzer/src/dart/element/field_name_non_promotability_info.dart';
910
import 'package:analyzer/src/summary2/export.dart';
1011
import 'package:analyzer/src/task/inference_error.dart';
1112
import 'package:collection/collection.dart';
@@ -77,9 +78,7 @@ class _ElementWriter {
7778
}) : _sink = sink,
7879
_elementPrinter = elementPrinter;
7980

80-
void writeLibraryElement(LibraryElement e) {
81-
e as LibraryElementImpl;
82-
81+
void writeLibraryElement(LibraryElementImpl e) {
8382
_sink.writelnWithIndent('library');
8483
_sink.withIndent(() {
8584
var name = e.name;
@@ -106,6 +105,8 @@ class _ElementWriter {
106105
_writeExportNamespace(e);
107106
});
108107
}
108+
109+
_writeFieldNameNonPromotabilityInfo(e.fieldNameNonPromotabilityInfo);
109110
});
110111
}
111112

@@ -491,6 +492,35 @@ class _ElementWriter {
491492
}
492493
}
493494

495+
void _writeFieldNameNonPromotabilityInfo(
496+
Map<String, FieldNameNonPromotabilityInfo>? info,
497+
) {
498+
if (info == null || info.isEmpty) {
499+
return;
500+
}
501+
502+
_sink.writelnWithIndent('fieldNameNonPromotabilityInfo');
503+
_sink.withIndent(() {
504+
for (final entry in info.entries) {
505+
_sink.writelnWithIndent(entry.key);
506+
_sink.withIndent(() {
507+
_elementPrinter.writeElementList(
508+
'conflictingFields',
509+
entry.value.conflictingFields,
510+
);
511+
_elementPrinter.writeElementList(
512+
'conflictingGetters',
513+
entry.value.conflictingGetters,
514+
);
515+
_elementPrinter.writeElementList(
516+
'conflictingNsmClasses',
517+
entry.value.conflictingNsmClasses,
518+
);
519+
});
520+
}
521+
});
522+
}
523+
494524
void _writeFunctionElement(FunctionElementImpl e) {
495525
expect(e.isStatic, isTrue);
496526

pkg/analyzer/test/src/summary/elements_test.dart

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8362,6 +8362,10 @@ library
83628362
fields
83638363
final _foo @23
83648364
type: int?
8365+
fieldNameNonPromotabilityInfo
8366+
_foo
8367+
conflictingGetters
8368+
self::@class::B::@getter::_foo
83658369
''');
83668370
}
83678371

@@ -8414,6 +8418,10 @@ library
84148418
fields
84158419
final _foo @38
84168420
type: int?
8421+
fieldNameNonPromotabilityInfo
8422+
_foo
8423+
conflictingGetters
8424+
self::@class::B::@getter::_foo
84178425
''');
84188426
}
84198427

@@ -8462,6 +8470,10 @@ library
84628470
fields
84638471
final _foo @23
84648472
type: int?
8473+
fieldNameNonPromotabilityInfo
8474+
_foo
8475+
conflictingFields
8476+
self::@class::B::@field::_foo
84658477
''');
84668478
}
84678479

@@ -8560,6 +8572,10 @@ library
85608572
fields
85618573
final _foo @23
85628574
type: int?
8575+
fieldNameNonPromotabilityInfo
8576+
_foo
8577+
conflictingNsmClasses
8578+
self::@class::C
85638579
''');
85648580
}
85658581

@@ -8680,6 +8696,10 @@ library
86808696
fields
86818697
final _foo @23
86828698
type: int?
8699+
fieldNameNonPromotabilityInfo
8700+
_foo
8701+
conflictingNsmClasses
8702+
self::@class::E
86838703
''');
86848704
}
86858705

@@ -8717,6 +8737,10 @@ library
87178737
final _foo @71
87188738
type: int?
87198739
shouldUseTypeForInitializerInference: true
8740+
fieldNameNonPromotabilityInfo
8741+
_foo
8742+
conflictingNsmClasses
8743+
self::@enum::E
87208744
''');
87218745
}
87228746

@@ -8746,6 +8770,10 @@ library
87468770
fields
87478771
final _foo @23
87488772
type: int?
8773+
fieldNameNonPromotabilityInfo
8774+
_foo
8775+
conflictingNsmClasses
8776+
self::@class::C
87498777
''');
87508778
}
87518779

@@ -8814,6 +8842,10 @@ library
88148842
fields
88158843
final _foo @23
88168844
type: int?
8845+
fieldNameNonPromotabilityInfo
8846+
_foo
8847+
conflictingNsmClasses
8848+
self::@class::C
88178849
''');
88188850
}
88198851

@@ -8856,6 +8888,10 @@ library
88568888
final _foo @71
88578889
type: int?
88588890
shouldUseTypeForInitializerInference: true
8891+
fieldNameNonPromotabilityInfo
8892+
_foo
8893+
conflictingNsmClasses
8894+
self::@class::C
88598895
''');
88608896
}
88618897

@@ -8905,6 +8941,10 @@ library
89058941
fields
89068942
_foo @17
89078943
type: int?
8944+
fieldNameNonPromotabilityInfo
8945+
_foo
8946+
conflictingFields
8947+
self::@class::A::@field::_foo
89088948
''');
89098949
}
89108950

0 commit comments

Comments
 (0)