Skip to content

Commit 0908a80

Browse files
johnniwintherCommit Queue
authored andcommitted
[cfe] Move check functionality to extension
This moves the check functionality from SourceLibraryBuilder to an extension on ProblemReporting. These functions don't really have anything to do with the SourceLibraryBuilder other than it implements the ProblemReporting interface. This change makes it clear what the dependencies actually are. Change-Id: If3f3b9b9417c36ee52e0acf4bf592fec2ad53db4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/449120 Reviewed-by: Chloe Stefantsova <[email protected]> Commit-Queue: Johnni Winther <[email protected]>
1 parent 3055e89 commit 0908a80

33 files changed

+975
-833
lines changed

pkg/front_end/lib/src/base/messages.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,35 @@ class LibraryProblemReporting implements ProblemReporting {
105105
@override
106106
String toString() => '$runtimeType(fileUri=$_fileUri)';
107107
}
108+
109+
abstract class ProblemReportingHelper {
110+
/// Assert that a compile-time error was reported during [expectedPhase] of
111+
/// compilation.
112+
///
113+
/// The parameters [location] and [originalStackTrace] are supposed to help to
114+
/// locate the place where the expectation was declared.
115+
///
116+
/// To avoid spending resources on stack trace computations, it is recommended
117+
/// to wrap the calls to [assertProblemReportedElsewhere] into `assert`s.
118+
bool assertProblemReportedElsewhere(
119+
String location, {
120+
required CompilationPhaseForProblemReporting expectedPhase,
121+
});
122+
}
123+
124+
/// This enum is used to mark the expected compilation phase for a compile-time
125+
/// error to be reported.
126+
enum CompilationPhaseForProblemReporting {
127+
/// The outline building phase.
128+
///
129+
/// The outline building phase includes outline expressions, such as default
130+
/// values of parameters, annotations, and initializers of top-level constant
131+
/// fields.
132+
outline,
133+
134+
/// The body building phase.
135+
///
136+
/// The body building phase includes initializers of non-constant fields,
137+
/// bodies of method, getters, setters, constructors, etc.
138+
bodyBuilding,
139+
}

pkg/front_end/lib/src/base/scope.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:kernel/ast.dart';
66
import 'package:kernel/class_hierarchy.dart';
77
import 'package:kernel/type_environment.dart';
88

9+
import '../api_prototype/experimental_flags.dart';
910
import '../builder/builder.dart';
1011
import '../builder/compilation_unit.dart';
1112
import '../builder/declaration_builders.dart';
@@ -505,7 +506,8 @@ mixin ErroneousMemberBuilderMixin implements SourceMemberBuilder {
505506
@override
506507
// Coverage-ignore(suite): Not run.
507508
void checkTypes(
508-
SourceLibraryBuilder library,
509+
ProblemReporting problemReporting,
510+
LibraryFeatures libraryFeatures,
509511
NameSpace nameSpace,
510512
TypeEnvironment typeEnvironment,
511513
) {

pkg/front_end/lib/src/builder/named_type_builder.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ import '../base/messages.dart'
3434
codeSupertypeIsTypeParameter,
3535
codeTypeArgumentMismatch,
3636
codeTypeArgumentsOnTypeVariable,
37-
codeTypeNotFound;
37+
codeTypeNotFound,
38+
CompilationPhaseForProblemReporting;
3839
import '../base/scope.dart';
3940
import '../base/uris.dart';
4041
import '../dill/dill_class_builder.dart';

pkg/front_end/lib/src/fragment/constructor/declaration.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import '../../kernel/body_builder.dart';
2727
import '../../kernel/body_builder_context.dart';
2828
import '../../kernel/kernel_helper.dart';
2929
import '../../kernel/type_algorithms.dart';
30+
import '../../source/check_helper.dart';
3031
import '../../source/name_scheme.dart';
3132
import '../../source/source_class_builder.dart';
3233
import '../../source/source_constructor_builder.dart';
@@ -85,7 +86,7 @@ abstract class ConstructorDeclaration {
8586
});
8687

8788
void checkTypes(
88-
SourceLibraryBuilder libraryBuilder,
89+
ProblemReporting problemReporting,
8990
NameSpace nameSpace,
9091
TypeEnvironment typeEnvironment,
9192
);
@@ -666,13 +667,13 @@ mixin _ConstructorDeclarationMixin
666667

667668
@override
668669
void checkTypes(
669-
SourceLibraryBuilder libraryBuilder,
670+
ProblemReporting problemReporting,
670671
NameSpace nameSpace,
671672
TypeEnvironment typeEnvironment,
672673
) {
673-
libraryBuilder.checkInitializersInFormals(
674-
formals,
675-
typeEnvironment,
674+
problemReporting.checkInitializersInFormals(
675+
formals: formals,
676+
typeEnvironment: typeEnvironment,
676677
isAbstract: false,
677678
isExternal: isExternal,
678679
);
@@ -1473,7 +1474,7 @@ mixin _SyntheticConstructorDeclarationMixin implements ConstructorDeclaration {
14731474

14741475
@override
14751476
void checkTypes(
1476-
SourceLibraryBuilder libraryBuilder,
1477+
ProblemReporting problemReporting,
14771478
NameSpace nameSpace,
14781479
TypeEnvironment typeEnvironment,
14791480
) {}

pkg/front_end/lib/src/fragment/enum_element.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class EnumElementDeclaration
213213

214214
@override
215215
void checkFieldTypes(
216-
SourceLibraryBuilder libraryBuilder,
216+
ProblemReporting problemReporting,
217217
TypeEnvironment typeEnvironment,
218218
SourcePropertyBuilder? setterBuilder,
219219
) {}
@@ -227,7 +227,8 @@ class EnumElementDeclaration
227227

228228
@override
229229
void checkGetterTypes(
230-
SourceLibraryBuilder libraryBuilder,
230+
ProblemReporting problemReporting,
231+
LibraryFeatures libraryFeatures,
231232
TypeEnvironment typeEnvironment,
232233
SourcePropertyBuilder? setterBuilder,
233234
) {}

pkg/front_end/lib/src/fragment/factory/declaration.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import '../../fragment/fragment.dart';
1818
import '../../kernel/body_builder_context.dart';
1919
import '../../kernel/kernel_helper.dart';
2020
import '../../kernel/type_algorithms.dart';
21+
import '../../source/check_helper.dart';
2122
import '../../source/name_scheme.dart';
2223
import '../../source/source_factory_builder.dart';
2324
import '../../source/source_function_builder.dart';
@@ -78,7 +79,7 @@ abstract class FactoryDeclaration {
7879
});
7980

8081
void checkTypes(
81-
SourceLibraryBuilder library,
82+
ProblemReporting problemReporting,
8283
NameSpace nameSpace,
8384
TypeEnvironment typeEnvironment,
8485
);
@@ -285,17 +286,17 @@ class FactoryDeclarationImpl
285286

286287
@override
287288
void checkTypes(
288-
SourceLibraryBuilder library,
289+
ProblemReporting problemReporting,
289290
NameSpace nameSpace,
290291
TypeEnvironment typeEnvironment,
291292
) {
292293
if (_fragment.redirectionTarget != null) {
293294
// Default values are not required on redirecting factory constructors so
294295
// we don't call [checkInitializersInFormals].
295296
} else {
296-
library.checkInitializersInFormals(
297-
_fragment.formals,
298-
typeEnvironment,
297+
problemReporting.checkInitializersInFormals(
298+
formals: _fragment.formals,
299+
typeEnvironment: typeEnvironment,
299300
isAbstract: _fragment.modifiers.isAbstract,
300301
isExternal: _fragment.modifiers.isExternal,
301302
);

pkg/front_end/lib/src/fragment/factory/encoding.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:kernel/type_environment.dart';
99

1010
import '../../base/identifiers.dart';
1111
import '../../base/lookup_result.dart';
12+
import '../../base/messages.dart';
1213
import '../../base/problems.dart' show unexpected, unhandled;
1314
import '../../builder/builder.dart';
1415
import '../../builder/constructor_builder.dart';
@@ -21,7 +22,6 @@ import '../../builder/named_type_builder.dart';
2122
import '../../builder/nullability_builder.dart';
2223
import '../../builder/omitted_type_builder.dart';
2324
import '../../builder/type_builder.dart';
24-
import '../../codes/cfe_codes.dart';
2525
import '../../dill/dill_extension_type_member_builder.dart';
2626
import '../../dill/dill_member_builder.dart';
2727
import '../../fragment/fragment.dart';
@@ -33,8 +33,7 @@ import '../../source/redirecting_factory_body.dart';
3333
import '../../source/source_factory_builder.dart';
3434
import '../../source/source_function_builder.dart';
3535
import '../../source/source_library_builder.dart' show SourceLibraryBuilder;
36-
import '../../source/source_loader.dart'
37-
show CompilationPhaseForProblemReporting, SourceLoader;
36+
import '../../source/source_loader.dart' show SourceLoader;
3837
import '../../source/source_member_builder.dart';
3938
import '../../source/source_type_parameter_builder.dart';
4039
import '../../source/type_parameter_factory.dart';

pkg/front_end/lib/src/fragment/field/declaration.dart

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:kernel/class_hierarchy.dart';
99
import 'package:kernel/core_types.dart';
1010
import 'package:kernel/type_environment.dart';
1111

12+
import '../../api_prototype/experimental_flags.dart';
1213
import '../../base/constant_context.dart';
1314
import '../../base/messages.dart';
1415
import '../../base/problems.dart';
@@ -21,6 +22,7 @@ import '../../builder/property_builder.dart';
2122
import '../../builder/type_builder.dart';
2223
import '../../kernel/body_builder.dart';
2324
import '../../kernel/body_builder_context.dart';
25+
import '../../source/check_helper.dart';
2426
import '../../kernel/hierarchy/class_member.dart';
2527
import '../../kernel/hierarchy/members_builder.dart';
2628
import '../../kernel/implicit_field_type.dart';
@@ -73,7 +75,7 @@ abstract class FieldDeclaration {
7375
void createFieldEncoding(SourcePropertyBuilder builder);
7476

7577
void checkFieldTypes(
76-
SourceLibraryBuilder libraryBuilder,
78+
ProblemReporting problemReporting,
7779
TypeEnvironment typeEnvironment,
7880
SourcePropertyBuilder? setterBuilder,
7981
);
@@ -437,12 +439,12 @@ class RegularFieldDeclaration
437439

438440
@override
439441
void checkFieldTypes(
440-
SourceLibraryBuilder libraryBuilder,
442+
ProblemReporting problemReporting,
441443
TypeEnvironment typeEnvironment,
442444
SourcePropertyBuilder? setterBuilder,
443445
) {
444-
libraryBuilder.checkTypesInField(
445-
typeEnvironment,
446+
problemReporting.checkTypesInField(
447+
typeEnvironment: typeEnvironment,
446448
isInstanceMember: builder.isDeclarationInstanceMember,
447449
isLate: isLate,
448450
isExternal: _fragment.modifiers.isExternal,
@@ -745,7 +747,8 @@ class RegularFieldDeclaration
745747

746748
@override
747749
void checkGetterTypes(
748-
SourceLibraryBuilder libraryBuilder,
750+
ProblemReporting problemReporting,
751+
LibraryFeatures libraryFeatures,
749752
TypeEnvironment typeEnvironment,
750753
SourcePropertyBuilder? setterBuilder,
751754
) {}
@@ -758,7 +761,7 @@ class RegularFieldDeclaration
758761

759762
@override
760763
void checkSetterTypes(
761-
SourceLibraryBuilder libraryBuilder,
764+
ProblemReporting problemReporting,
762765
TypeEnvironment typeEnvironment,
763766
) {}
764767

pkg/front_end/lib/src/fragment/fragment.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import 'package:kernel/transformations/flags.dart';
1212
import 'package:kernel/type_algebra.dart';
1313
import 'package:kernel/type_environment.dart';
1414

15+
import '../api_prototype/experimental_flags.dart';
1516
import '../api_prototype/lowering_predicates.dart';
1617
import '../base/constant_context.dart';
1718
import '../base/local_scope.dart';
@@ -33,6 +34,7 @@ import '../builder/type_builder.dart';
3334
import '../builder/variable_builder.dart';
3435
import '../kernel/body_builder.dart';
3536
import '../kernel/body_builder_context.dart';
37+
import '../source/check_helper.dart';
3638
import '../kernel/constness.dart';
3739
import '../kernel/expression_generator_helper.dart';
3840
import '../kernel/hierarchy/class_member.dart';

pkg/front_end/lib/src/fragment/getter/declaration.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:kernel/ast.dart';
66
import 'package:kernel/class_hierarchy.dart';
77
import 'package:kernel/type_environment.dart';
88

9+
import '../../api_prototype/experimental_flags.dart';
910
import '../../base/local_scope.dart';
1011
import '../../base/messages.dart';
1112
import '../../base/scope.dart';
@@ -61,7 +62,8 @@ abstract class GetterDeclaration {
6162
});
6263

6364
void checkGetterTypes(
64-
SourceLibraryBuilder libraryBuilder,
65+
ProblemReporting problemReporting,
66+
LibraryFeatures libraryFeatures,
6567
TypeEnvironment typeEnvironment,
6668
SourcePropertyBuilder? setterBuilder,
6769
);
@@ -198,12 +200,14 @@ class RegularGetterDeclaration
198200

199201
@override
200202
void checkGetterTypes(
201-
SourceLibraryBuilder libraryBuilder,
203+
ProblemReporting problemReporting,
204+
LibraryFeatures libraryFeatures,
202205
TypeEnvironment typeEnvironment,
203206
SourcePropertyBuilder? setterBuilder,
204207
) {
205208
_encoding.checkTypes(
206-
libraryBuilder,
209+
problemReporting,
210+
libraryFeatures,
207211
typeEnvironment,
208212
setterBuilder,
209213
isAbstract: _fragment.modifiers.isAbstract,

0 commit comments

Comments
 (0)