Skip to content

Commit fc1bd94

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Move to ConstructorElementImpl flags 'isCycleFree' and 'isConstantEvaluated'.
Change-Id: Ie48daf0fddc758615b92e663911a70afd5e2db8f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/448882 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 83b2c5d commit fc1bd94

File tree

4 files changed

+15
-19
lines changed

4 files changed

+15
-19
lines changed

pkg/analyzer/lib/src/dart/constant/compute.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ class _ConstantWalker extends graph.DependencyWalker<_ConstantNode> {
6868
for (var node in scc) {
6969
var constant = node.constant;
7070
if (constant is ConstructorElementImpl) {
71-
// TODO(scheglov): move the flag to the element
72-
constant.firstFragment.isCycleFree = false;
71+
constant.isCycleFree = false;
7372
}
7473
_getEvaluationEngine(node).generateCycleError(constantsInCycle, constant);
7574
}

pkg/analyzer/lib/src/dart/constant/constant_verifier.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,8 @@ class ConstantVerifier extends RecursiveAstVisitor<void> {
170170
// Check and report cycles.
171171
// Factory cycles are reported in elsewhere in
172172
// [ErrorVerifier._checkForRecursiveFactoryRedirect].
173-
var element = node.declaredFragment;
174-
if (element is ConstructorFragmentImpl &&
175-
!element.isCycleFree &&
176-
!element.isFactory) {
173+
var element = node.declaredFragment!.element;
174+
if (!element.isCycleFree && !element.isFactory) {
177175
_diagnosticReporter.atNode(
178176
node.returnType,
179177
CompileTimeErrorCode.recursiveConstantConstructor,

pkg/analyzer/lib/src/dart/constant/evaluation.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class ConstantEvaluationEngine {
164164
// the dependency graph to ensure that any constants referred to in
165165
// initializer lists and parameter defaults are evaluated before
166166
// invocations of the constructor.
167-
constant.firstFragment.isConstantEvaluated = true;
167+
constant.isConstantEvaluated = true;
168168
}
169169
} else if (constant is ElementAnnotationImpl) {
170170
var constNode = constant.annotationAst;
@@ -3560,7 +3560,7 @@ class _InstanceCreationEvaluator {
35603560
);
35613561
}
35623562

3563-
if (!constructor.baseElement.firstFragment.isCycleFree) {
3563+
if (!constructor.baseElement.isCycleFree) {
35643564
// It's not safe to evaluate this constructor, so bail out.
35653565
//
35663566
// Instead of reporting an error at the call-sites, we will report an

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,16 @@ class ConstructorElementImpl extends ExecutableElementImpl
628628
// So, ideally we should have some kind of "either" or "variant" here.
629629
InternalConstructorElement? _superConstructor;
630630

631+
/// For every constructor we initially set this flag to `true`, and then
632+
/// set it to `false` during computing constant values if we detect that it
633+
/// is a part of a cycle.
634+
@trackedInternal
635+
bool isCycleFree = true;
636+
637+
@override
638+
@trackedInternal
639+
bool isConstantEvaluated = false;
640+
631641
ConstructorElementImpl({
632642
required this.name,
633643
required this.reference,
@@ -684,9 +694,6 @@ class ConstructorElementImpl extends ExecutableElementImpl
684694
@override
685695
bool get isConst => _firstFragment.isConst;
686696

687-
@override
688-
bool get isConstantEvaluated => _firstFragment.isConstantEvaluated;
689-
690697
@override
691698
bool get isDefaultConstructor => _firstFragment.isDefaultConstructor;
692699

@@ -840,14 +847,6 @@ class ConstructorFragmentImpl extends ExecutableFragmentImpl
840847
@override
841848
ConstructorFragmentImpl? nextFragment;
842849

843-
/// For every constructor we initially set this flag to `true`, and then
844-
/// set it to `false` during computing constant values if we detect that it
845-
/// is a part of a cycle.
846-
bool isCycleFree = true;
847-
848-
/// Return whether this constant is evaluated.
849-
bool isConstantEvaluated = false;
850-
851850
/// Initialize a newly created constructor element to have the given [name]
852851
/// and [offset].
853852
ConstructorFragmentImpl({required this.name});

0 commit comments

Comments
 (0)