Skip to content

Commit

Permalink
Version 2.10.0-142.0.dev
Browse files Browse the repository at this point in the history
Merge commit 'ac6095a7cc5098d4449db9eb7f2a41da6f76d00e' into 'dev'
  • Loading branch information
Dart CI committed Sep 17, 2020
2 parents fcaedc6 + ac6095a commit 2cec6af
Show file tree
Hide file tree
Showing 15 changed files with 239 additions and 368 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,8 @@ class FixProcessor extends BaseProcessor {

Future<void> compute(CorrectionProducer producer) async {
producer.configure(context);
var builder = ChangeBuilder(workspace: context.workspace);
var builder = ChangeBuilder(
workspace: context.workspace, eol: context.utils.endOfLine);
await producer.compute(builder);
_addFixFromBuilder(builder, producer.fixKind,
args: producer.fixArguments);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,34 @@ class B extends A {
''');
}

Future<void> test_lineEndings() async {
// TODO(dantup): Remove the need for this here, and have all of the tests
// test with CRLF when running on Windows.
final newlineWithoutCarriageReturn = RegExp(r'(?<!\r)\n');
String asCrLf(String input) =>
input.replaceAll(newlineWithoutCarriageReturn, '\r\n');
await resolveTestUnit(asCrLf('''
class A {
void ma() {}
}
class B implements A {
}
'''));
await assertHasFix(asCrLf('''
class A {
void ma() {}
}
class B implements A {
@override
void ma() {
// TODO: implement ma
}
}
'''));
}

Future<void> test_mergeToField_getterSetter() async {
await resolveTestUnit('''
class A {
Expand Down
3 changes: 3 additions & 0 deletions pkg/analyzer/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ linter:
rules:
- avoid_unused_constructor_parameters
- empty_statements
- iterable_contains_unrelated_type
- list_remove_unrelated_type
- prefer_typing_uninitialized_variables
- unnecessary_brace_in_string_interps
- unnecessary_overrides
- unnecessary_parenthesis
35 changes: 0 additions & 35 deletions pkg/analyzer/lib/src/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3320,11 +3320,6 @@ class EnumElementImpl extends AbstractClassElementImpl {
return _accessors ?? const <PropertyAccessorElement>[];
}

@override
set accessors(List<PropertyAccessorElement> accessors) {
super.accessors = accessors;
}

@override
List<InterfaceType> get allSupertypes => <InterfaceType>[supertype];

Expand Down Expand Up @@ -3377,11 +3372,6 @@ class EnumElementImpl extends AbstractClassElementImpl {
return _fields ?? const <FieldElement>[];
}

@override
set fields(List<FieldElement> fields) {
super.fields = fields;
}

@override
bool get hasNonFinalField => false;

Expand Down Expand Up @@ -3837,11 +3827,6 @@ class ExportElementImpl extends UriReferencedElementImpl
@override
ElementKind get kind => ElementKind.EXPORT;

@override
set metadata(List<ElementAnnotation> metadata) {
super.metadata = metadata;
}

@override
int get nameOffset {
if (linkedNode != null) {
Expand Down Expand Up @@ -4916,11 +4901,6 @@ class ImportElementImpl extends UriReferencedElementImpl
@override
ElementKind get kind => ElementKind.IMPORT;

@override
set metadata(List<ElementAnnotation> metadata) {
super.metadata = metadata;
}

@override
int get nameOffset {
if (linkedNode != null) {
Expand Down Expand Up @@ -4984,11 +4964,6 @@ class ImportElementImpl extends UriReferencedElementImpl
return super.uri;
}

@override
set uri(String uri) {
super.uri = uri;
}

@override
T accept<T>(ElementVisitor<T> visitor) => visitor.visitImportElement(this);

Expand Down Expand Up @@ -6248,11 +6223,6 @@ abstract class NonParameterVariableElementImpl extends VariableElementImpl {
return super.hasImplicitType;
}

@override
set hasImplicitType(bool hasImplicitType) {
super.hasImplicitType = hasImplicitType;
}

bool get hasInitializer {
return linkedNode != null && linkedContext.hasInitializer(linkedNode);
}
Expand Down Expand Up @@ -6406,11 +6376,6 @@ class ParameterElementImpl extends VariableElementImpl
return super.hasImplicitType;
}

@override
set hasImplicitType(bool hasImplicitType) {
super.hasImplicitType = hasImplicitType;
}

/// True if this parameter inherits from a covariant parameter. This happens
/// when it overrides a method in a supertype that has a corresponding
/// covariant parameter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -832,11 +832,6 @@ class _PackageBuildWorkspaceBase extends PubPackageResolutionTest {
return '$testPackageRootPath/.dart_tool/build/generated';
}

@override
void setUp() {
super.setUp();
}

@override
void verifyCreatedCollection() {
super.verifyCreatedCollection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ChangeBuilderImpl implements ChangeBuilder {

/// The end-of-line marker used in the file being edited, or `null` if the
/// default marker should be used.
String eol;
final String eol;

/// A table mapping group ids to the associated linked edit groups.
final Map<String, LinkedEditGroup> _linkedEditGroups =
Expand All @@ -49,7 +49,8 @@ class ChangeBuilderImpl implements ChangeBuilder {
/// Initialize a newly created change builder. If the builder will be used to
/// create changes for Dart files, then either a [session] or a [workspace]
/// must be provided (but not both).
ChangeBuilderImpl({AnalysisSession session, ChangeWorkspace workspace})
ChangeBuilderImpl(
{AnalysisSession session, ChangeWorkspace workspace, this.eol})
: assert(session == null || workspace == null),
workspace = workspace ?? _SingleSessionWorkspace(session);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ abstract class ChangeBuilder {
/// Initialize a newly created change builder. If the builder will be used to
/// create changes for Dart files, then either a [session] or a [workspace]
/// must be provided (but not both).
factory ChangeBuilder({AnalysisSession session, ChangeWorkspace workspace}) =
ChangeBuilderImpl;
factory ChangeBuilder(
{AnalysisSession session,
ChangeWorkspace workspace,
String eol}) = ChangeBuilderImpl;

/// Return the range of the selection for the change being built, or `null` if
/// there is no selection.
Expand Down
21 changes: 13 additions & 8 deletions runtime/vm/clustered_snapshot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4885,13 +4885,13 @@ class OneByteStringDeserializationCluster : public DeserializationCluster {
OneByteString::InstanceSize(length),
is_canonical);
str->ptr()->length_ = Smi::New(length);
uint32_t hash = 0;
StringHasher hasher;
for (intptr_t j = 0; j < length; j++) {
uint8_t code_point = d->Read<uint8_t>();
str->ptr()->data()[j] = code_point;
hash = CombineHashes(hash, code_point);
uint8_t code_unit = d->Read<uint8_t>();
str->ptr()->data()[j] = code_unit;
hasher.Add(code_unit);
}
String::SetCachedHash(str, FinalizeHash(hash, String::kHashBits));
String::SetCachedHash(str, hasher.Finalize());
}
}
};
Expand Down Expand Up @@ -4964,9 +4964,14 @@ class TwoByteStringDeserializationCluster : public DeserializationCluster {
TwoByteString::InstanceSize(length),
is_canonical);
str->ptr()->length_ = Smi::New(length);
uint8_t* cdata = reinterpret_cast<uint8_t*>(str->ptr()->data());
d->ReadBytes(cdata, length * 2);
String::SetCachedHash(str, String::Hash(str));
StringHasher hasher;
for (intptr_t j = 0; j < length; j++) {
uint16_t code_unit = d->Read<uint8_t>();
code_unit = code_unit | (d->Read<uint8_t>() << 8);
str->ptr()->data()[j] = code_unit;
hasher.Add(code_unit);
}
String::SetCachedHash(str, hasher.Finalize());
}
}
};
Expand Down
84 changes: 23 additions & 61 deletions runtime/vm/object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21734,25 +21734,6 @@ const char* Double::ToCString() const {
return buffer;
}

// Synchronize with implementation in compiler (intrinsifier).
class StringHasher : ValueObject {
public:
StringHasher() : hash_(0) {}
void Add(int32_t ch) { hash_ = CombineHashes(hash_, ch); }
void Add(const String& str, intptr_t begin_index, intptr_t len);

// Return a non-zero hash of at most 'bits' bits.
intptr_t Finalize(int bits) {
ASSERT(1 <= bits && bits <= (kBitsPerWord - 1));
hash_ = FinalizeHash(hash_, bits);
ASSERT(hash_ <= static_cast<uint32_t>(kMaxInt32));
return hash_;
}

private:
uint32_t hash_;
};

void StringHasher::Add(const String& str, intptr_t begin_index, intptr_t len) {
ASSERT(begin_index >= 0);
ASSERT(len >= 0);
Expand All @@ -21762,48 +21743,32 @@ void StringHasher::Add(const String& str, intptr_t begin_index, intptr_t len) {
}
if (str.IsOneByteString()) {
NoSafepointScope no_safepoint;
uint8_t* str_addr = OneByteString::CharAddr(str, begin_index);
for (intptr_t i = 0; i < len; i++) {
Add(*str_addr);
str_addr++;
}
Add(OneByteString::CharAddr(str, begin_index), len);
} else if (str.IsExternalOneByteString()) {
NoSafepointScope no_safepoint;
Add(ExternalOneByteString::CharAddr(str, begin_index), len);
} else if (str.IsTwoByteString()) {
NoSafepointScope no_safepoint;
Add(TwoByteString::CharAddr(str, begin_index), len);
} else if (str.IsExternalOneByteString()) {
NoSafepointScope no_safepoint;
Add(ExternalTwoByteString::CharAddr(str, begin_index), len);
} else {
String::CodePointIterator it(str, begin_index, len);
while (it.Next()) {
Add(it.Current());
}
UNREACHABLE();
}
}

intptr_t String::Hash(const String& str, intptr_t begin_index, intptr_t len) {
StringHasher hasher;
hasher.Add(str, begin_index, len);
return hasher.Finalize(kHashBits);
return hasher.Finalize();
}

intptr_t String::HashConcat(const String& str1, const String& str2) {
intptr_t len1 = str1.Length();
// Since String::Hash works at the code point (rune) level, a surrogate pair
// that crosses the boundary between str1 and str2 must be composed.
if (str1.IsTwoByteString() && Utf16::IsLeadSurrogate(str1.CharAt(len1 - 1))) {
const String& temp = String::Handle(String::Concat(str1, str2));
return temp.Hash();
} else {
StringHasher hasher;
hasher.Add(str1, 0, len1);
hasher.Add(str2, 0, str2.Length());
return hasher.Finalize(kHashBits);
}
}

template <typename T>
static intptr_t HashImpl(const T* characters, intptr_t len) {
ASSERT(len >= 0);
StringHasher hasher;
for (intptr_t i = 0; i < len; i++) {
hasher.Add(characters[i]);
}
return hasher.Finalize(String::kHashBits);
hasher.Add(str1, 0, str1.Length());
hasher.Add(str2, 0, str2.Length());
return hasher.Finalize();
}

intptr_t String::Hash(StringPtr raw) {
Expand Down Expand Up @@ -21833,24 +21798,21 @@ intptr_t String::Hash(StringPtr raw) {
}

intptr_t String::Hash(const char* characters, intptr_t len) {
return HashImpl(characters, len);
StringHasher hasher;
hasher.Add(reinterpret_cast<const uint8_t*>(characters), len);
return hasher.Finalize();
}

intptr_t String::Hash(const uint8_t* characters, intptr_t len) {
return HashImpl(characters, len);
StringHasher hasher;
hasher.Add(characters, len);
return hasher.Finalize();
}

intptr_t String::Hash(const uint16_t* characters, intptr_t len) {
StringHasher hasher;
intptr_t i = 0;
while (i < len) {
hasher.Add(Utf16::Next(characters, &i, len));
}
return hasher.Finalize(kHashBits);
}

intptr_t String::Hash(const int32_t* characters, intptr_t len) {
return HashImpl(characters, len);
hasher.Add(characters, len);
return hasher.Finalize();
}

intptr_t String::CharSize() const {
Expand Down
29 changes: 29 additions & 0 deletions runtime/vm/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -9065,6 +9065,32 @@ class String : public Instance {
friend class Pass2Visitor; // Stack "handle"
};

// Synchronize with implementation in compiler (intrinsifier).
class StringHasher : ValueObject {
public:
StringHasher() : hash_(0) {}
void Add(uint16_t code_unit) { hash_ = CombineHashes(hash_, code_unit); }
void Add(const uint8_t* code_units, intptr_t len) {
while (len > 0) {
Add(*code_units);
code_units++;
len--;
}
}
void Add(const uint16_t* code_units, intptr_t len) {
while (len > 0) {
Add(LoadUnaligned(code_units));
code_units++;
len--;
}
}
void Add(const String& str, intptr_t begin_index, intptr_t len);
intptr_t Finalize() { return FinalizeHash(hash_, String::kHashBits); }

private:
uint32_t hash_;
};

class OneByteString : public AllStatic {
public:
static uint16_t CharAt(const String& str, intptr_t index) {
Expand Down Expand Up @@ -9327,6 +9353,7 @@ class TwoByteString : public AllStatic {

friend class Class;
friend class String;
friend class StringHasher;
friend class SnapshotReader;
friend class Symbols;
};
Expand Down Expand Up @@ -9424,6 +9451,7 @@ class ExternalOneByteString : public AllStatic {

friend class Class;
friend class String;
friend class StringHasher;
friend class SnapshotReader;
friend class Symbols;
friend class Utf8;
Expand Down Expand Up @@ -9518,6 +9546,7 @@ class ExternalTwoByteString : public AllStatic {

friend class Class;
friend class String;
friend class StringHasher;
friend class SnapshotReader;
friend class Symbols;
};
Expand Down
Loading

0 comments on commit 2cec6af

Please sign in to comment.