Skip to content

Commit eed3b5e

Browse files
Fix inlining annotations for AOT.
We were only recording metadata positions when mirrors were enabled. Mirrors are not enabled for AOT, so this metadata became unavailable to the inliner. Now we always record metadata position. The tree-shaker has been updated to know how to remove the metadata. [email protected] Review-Url: https://codereview.chromium.org/3003183003 .
1 parent d9ae60e commit eed3b5e

File tree

5 files changed

+51
-13
lines changed

5 files changed

+51
-13
lines changed

runtime/vm/object.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10705,6 +10705,10 @@ void Library::set_toplevel_class(const Class& value) const {
1070510705
StorePointer(&raw_ptr()->toplevel_class_, value.raw());
1070610706
}
1070710707

10708+
void Library::set_metadata(const GrowableObjectArray& value) const {
10709+
StorePointer(&raw_ptr()->metadata_, value.raw());
10710+
}
10711+
1070810712
RawLibrary* Library::ImportLibraryAt(intptr_t index) const {
1070910713
Namespace& import = Namespace::Handle(ImportAt(index));
1071010714
if (import.IsNull()) {

runtime/vm/object.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4051,6 +4051,7 @@ class Library : public Object {
40514051
bool HasExports() const;
40524052
RawArray* loaded_scripts() const { return raw_ptr()->loaded_scripts_; }
40534053
RawGrowableObjectArray* metadata() const { return raw_ptr()->metadata_; }
4054+
void set_metadata(const GrowableObjectArray& value) const;
40544055
RawArray* dictionary() const { return raw_ptr()->dictionary_; }
40554056
void InitClassDictionary() const;
40564057

@@ -4128,6 +4129,7 @@ class Namespace : public Object {
41284129

41294130
FINAL_HEAP_OBJECT_IMPLEMENTATION(Namespace, Object);
41304131
friend class Class;
4132+
friend class Precompiler;
41314133
};
41324134

41334135
// ObjectPool contains constants, immediates and addresses embedded in code

runtime/vm/parser.cc

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4238,7 +4238,7 @@ void Parser::ParseMethodOrConstructor(ClassDesc* members, MemberDesc* method) {
42384238
// the one in the patched class.
42394239
method->metadata_pos = TokenPosition::kNoSource;
42404240
}
4241-
if (FLAG_enable_mirrors && (method->metadata_pos.IsReal())) {
4241+
if (method->metadata_pos.IsReal()) {
42424242
library_.AddFunctionMetadata(func, method->metadata_pos);
42434243
}
42444244
if (method->has_native) {
@@ -4345,7 +4345,7 @@ void Parser::ParseFieldDefinition(ClassDesc* members, MemberDesc* field) {
43454345
// All fields in the patch class are added to the patched class.
43464346
field->metadata_pos = TokenPosition::kNoSource;
43474347
}
4348-
if (FLAG_enable_mirrors && (field->metadata_pos.IsReal())) {
4348+
if ((field->metadata_pos.IsReal())) {
43494349
library_.AddFieldMetadata(class_field, field->metadata_pos);
43504350
}
43514351

@@ -4730,7 +4730,7 @@ void Parser::ParseEnumDeclaration(const GrowableObjectArray& pending_classes,
47304730
library_.AddClass(cls);
47314731
cls.set_is_synthesized_class();
47324732
cls.set_is_enum_class();
4733-
if (FLAG_enable_mirrors && (metadata_pos.IsReal())) {
4733+
if (metadata_pos.IsReal()) {
47344734
library_.AddClassMetadata(cls, tl_owner, metadata_pos);
47354735
}
47364736
cls.set_super_type(Type::Handle(Z, Type::ObjectType()));
@@ -4847,7 +4847,7 @@ void Parser::ParseClassDeclaration(const GrowableObjectArray& pending_classes,
48474847
if (is_abstract) {
48484848
cls.set_is_abstract();
48494849
}
4850-
if (FLAG_enable_mirrors && metadata_pos.IsReal()) {
4850+
if (metadata_pos.IsReal()) {
48514851
library_.AddClassMetadata(cls, tl_owner, metadata_pos);
48524852
}
48534853

@@ -5335,7 +5335,7 @@ void Parser::ParseMixinAppAlias(const GrowableObjectArray& pending_classes,
53355335
}
53365336
ExpectSemicolon();
53375337
pending_classes.Add(mixin_application, Heap::kOld);
5338-
if (FLAG_enable_mirrors && metadata_pos.IsReal()) {
5338+
if (metadata_pos.IsReal()) {
53395339
library_.AddClassMetadata(mixin_application, tl_owner, metadata_pos);
53405340
}
53415341
}
@@ -5483,7 +5483,7 @@ void Parser::ParseTypedef(const GrowableObjectArray& pending_classes,
54835483
// checked in the class finalizer for illegal self references.
54845484
ASSERT(!function_type_alias.is_finalized());
54855485
pending_classes.Add(function_type_alias, Heap::kOld);
5486-
if (FLAG_enable_mirrors && metadata_pos.IsReal()) {
5486+
if (metadata_pos.IsReal()) {
54875487
library_.AddClassMetadata(function_type_alias, tl_owner, metadata_pos);
54885488
}
54895489
}
@@ -5652,7 +5652,7 @@ void Parser::ParseTypeParameters(bool parameterizing_class) {
56525652
index, type_parameter_name, type_parameter_bound, declaration_pos);
56535653
type_parameters_array.Add(
56545654
&AbstractType::ZoneHandle(Z, type_parameter.raw()));
5655-
if (FLAG_enable_mirrors && metadata_pos.IsReal()) {
5655+
if (metadata_pos.IsReal()) {
56565656
library_.AddTypeParameterMetadata(type_parameter, metadata_pos);
56575657
}
56585658
index++;
@@ -5814,7 +5814,7 @@ void Parser::ParseTopLevelVariable(TopLevel* top_level,
58145814
field.SetStaticValue(Object::null_instance(), true);
58155815
top_level->AddField(field);
58165816
library_.AddObject(field, var_name);
5817-
if (FLAG_enable_mirrors && metadata_pos.IsReal()) {
5817+
if (metadata_pos.IsReal()) {
58185818
library_.AddFieldMetadata(field, metadata_pos);
58195819
}
58205820
if (CurrentToken() == Token::kASSIGN) {
@@ -6012,7 +6012,7 @@ void Parser::ParseTopLevelFunction(TopLevel* top_level,
60126012
toplevel_cls.RemoveFunction(replaced_func);
60136013
library_.ReplaceObject(func, func_name);
60146014
}
6015-
if (FLAG_enable_mirrors && metadata_pos.IsReal()) {
6015+
if (metadata_pos.IsReal()) {
60166016
library_.AddFunctionMetadata(func, metadata_pos);
60176017
}
60186018
}
@@ -6172,7 +6172,7 @@ void Parser::ParseTopLevelAccessor(TopLevel* top_level,
61726172
toplevel_cls.RemoveFunction(replaced_func);
61736173
library_.ReplaceObject(func, accessor_name);
61746174
}
6175-
if (FLAG_enable_mirrors && metadata_pos.IsReal()) {
6175+
if (metadata_pos.IsReal()) {
61766176
library_.AddFunctionMetadata(func, metadata_pos);
61776177
}
61786178
}
@@ -6381,7 +6381,7 @@ void Parser::ParseLibraryImportExport(const Object& tl_owner,
63816381

63826382
Namespace& ns =
63836383
Namespace::Handle(Z, Namespace::New(library, show_names, hide_names));
6384-
if (FLAG_enable_mirrors && metadata_pos.IsReal()) {
6384+
if (metadata_pos.IsReal()) {
63856385
ns.AddMetadata(tl_owner, metadata_pos);
63866386
}
63876387

@@ -6468,7 +6468,7 @@ void Parser::ParseLibraryDefinition(const Object& tl_owner) {
64686468
ReportError("patch cannot override library name");
64696469
}
64706470
ParseLibraryName();
6471-
if (FLAG_enable_mirrors && metadata_pos.IsReal()) {
6471+
if (metadata_pos.IsReal()) {
64726472
library_.AddLibraryMetadata(tl_owner, metadata_pos);
64736473
}
64746474
rewind_pos = TokenPos();
@@ -8050,7 +8050,7 @@ AstNode* Parser::ParseFunctionStatement(bool is_literal) {
80508050
// The result type may refer to the function's type parameters,
80518051
// but was not parsed in the scope of the function. Adjust.
80528052
result_type.SetScopeFunction(function);
8053-
if (FLAG_enable_mirrors && metadata_pos.IsReal()) {
8053+
if (metadata_pos.IsReal()) {
80548054
library_.AddFunctionMetadata(function, metadata_pos);
80558055
}
80568056
}

runtime/vm/precompiler.cc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ void Precompiler::DoCompileAll(
482482
I->object_store()->set_async_star_move_next_helper(null_function);
483483
I->object_store()->set_complete_on_async_return(null_function);
484484
I->object_store()->set_async_star_stream_controller(null_class);
485+
DropMetadata();
485486
DropLibraryEntries();
486487
}
487488
DropClasses();
@@ -1968,6 +1969,36 @@ void Precompiler::TraceTypesFromRetainedClasses() {
19681969
}
19691970
}
19701971

1972+
void Precompiler::DropMetadata() {
1973+
Library& lib = Library::Handle(Z);
1974+
const GrowableObjectArray& null_growable_list =
1975+
GrowableObjectArray::Handle(Z);
1976+
Array& dependencies = Array::Handle(Z);
1977+
Namespace& ns = Namespace::Handle(Z);
1978+
const Field& null_field = Field::Handle(Z);
1979+
1980+
for (intptr_t i = 0; i < libraries_.Length(); i++) {
1981+
lib ^= libraries_.At(i);
1982+
lib.set_metadata(null_growable_list);
1983+
1984+
dependencies = lib.imports();
1985+
for (intptr_t j = 0; j < dependencies.Length(); j++) {
1986+
ns ^= dependencies.At(j);
1987+
if (!ns.IsNull()) {
1988+
ns.set_metadata_field(null_field);
1989+
}
1990+
}
1991+
1992+
dependencies = lib.exports();
1993+
for (intptr_t j = 0; j < dependencies.Length(); j++) {
1994+
ns ^= dependencies.At(j);
1995+
if (!ns.IsNull()) {
1996+
ns.set_metadata_field(null_field);
1997+
}
1998+
}
1999+
}
2000+
}
2001+
19712002
void Precompiler::DropLibraryEntries() {
19722003
Library& lib = Library::Handle(Z);
19732004
Array& dict = Array::Handle(Z);

runtime/vm/precompiler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ class Precompiler : public ValueObject {
390390
void DropTypes();
391391
void DropTypeArguments();
392392
void DropScriptData();
393+
void DropMetadata();
393394
void DropLibraryEntries();
394395
void DropClasses();
395396
void DropLibraries();

0 commit comments

Comments
 (0)