Skip to content

Commit

Permalink
[cfe] Ensure getter references for fragments
Browse files Browse the repository at this point in the history
Change-Id: I7e0fbe232b0d8638b61b1f26f3c23c634c6ce4fe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385724
Reviewed-by: Jens Johansen <[email protected]>
Commit-Queue: Johnni Winther <[email protected]>
  • Loading branch information
johnniwinther authored and Commit Queue committed Sep 23, 2024
1 parent f98a84a commit 200cf86
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 39 deletions.
61 changes: 32 additions & 29 deletions pkg/front_end/lib/src/source/source_builder_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,8 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult {

_constructorReferences.clear();

_addFragment(declarationFragment);
_addFragment(declarationFragment,
getterReference: referencesFromIndexedClass?.reference);

offsetMap.registerNamedDeclarationFragment(identifier, declarationFragment);
}
Expand Down Expand Up @@ -1044,7 +1045,8 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult {

_constructorReferences.clear();

_addFragment(declarationFragment);
_addFragment(declarationFragment,
getterReference: _indexedContainer?.reference);

offsetMap.registerNamedDeclarationFragment(identifier, declarationFragment);
}
Expand Down Expand Up @@ -1085,28 +1087,32 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult {
_problemReporting, typeVariables,
ownerName: name, allowNameConflict: false);

_addFragment(new NamedMixinApplicationFragment(
name: name,
fileUri: _compilationUnit.fileUri,
startCharOffset: startCharOffset,
charOffset: charOffset,
charEndOffset: charEndOffset,
modifiers: modifiers,
metadata: metadata,
typeParameters: typeVariables,
supertype: supertype,
mixins: mixinApplication,
interfaces: interfaces,
isAugmentation: isAugmentation,
isBase: isBase,
isFinal: isFinal,
isInterface: isInterface,
isMacro: isMacro,
isMixinClass: isMixinClass,
isSealed: isSealed,
compilationUnitScope: _compilationUnitScope,
indexedLibrary: indexedLibrary,
));
_addFragment(
new NamedMixinApplicationFragment(
name: name,
fileUri: _compilationUnit.fileUri,
startCharOffset: startCharOffset,
charOffset: charOffset,
charEndOffset: charEndOffset,
modifiers: modifiers,
metadata: metadata,
typeParameters: typeVariables,
supertype: supertype,
mixins: mixinApplication,
interfaces: interfaces,
isAugmentation: isAugmentation,
isBase: isBase,
isFinal: isFinal,
isInterface: isInterface,
isMacro: isMacro,
isMixinClass: isMixinClass,
isSealed: isSealed,
compilationUnitScope: _compilationUnitScope,
indexedLibrary: indexedLibrary,
),
// References are looked up in [BuilderFactoryImpl.applyMixin] when the
// [SourceClassBuilder] is created.
getterReference: null);
}

static TypeBuilder? applyMixins(
Expand Down Expand Up @@ -1481,10 +1487,7 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult {
fileUri: _compilationUnit.fileUri,
fileOffset: charOffset,
reference: reference);
_addFragment(fragment);
if (reference != null) {
loader.fragmentsCreatedWithReferences[reference] = fragment;
}
_addFragment(fragment, getterReference: reference);
}

@override
Expand Down Expand Up @@ -2603,7 +2606,7 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult {
}

void _addFragment(Fragment fragment,
{Reference? getterReference, Reference? setterReference}) {
{required Reference? getterReference, Reference? setterReference}) {
if (getterReference != null) {
loader.fragmentsCreatedWithReferences[getterReference] = fragment;
}
Expand Down
14 changes: 10 additions & 4 deletions pkg/front_end/testcases/incremental/export_through_dill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ worlds:
sources:
main.dart: |
import 'lib1.dart';
void method(Foo foo) {}
void method(Typedef t, Enum e, Mixin m, NamedMixinApplication a) {}
lib1.dart: |
export 'lib2.dart';
lib2.dart: |
typedef Foo = int;
typedef Typedef = int;
enum Enum { a, b }
mixin Mixin {}
class NamedMixinApplication = Object with Mixin;
expectedLibraryCount: 3

- entry: main.dart
Expand All @@ -22,8 +25,11 @@ worlds:
sources:
main.dart: |
import 'lib1.dart';
void method(Foo foo) {}
void method(Typedef t, Enum e, Mixin m, NamedMixinApplication a) {}
lib2.dart: |
typedef Foo = int;
typedef Typedef = int;
enum Enum { a, b }
mixin Mixin {}
class NamedMixinApplication = Object with Mixin;
expectedLibraryCount: 3
advancedInvalidation: bodiesOnly
Original file line number Diff line number Diff line change
@@ -1,17 +1,54 @@
main = <No Member>;
library from "org-dartlang-test:///lib1.dart" as lib1 {
additionalExports = (lib2::Foo)
additionalExports = (lib2::Enum,
lib2::Mixin,
lib2::NamedMixinApplication,
lib2::Typedef)

export "org-dartlang-test:///lib2.dart";

}
library from "org-dartlang-test:///lib2.dart" as lib2 {

typedef Foo = dart.core::int;
typedef Typedef = dart.core::int;
class Enum extends dart.core::_Enum /*isEnum*/ {
static const field dart.core::List<lib2::Enum> values = #C7;
enum-element static const field lib2::Enum a = #C3;
enum-element static const field lib2::Enum b = #C6;
const synthetic constructor •(dart.core::int #index, dart.core::String #name) → lib2::Enum
: super dart.core::_Enum::•(#index, #name)
;
method _enumToString() → dart.core::String
return "Enum.${this.{dart.core::_Enum::_name}{dart.core::String}}";
}
abstract class Mixin extends dart.core::Object /*isMixinDeclaration*/ {
}
class NamedMixinApplication extends dart.core::Object implements lib2::Mixin /*isEliminatedMixin,hasConstConstructor*/ {
const synthetic constructor •() → lib2::NamedMixinApplication
: super dart.core::Object::•()
;
}
}
library from "org-dartlang-test:///main.dart" as main {

import "org-dartlang-test:///lib1.dart";

static method method(dart.core::int foo) → void {}
static method method(dart.core::int t, lib2::Enum e, lib2::Mixin m, lib2::NamedMixinApplication a) → void {}
}
constants {
#C1 = 0
#C2 = "a"
#C3 = lib2::Enum {index:#C1, _name:#C2}
#C4 = 1
#C5 = "b"
#C6 = lib2::Enum {index:#C4, _name:#C5}
#C7 = <lib2::Enum>[#C3, #C6]
}


Constructor coverage from constants:
org-dartlang-test:///lib2.dart:
- Enum. (from org-dartlang-test:///lib2.dart:2:6)
- _Enum. (from org-dartlang-sdk:///sdk/lib/core/enum.dart)
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart)

Original file line number Diff line number Diff line change
@@ -1,17 +1,54 @@
main = <No Member>;
library from "org-dartlang-test:///lib1.dart" as lib1 {
additionalExports = (lib2::Foo)
additionalExports = (lib2::Enum,
lib2::Mixin,
lib2::NamedMixinApplication,
lib2::Typedef)

export "org-dartlang-test:///lib2.dart";

}
library from "org-dartlang-test:///lib2.dart" as lib2 {

typedef Foo = dart.core::int;
typedef Typedef = dart.core::int;
class Enum extends dart.core::_Enum /*isEnum*/ {
static const field dart.core::List<lib2::Enum> values = #C7;
enum-element static const field lib2::Enum a = #C3;
enum-element static const field lib2::Enum b = #C6;
const synthetic constructor •(dart.core::int #index, dart.core::String #name) → lib2::Enum
: super dart.core::_Enum::•(#index, #name)
;
method _enumToString() → dart.core::String
return "Enum.${this.{dart.core::_Enum::_name}{dart.core::String}}";
}
abstract class Mixin extends dart.core::Object /*isMixinDeclaration*/ {
}
class NamedMixinApplication extends dart.core::Object implements lib2::Mixin /*isEliminatedMixin,hasConstConstructor*/ {
const synthetic constructor •() → lib2::NamedMixinApplication
: super dart.core::Object::•()
;
}
}
library from "org-dartlang-test:///main.dart" as main {

import "org-dartlang-test:///lib1.dart";

static method method(dart.core::int foo) → void {}
static method method(dart.core::int t, lib2::Enum e, lib2::Mixin m, lib2::NamedMixinApplication a) → void {}
}
constants {
#C1 = 0
#C2 = "a"
#C3 = lib2::Enum {index:#C1, _name:#C2}
#C4 = 1
#C5 = "b"
#C6 = lib2::Enum {index:#C4, _name:#C5}
#C7 = <lib2::Enum>[#C3, #C6]
}


Constructor coverage from constants:
org-dartlang-test:///lib2.dart:
- Enum. (from org-dartlang-test:///lib2.dart:2:6)
- _Enum. (from org-dartlang-sdk:///sdk/lib/core/enum.dart)
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart)

0 comments on commit 200cf86

Please sign in to comment.