Skip to content

Commit ad92d28

Browse files
johnniwintherCommit Queue
authored andcommitted
[cfe] Remove SourceProcedureBuilder
This removes the SourceProcedureBuilder. This is achieved by adding SyntheticMethodBuilder for creating synthesized methods, currently only used for `_enumToString` in enums, changin the creation of Expression for expression compilation to avoid the need for a SourceMemberBuilder. Change-Id: I81fe891ec26a979b04e6cdd4c2b906bd945d4bde Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/400980 Commit-Queue: Johnni Winther <[email protected]> Reviewed-by: Chloe Stefantsova <[email protected]>
1 parent 0fd7cd0 commit ad92d28

18 files changed

+473
-1230
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,18 +2126,19 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
21262126
lastGoodKernelTarget.objectClassBuilder,
21272127
lastGoodKernelTarget.dynamicType);
21282128
debugLibrary.buildOutlineNodes(lastGoodKernelTarget.loader.coreLibrary);
2129+
2130+
Procedure procedure = new Procedure(
2131+
new Name(syntheticProcedureName), ProcedureKind.Method, parameters,
2132+
isStatic: isStatic, fileUri: debugLibrary.fileUri);
2133+
21292134
Expression compiledExpression = await lastGoodKernelTarget.loader
21302135
.buildExpression(
21312136
debugLibrary,
21322137
className ?? extensionName,
21332138
(className != null && !isStatic) || extensionThis != null,
2134-
parameters,
2139+
procedure,
21352140
extensionThis);
21362141

2137-
Procedure procedure = new Procedure(
2138-
new Name(syntheticProcedureName), ProcedureKind.Method, parameters,
2139-
isStatic: isStatic, fileUri: debugLibrary.fileUri);
2140-
21412142
parameters.body = new ReturnStatement(compiledExpression)
21422143
..parent = parameters;
21432144

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,6 @@ abstract class BuilderImpl implements Builder {
336336
bool get isSetter => false;
337337

338338
@override
339-
// Coverage-ignore(suite): Not run.
340339
bool get isStatic => false;
341340

342341
@override

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ abstract class BuilderClassMember implements ClassMember {
209209
bool get isField => memberBuilder.isField;
210210

211211
@override
212+
// Coverage-ignore(suite): Not run.
212213
bool get isGetter => memberBuilder.isGetter;
213214

214215
@override
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:kernel/ast.dart';
6+
7+
import 'member_builder.dart';
8+
9+
abstract class MethodBuilder implements MemberBuilder {
10+
@override
11+
Reference get invokeTargetReference;
12+
}

pkg/front_end/lib/src/kernel/body_builder_context.dart

Lines changed: 16 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@ import '../source/source_field_builder.dart';
2929
import '../source/source_function_builder.dart';
3030
import '../source/source_library_builder.dart';
3131
import '../source/source_member_builder.dart';
32-
import '../source/source_procedure_builder.dart';
3332
import '../source/source_type_alias_builder.dart';
3433
import '../type_inference/inference_results.dart'
3534
show InitializerInferenceResult;
3635
import '../type_inference/type_inferrer.dart' show TypeInferrer;
37-
import '../type_inference/type_schema.dart' show UnknownType;
3836
import 'expression_generator_helper.dart';
3937
import 'internal_ast.dart';
4038

@@ -841,44 +839,6 @@ mixin _FunctionBodyBuilderContextMixin<T extends SourceFunctionBuilder>
841839
}
842840
}
843841

844-
mixin _ProcedureBodyBuilderContextMixin<T extends SourceProcedureBuilder>
845-
implements BodyBuilderContext {
846-
T get _member;
847-
848-
@override
849-
// Coverage-ignore(suite): Not run.
850-
void setAsyncModifier(AsyncMarker asyncModifier) {
851-
_member.asyncModifier = asyncModifier;
852-
}
853-
854-
@override
855-
// Coverage-ignore(suite): Not run.
856-
DartType get returnTypeContext {
857-
final bool isReturnTypeUndeclared =
858-
_member.returnType is OmittedTypeBuilder &&
859-
_member.function.returnType is DynamicType;
860-
return isReturnTypeUndeclared
861-
? const UnknownType()
862-
: _member.function.returnType;
863-
}
864-
}
865-
866-
class ProcedureBodyBuilderContext extends BodyBuilderContext
867-
with
868-
_MemberBodyBuilderContext<SourceProcedureBuilder>,
869-
_FunctionBodyBuilderContextMixin<SourceProcedureBuilder>,
870-
_ProcedureBodyBuilderContextMixin<SourceProcedureBuilder> {
871-
@override
872-
final SourceProcedureBuilder _member;
873-
874-
@override
875-
final Member _builtMember;
876-
877-
ProcedureBodyBuilderContext(this._member, this._builtMember)
878-
: super(_member.libraryBuilder, _member.declarationBuilder,
879-
isDeclarationInstanceMember: _member.isDeclarationInstanceMember);
880-
}
881-
882842
mixin _ConstructorBodyBuilderContextMixin<T extends ConstructorDeclaration>
883843
implements BodyBuilderContext {
884844
T get _member;
@@ -1058,17 +1018,25 @@ class ParameterBodyBuilderContext extends BodyBuilderContext {
10581018
}
10591019

10601020
// Coverage-ignore(suite): Not run.
1061-
class ExpressionCompilerProcedureBodyBuildContext extends BodyBuilderContext
1062-
with _MemberBodyBuilderContext<SourceProcedureBuilder> {
1063-
@override
1064-
final SourceProcedureBuilder _member;
1065-
1066-
@override
1067-
final Member _builtMember;
1021+
class ExpressionCompilerProcedureBodyBuildContext extends BodyBuilderContext {
1022+
final Procedure _procedure;
10681023

10691024
ExpressionCompilerProcedureBodyBuildContext(
1070-
DietListener listener, this._member, this._builtMember,
1025+
DietListener listener, this._procedure,
10711026
{required bool isDeclarationInstanceMember})
10721027
: super(listener.libraryBuilder, listener.currentDeclaration,
10731028
isDeclarationInstanceMember: isDeclarationInstanceMember);
1029+
1030+
@override
1031+
AugmentSuperTarget? get augmentSuperTarget {
1032+
return null;
1033+
}
1034+
1035+
@override
1036+
int get memberNameOffset => _procedure.fileOffset;
1037+
1038+
@override
1039+
void registerSuperCall() {
1040+
_procedure.transformerFlags |= TransformerFlag.superCalls;
1041+
}
10741042
}

pkg/front_end/lib/src/kernel/hierarchy/class_member.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ abstract class ClassMember {
290290

291291
/// The interface member corresponding to this member.
292292
///
293-
/// If this member is declared on the source, the interface member is
293+
/// If this member is declared in the source, the interface member is
294294
/// the member itself. For instance
295295
///
296296
/// abstract class Class {

pkg/front_end/lib/src/kernel/macro/introspectors.dart

Lines changed: 3 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import '../../source/source_field_builder.dart';
2222
import '../../source/source_loader.dart';
2323
import '../../source/source_member_builder.dart';
2424
import '../../source/source_method_builder.dart';
25-
import '../../source/source_procedure_builder.dart';
2625
import '../../source/source_property_builder.dart';
2726
import '../hierarchy/hierarchy_builder.dart';
2827
import 'identifiers.dart';
@@ -128,9 +127,7 @@ class MacroIntrospection {
128127

129128
/// Creates the [macro.Declaration] corresponding to [memberBuilder].
130129
macro.Declaration _createMemberDeclaration(MemberBuilder memberBuilder) {
131-
if (memberBuilder is SourceProcedureBuilder) {
132-
return _createFunctionDeclaration(memberBuilder);
133-
} else if (memberBuilder is SourceMethodBuilder) {
130+
if (memberBuilder is SourceMethodBuilder) {
134131
return _createMethodDeclaration(memberBuilder);
135132
} else if (memberBuilder is SourcePropertyBuilder) {
136133
return _createGetterDeclaration(memberBuilder);
@@ -499,78 +496,6 @@ class MacroIntrospection {
499496
return declaration;
500497
}
501498

502-
/// Creates the [macro.FunctionDeclaration] corresponding to [builder].
503-
macro.FunctionDeclaration _createFunctionDeclaration(
504-
SourceProcedureBuilder builder) {
505-
var (
506-
List<macro.FormalParameterDeclarationImpl> positionalParameters,
507-
List<macro.FormalParameterDeclarationImpl> namedParameters
508-
) = _createParameters(builder.libraryBuilder, builder.formals);
509-
510-
macro.ParameterizedTypeDeclaration? definingTypeDeclaration = null;
511-
Builder? parent = builder.parent;
512-
if (parent is ClassBuilder) {
513-
definingTypeDeclaration = getClassDeclaration(parent);
514-
} else if (parent is ExtensionTypeDeclarationBuilder) {
515-
definingTypeDeclaration = getExtensionTypeDeclaration(parent);
516-
}
517-
final macro.LibraryImpl library = getLibrary(builder.libraryBuilder);
518-
macro.FunctionDeclaration declaration;
519-
if (definingTypeDeclaration != null) {
520-
// TODO(johnniwinther): Should static fields be field or variable
521-
// declarations?
522-
declaration = new macro.MethodDeclarationImpl(
523-
id: macro.RemoteInstance.uniqueId,
524-
identifier: new MemberBuilderIdentifier(
525-
memberBuilder: builder,
526-
id: macro.RemoteInstance.uniqueId,
527-
name: builder.name),
528-
library: library,
529-
// TODO(johnniwinther): Provide metadata annotations.
530-
metadata: const [],
531-
definingType:
532-
definingTypeDeclaration.identifier as macro.IdentifierImpl,
533-
// TODO(johnniwinther): Real implementation of hasBody.
534-
hasBody: true,
535-
hasExternal: builder.isExternal,
536-
isGetter: builder.isGetter,
537-
isOperator: builder.isOperator,
538-
isSetter: builder.isSetter,
539-
hasStatic: builder.isStatic,
540-
positionalParameters: positionalParameters,
541-
namedParameters: namedParameters,
542-
returnType: types.getTypeAnnotation(
543-
builder.libraryBuilder, builder.returnType),
544-
// TODO(johnniwinther): Support typeParameters
545-
typeParameters: const []);
546-
} else {
547-
declaration = new macro.FunctionDeclarationImpl(
548-
id: macro.RemoteInstance.uniqueId,
549-
identifier: new MemberBuilderIdentifier(
550-
memberBuilder: builder,
551-
id: macro.RemoteInstance.uniqueId,
552-
name: builder.name),
553-
library: library,
554-
// TODO(johnniwinther): Provide metadata annotations.
555-
metadata: const [],
556-
// TODO(johnniwinther): Real implementation of hasBody.
557-
hasBody: true,
558-
hasExternal: builder.isExternal,
559-
isGetter: builder.isGetter,
560-
isOperator: builder.isOperator,
561-
isSetter: builder.isSetter,
562-
positionalParameters: positionalParameters,
563-
namedParameters: namedParameters,
564-
returnType: types.getTypeAnnotation(
565-
builder.libraryBuilder, builder.returnType),
566-
// TODO(johnniwinther): Support typeParameters
567-
typeParameters: const []);
568-
}
569-
_declarationOffsets[declaration] =
570-
new UriOffset(builder.fileUri, builder.fileOffset);
571-
return declaration;
572-
}
573-
574499
/// Creates the [macro.FunctionDeclaration] corresponding to [builder].
575500
macro.FunctionDeclaration _createMethodDeclaration(
576501
SourceMethodBuilder builder) {
@@ -973,8 +898,7 @@ class _DeclarationPhaseIntrospector extends _TypePhaseIntrospector
973898
classBuilder.fullMemberIterator();
974899
while (iterator.moveNext()) {
975900
SourceMemberBuilder memberBuilder = iterator.current;
976-
if (memberBuilder is SourceProcedureBuilder ||
977-
memberBuilder is SourceMethodBuilder ||
901+
if (memberBuilder is SourceMethodBuilder ||
978902
memberBuilder is SourcePropertyBuilder) {
979903
result.add(_introspection.getMemberDeclaration(memberBuilder)
980904
as macro.MethodDeclaration);
@@ -987,8 +911,7 @@ class _DeclarationPhaseIntrospector extends _TypePhaseIntrospector
987911
extensionTypeDeclarationBuilder.fullMemberIterator();
988912
while (iterator.moveNext()) {
989913
SourceMemberBuilder memberBuilder = iterator.current;
990-
if (memberBuilder is SourceProcedureBuilder ||
991-
memberBuilder is SourceMethodBuilder ||
914+
if (memberBuilder is SourceMethodBuilder ||
992915
memberBuilder is SourcePropertyBuilder) {
993916
result.add(_introspection.getMemberDeclaration(memberBuilder)
994917
as macro.MethodDeclaration);

pkg/front_end/lib/src/kernel/macro/macro.dart

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ import '../../source/source_field_builder.dart';
3232
import '../../source/source_library_builder.dart';
3333
import '../../source/source_loader.dart';
3434
import '../../source/source_method_builder.dart';
35-
import '../../source/source_procedure_builder.dart';
3635
import '../../source/source_property_builder.dart';
3736
import '../../source/source_type_alias_builder.dart';
37+
import '../../source/synthetic_method_builder.dart';
3838
import '../benchmarker.dart' show BenchmarkSubdivides, Benchmarker;
3939
import '../hierarchy/hierarchy_builder.dart';
4040
import 'annotation_parser.dart';
@@ -478,19 +478,7 @@ class MacroApplications {
478478
Iterator<Builder> memberIterator = builder.localMemberIterator();
479479
while (memberIterator.moveNext()) {
480480
Builder memberBuilder = memberIterator.current;
481-
if (memberBuilder is SourceProcedureBuilder) {
482-
List<MacroApplication>? macroApplications = prebuildAnnotations(
483-
enclosingLibrary: libraryBuilder,
484-
scope: builder.scope,
485-
fileUri: memberBuilder.fileUri,
486-
metadataBuilders: memberBuilder.metadata,
487-
currentMacroDeclarations: currentMacroDeclarations);
488-
if (macroApplications != null) {
489-
classMacroApplicationData.memberApplications[memberBuilder] =
490-
new MemberApplicationData(_macroIntrospection, libraryBuilder,
491-
memberBuilder, macroApplications);
492-
}
493-
} else if (memberBuilder is SourceMethodBuilder) {
481+
if (memberBuilder is SourceMethodBuilder) {
494482
List<MacroApplication>? macroApplications = prebuildAnnotations(
495483
enclosingLibrary: libraryBuilder,
496484
scope: builder.scope,
@@ -502,6 +490,8 @@ class MacroApplications {
502490
new MemberApplicationData(_macroIntrospection, libraryBuilder,
503491
memberBuilder, macroApplications);
504492
}
493+
} else if (memberBuilder is SyntheticMethodBuilder) {
494+
// [SyntheticMethodBuilder] doesn't have metadata.
505495
} else if (memberBuilder is SourcePropertyBuilder) {
506496
List<MacroApplication>? macroApplications = prebuildAnnotations(
507497
enclosingLibrary: libraryBuilder,
@@ -570,18 +560,6 @@ class MacroApplications {
570560
libraryMacroApplicationData.classData[builder] =
571561
classMacroApplicationData;
572562
}
573-
} else if (builder is SourceProcedureBuilder) {
574-
List<MacroApplication>? macroApplications = prebuildAnnotations(
575-
enclosingLibrary: libraryBuilder,
576-
scope: libraryBuilder.scope,
577-
fileUri: builder.fileUri,
578-
metadataBuilders: builder.metadata,
579-
currentMacroDeclarations: currentMacroDeclarations);
580-
if (macroApplications != null) {
581-
libraryMacroApplicationData.memberApplications[builder] =
582-
new MemberApplicationData(_macroIntrospection, libraryBuilder,
583-
builder, macroApplications);
584-
}
585563
} else if (builder is SourceMethodBuilder) {
586564
List<MacroApplication>? macroApplications = prebuildAnnotations(
587565
enclosingLibrary: libraryBuilder,
@@ -648,19 +626,6 @@ class MacroApplications {
648626
new MemberApplicationData(_macroIntrospection, libraryBuilder,
649627
memberBuilder, macroApplications);
650628
}
651-
} else if (memberBuilder is SourceProcedureBuilder) {
652-
List<MacroApplication>? macroApplications = prebuildAnnotations(
653-
enclosingLibrary: libraryBuilder,
654-
scope: builder.scope,
655-
fileUri: memberBuilder.fileUri,
656-
metadataBuilders: memberBuilder.metadata,
657-
currentMacroDeclarations: currentMacroDeclarations);
658-
if (macroApplications != null) {
659-
extensionTypeMacroApplicationData
660-
.memberApplications[memberBuilder] =
661-
new MemberApplicationData(_macroIntrospection, libraryBuilder,
662-
memberBuilder, macroApplications);
663-
}
664629
} else if (memberBuilder is SourcePropertyBuilder) {
665630
List<MacroApplication>? macroApplications = prebuildAnnotations(
666631
enclosingLibrary: libraryBuilder,

pkg/front_end/lib/src/source/source_class_builder.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,7 @@ class SourceClassBuilder extends ClassBuilderImpl
11021102
}
11031103
}
11041104

1105+
// Coverage-ignore(suite): Not run.
11051106
void checkVarianceInFunction(Procedure procedure,
11061107
TypeEnvironment typeEnvironment, List<TypeParameter> typeParameters) {
11071108
List<TypeParameter> functionTypeParameters =
@@ -1113,7 +1114,6 @@ class SourceClassBuilder extends ClassBuilderImpl
11131114
DartType returnType = procedure.function.returnType;
11141115

11151116
for (TypeParameter functionParameter in functionTypeParameters) {
1116-
// Coverage-ignore-block(suite): Not run.
11171117
for (TypeParameter typeParameter in typeParameters) {
11181118
Variance typeVariance = Variance.invariant
11191119
.combine(computeVariance(typeParameter, functionParameter.bound));
@@ -1122,7 +1122,6 @@ class SourceClassBuilder extends ClassBuilderImpl
11221122
}
11231123
}
11241124
for (VariableDeclaration formal in positionalParameters) {
1125-
// Coverage-ignore-block(suite): Not run.
11261125
if (!formal.isCovariantByDeclaration) {
11271126
for (TypeParameter typeParameter in typeParameters) {
11281127
Variance formalVariance = Variance.contravariant
@@ -1133,7 +1132,6 @@ class SourceClassBuilder extends ClassBuilderImpl
11331132
}
11341133
}
11351134
for (VariableDeclaration named in namedParameters) {
1136-
// Coverage-ignore-block(suite): Not run.
11371135
for (TypeParameter typeParameter in typeParameters) {
11381136
Variance namedVariance = Variance.contravariant
11391137
.combine(computeVariance(typeParameter, named.type));

0 commit comments

Comments
 (0)