Skip to content

Commit

Permalink
Version 3.3.0-254.0.dev
Browse files Browse the repository at this point in the history
Merge b574db4 into dev
  • Loading branch information
Dart CI committed Dec 21, 2023
2 parents bcf68d2 + b574db4 commit fe94d9b
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 32 deletions.
9 changes: 5 additions & 4 deletions pkg/analyzer/lib/src/summary2/macro_declarations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,11 @@ class DeclarationBuilder {
}
case ParameterElement():
return macro.ResolvedIdentifier(
kind: macro.IdentifierKind.local,
name: element.name,
uri: null,
staticScope: null);
kind: macro.IdentifierKind.local,
name: element.name,
uri: null,
staticScope: null,
);
case PropertyAccessorElement():
if (element.enclosingElement is CompilationUnitElement) {
return macro.ResolvedIdentifier(
Expand Down
37 changes: 37 additions & 0 deletions pkg/analyzer/test/src/summary/macro/code_generation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,43 @@ import 'package:_fe_analyzer_shared/src/macros/api.dart';
}
}

/*macro*/ class ReferenceFirstFormalParameter
implements FunctionDefinitionMacro {
const ReferenceFirstFormalParameter();

@override
Future<void> buildDefinitionForFunction(
FunctionDeclaration function,
FunctionDefinitionBuilder builder,
) async {
builder.augment(
FunctionBodyCode.fromParts([
'{\n ',
function.positionalParameters.first.identifier,
';\n}',
]),
);
}
}

/*macro*/ class ReferenceFirstTypeParameter implements FunctionDefinitionMacro {
const ReferenceFirstTypeParameter();

@override
Future<void> buildDefinitionForFunction(
FunctionDeclaration function,
FunctionDefinitionBuilder builder,
) async {
builder.augment(
FunctionBodyCode.fromParts([
'{\n ',
function.typeParameters.first.identifier,
';\n}',
]),
);
}
}

/*macro*/ class ReferenceIdentifier implements ClassDeclarationsMacro {
final String uriStr;
final String topName;
Expand Down
36 changes: 36 additions & 0 deletions pkg/analyzer/test/src/summary/macro_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1832,6 +1832,25 @@ augment class X {
''');
}

test_resolveIdentifier_formalParameter() async {
final library = await buildLibrary(r'''
import 'code_generation.dart';
@ReferenceFirstFormalParameter()
void foo(int a);
''');

_assertMacroCode(library, r'''
library augment 'test.dart';
import 'dart:core' as prefix0;
augment void foo(prefix0.int a, ) {
a;
}
''');
}

test_resolveIdentifier_functionTypeAlias() async {
newFile('$testPackageLibPath/a.dart', r'''
typedef void A();
Expand Down Expand Up @@ -1884,6 +1903,23 @@ augment class X {
''');
}

test_resolveIdentifier_typeParameter() async {
final library = await buildLibrary(r'''
import 'code_generation.dart';
@ReferenceFirstTypeParameter()
void foo<T>();
''');

_assertMacroCode(library, r'''
library augment 'test.dart';
augment void foo<T>() {
T;
}
''');
}

test_resolveIdentifier_unit_function() async {
newFile('$testPackageLibPath/a.dart', r'''
void foo() {}
Expand Down
29 changes: 15 additions & 14 deletions pkg/compiler/lib/src/io/position_information.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1549,34 +1549,35 @@ class OnlineJavaScriptTracer extends js.BaseVisitor1Void<int>
@override
visitNode(js.Node node, _) {}

void _handleFunction(js.Node node, js.Node body, int start) {
_currentNode.active =
_currentNode.active || reader.getSourceInformation(node) != null;
Offset entryOffset = getOffsetForNode(_currentNode.statementOffset, start);
notifyStep(node, entryOffset, StepKind.FUN_ENTRY);
void _handleFunction(_PositionInfoNode node, js.Node body, int start) {
_currentNode.active = _currentNode.active ||
reader.getSourceInformation(node.astNode) != null;
Offset entryOffset = getOffsetForNode(node.statementOffset, start);
notifyStep(node.astNode, entryOffset, StepKind.FUN_ENTRY);

visit(body, statementOffset: start);

_currentNode.addNotifyStep(StepKind.FUN_EXIT);
node.addNotifyStep(StepKind.FUN_EXIT);
}

_handleFunctionExpression(js.FunctionExpression node, int start) {
final parentNode = _currentNode.parent!.astNode;
js.NamedFunction? namedParent;
final parentNode = _currentNode.parent;
final parentAstNode = _currentNode.parent?.astNode;
_PositionInfoNode functionNode = _currentNode;
js.Expression? declaration;
if (parentNode is js.NamedFunction) {
namedParent = parentNode;
declaration = parentNode.name;
} else if (parentNode is js.FunctionDeclaration) {
declaration = parentNode.name;
if (parentAstNode is js.NamedFunction) {
functionNode = parentNode!;
declaration = parentAstNode.name;
} else if (parentAstNode is js.FunctionDeclaration) {
declaration = parentAstNode.name;
}

visit(declaration);
for (final param in node.params) {
visit(param);
}
// For named functions we treat the named parent as the main node.
_handleFunction(namedParent ?? node, node.body, start);
_handleFunction(functionNode, node.body, start);
}

@override
Expand Down
25 changes: 13 additions & 12 deletions pkg/front_end/tool/update_expectations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,23 @@ const List<String> specialSuites = <String>[
Future<void> runStandardSuites([List<String>? args]) async {
// Assert that 'strong' is the first suite - we use the assumption below.
assert(standardSuites.first == 'weak', "Suite 'weak' most be the first.");
bool first = true;

List<String> testingArguments = [];
for (String suite in standardSuites) {
List<String> tests = args == null
? [suite]
: args.map((String arg) => '${suite}/$arg').toList();
await fasta.main([
'testing',
...tests,
// Only update comments in the first suite. Note that this only works
// if the first compilation is a full compilation, i.e. not outline,
// because comments are generated during body building and inference.
if (first) '-DupdateComments=true',
'-DupdateExpectations=true'
]);
first = false;
testingArguments.addAll(tests);
}
await fasta.main([
'testing',
...testingArguments,
// Only update comments in the first suite. Note that this only works
// if the first compilation is a full compilation, i.e. not outline,
// because comments are generated during body building and inference.
'-DupdateComments=true',
'-DupdateExpectations=true'
]);
}

Future<void> main(List<String> args) async {
Expand All @@ -61,7 +62,7 @@ Future<void> main(List<String> args) async {
}
}
if (standardTests.isNotEmpty) {
await runStandardSuites(args);
await runStandardSuites(standardTests);
}
}
}
2 changes: 1 addition & 1 deletion pkg/testing/lib/src/chain.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Chain extends Suite {
void writeClosureOn(StringSink sink) {
sink.write("await runChain(");
sink.write(name);
sink.writeln(".createContext, environment, selectors, r'''");
sink.writeln(".createContext, {...environment}, selectors, r'''");
const String jsonExtraIndent = " ";
sink.write(jsonExtraIndent);
sink.writeAll(splitLines(JsonEncoder.withIndent(" ").convert(this)),
Expand Down
2 changes: 1 addition & 1 deletion tools/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ CHANNEL dev
MAJOR 3
MINOR 3
PATCH 0
PRERELEASE 253
PRERELEASE 254
PRERELEASE_PATCH 0

0 comments on commit fe94d9b

Please sign in to comment.