Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 469da72

Browse files
alexmarkovcommit-bot@chromium.org
authored andcommitted
[vm] Put covariance attributes into Field flags
This change reduces number of places where we need to re-parse kernel field declarations in order to get covariance attributes. Change-Id: I7d33d3787726270b93d16eda59b09345749a38fb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/96407 Commit-Queue: Alexander Markov <[email protected]> Auto-Submit: Alexander Markov <[email protected]> Reviewed-by: Martin Kustermann <[email protected]> Reviewed-by: Samir Jindel <[email protected]>
1 parent 0908749 commit 469da72

File tree

6 files changed

+33
-41
lines changed

6 files changed

+33
-41
lines changed

runtime/vm/compiler/call_specializer.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,14 +1017,10 @@ bool CallSpecializer::TryInlineInstanceSetter(InstanceCallInstr* instr,
10171017
// not in strong mode or if at a dynamic invocation.
10181018
bool needs_check = true;
10191019
if (!instr->interface_target().IsNull() && (field.kernel_offset() >= 0)) {
1020-
bool is_covariant = false;
1021-
bool is_generic_covariant = false;
1022-
field.GetCovarianceAttributes(&is_covariant, &is_generic_covariant);
1023-
1024-
if (is_covariant) {
1020+
if (field.is_covariant()) {
10251021
// Always type check covariant fields.
10261022
needs_check = true;
1027-
} else if (is_generic_covariant) {
1023+
} else if (field.is_generic_covariant_impl()) {
10281024
// If field is generic covariant then we don't need to check it
10291025
// if the invocation was marked as unchecked (e.g. receiver of
10301026
// the invocation is also the receiver of the surrounding method).

runtime/vm/compiler/frontend/scope_builder.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,10 @@ ScopeBuildingResult* ScopeBuilder::BuildScopes() {
290290

291291
if (is_method &&
292292
MethodCanSkipTypeChecksForNonCovariantArguments(function, attrs)) {
293-
FieldHelper field_helper(&helper_);
294-
field_helper.ReadUntilIncluding(FieldHelper::kFlags);
295-
296-
if (field_helper.IsCovariant()) {
293+
const auto& field = Field::Handle(Z, function.accessor_field());
294+
if (field.is_covariant()) {
297295
result_->setter_value->set_is_explicit_covariant_parameter();
298-
} else if (!field_helper.IsGenericCovariantImpl() ||
296+
} else if (!field.is_generic_covariant_impl() ||
299297
(!attrs.has_non_this_uses && !attrs.has_tearoff_uses)) {
300298
result_->setter_value->set_type_check_mode(
301299
LocalVariable::kTypeCheckedByCaller);

runtime/vm/kernel.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -618,10 +618,8 @@ bool NeedsDynamicInvocationForwarder(const Function& function) {
618618
// Handle setters.
619619
if (reader_helper.PeekTag() == kField) {
620620
ASSERT(function.IsImplicitSetterFunction());
621-
FieldHelper field_helper(&reader_helper);
622-
field_helper.ReadUntilIncluding(FieldHelper::kFlags);
623-
return !(field_helper.IsCovariant() ||
624-
field_helper.IsGenericCovariantImpl());
621+
const auto& field = Field::Handle(zone, function.accessor_field());
622+
return !(field.is_covariant() || field.is_generic_covariant_impl());
625623
}
626624

627625
reader_helper.ReadUntilFunctionNode();

runtime/vm/kernel_loader.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,9 @@ void KernelLoader::FinishTopLevelClassLoading(
10671067
// In the VM all const fields are implicitly final whereas in Kernel they
10681068
// are not final because they are not explicitly declared that way.
10691069
const bool is_final = field_helper.IsConst() || field_helper.IsFinal();
1070+
// Only instance fields could be covariant.
1071+
ASSERT(!field_helper.IsCovariant() &&
1072+
!field_helper.IsGenericCovariantImpl());
10701073
const Field& field = Field::Handle(
10711074
Z,
10721075
Field::NewTopLevel(name, is_final, field_helper.IsConst(), script_class,
@@ -1490,6 +1493,9 @@ void KernelLoader::FinishClassLoading(const Class& klass,
14901493
field_helper.position_, field_helper.end_position_));
14911494
field.set_kernel_offset(field_offset);
14921495
field.set_has_pragma(has_pragma_annotation);
1496+
field.set_is_covariant(field_helper.IsCovariant());
1497+
field.set_is_generic_covariant_impl(
1498+
field_helper.IsGenericCovariantImpl());
14931499
ReadInferredType(field, field_offset + library_kernel_offset_);
14941500
CheckForInitializer(field);
14951501
field_helper.ReadUntilExcluding(FieldHelper::kInitializer);

runtime/vm/object.cc

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8279,27 +8279,6 @@ intptr_t Field::KernelDataProgramOffset() const {
82798279
return PatchClass::Cast(obj).library_kernel_offset();
82808280
}
82818281

8282-
#if !defined(DART_PRECOMPILED_RUNTIME)
8283-
void Field::GetCovarianceAttributes(bool* is_covariant,
8284-
bool* is_generic_covariant) const {
8285-
Thread* thread = Thread::Current();
8286-
Zone* zone = Thread::Current()->zone();
8287-
auto& script = Script::Handle(zone, Script());
8288-
8289-
kernel::TranslationHelper translation_helper(thread);
8290-
translation_helper.InitFromScript(script);
8291-
8292-
kernel::KernelReaderHelper kernel_reader_helper(
8293-
zone, &translation_helper, script,
8294-
ExternalTypedData::Handle(zone, KernelData()), KernelDataProgramOffset());
8295-
kernel_reader_helper.SetOffset(kernel_offset());
8296-
kernel::FieldHelper field_helper(&kernel_reader_helper);
8297-
field_helper.ReadUntilIncluding(kernel::FieldHelper::kFlags);
8298-
*is_covariant = field_helper.IsCovariant();
8299-
*is_generic_covariant = field_helper.IsGenericCovariantImpl();
8300-
}
8301-
#endif
8302-
83038282
// Called at finalization time
83048283
void Field::SetFieldType(const AbstractType& value) const {
83058284
ASSERT(Thread::Current()->IsMutatorThread());

runtime/vm/object.h

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3055,6 +3055,21 @@ class Field : public Object {
30553055
set_kind_bits(HasPragmaBit::update(value, raw_ptr()->kind_bits_));
30563056
}
30573057

3058+
bool is_covariant() const {
3059+
return CovariantBit::decode(raw_ptr()->kind_bits_);
3060+
}
3061+
void set_is_covariant(bool value) const {
3062+
set_kind_bits(CovariantBit::update(value, raw_ptr()->kind_bits_));
3063+
}
3064+
3065+
bool is_generic_covariant_impl() const {
3066+
return GenericCovariantImplBit::decode(raw_ptr()->kind_bits_);
3067+
}
3068+
void set_is_generic_covariant_impl(bool value) const {
3069+
set_kind_bits(
3070+
GenericCovariantImplBit::update(value, raw_ptr()->kind_bits_));
3071+
}
3072+
30583073
intptr_t kernel_offset() const {
30593074
#if defined(DART_PRECOMPILED_RUNTIME)
30603075
return 0;
@@ -3073,11 +3088,6 @@ class Field : public Object {
30733088

30743089
intptr_t KernelDataProgramOffset() const;
30753090

3076-
#if !defined(DART_PRECOMPILED_RUNTIME)
3077-
void GetCovarianceAttributes(bool* is_covariant,
3078-
bool* is_generic_covariant) const;
3079-
#endif
3080-
30813091
inline intptr_t Offset() const;
30823092
// Called during class finalization.
30833093
inline void SetOffset(intptr_t offset_in_bytes) const;
@@ -3313,6 +3323,8 @@ class Field : public Object {
33133323
kDoubleInitializedBit,
33143324
kInitializerChangedAfterInitializatonBit,
33153325
kHasPragmaBit,
3326+
kCovariantBit,
3327+
kGenericCovariantImplBit,
33163328
};
33173329
class ConstBit : public BitField<uint16_t, bool, kConstBit, 1> {};
33183330
class StaticBit : public BitField<uint16_t, bool, kStaticBit, 1> {};
@@ -3330,6 +3342,9 @@ class Field : public Object {
33303342
kInitializerChangedAfterInitializatonBit,
33313343
1> {};
33323344
class HasPragmaBit : public BitField<uint16_t, bool, kHasPragmaBit, 1> {};
3345+
class CovariantBit : public BitField<uint16_t, bool, kCovariantBit, 1> {};
3346+
class GenericCovariantImplBit
3347+
: public BitField<uint16_t, bool, kGenericCovariantImplBit, 1> {};
33333348

33343349
// Update guarded cid and guarded length for this field. Returns true, if
33353350
// deoptimization of dependent code is required.

0 commit comments

Comments
 (0)