Skip to content

Commit

Permalink
Version 3.7.0-199.0.dev
Browse files Browse the repository at this point in the history
Merge 0ac63b6 into dev
  • Loading branch information
Dart CI committed Nov 28, 2024
2 parents 4450320 + 0ac63b6 commit ebcdfe1
Show file tree
Hide file tree
Showing 22 changed files with 289 additions and 132 deletions.
2 changes: 2 additions & 0 deletions pkg/dartdev/lib/src/commands/compilation_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import 'dart:io' show File;

import 'package:args/args.dart';
import 'package:dartdev/src/generate_kernel.dart';
import 'package:frontend_server/resident_frontend_server_utils.dart'
show ResidentCompilerInfo;

import '../core.dart';
import '../resident_frontend_constants.dart';
Expand Down
2 changes: 2 additions & 0 deletions pkg/dartdev/lib/src/generate_kernel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import 'dart:io';

import 'package:args/args.dart';
import 'package:frontend_server/resident_frontend_server_utils.dart'
show ResidentCompilerInfo, sendAndReceiveResponse;
import 'package:kernel/binary/tag.dart' show isValidSdkHash;
import 'package:path/path.dart' as p;
import 'package:pub/pub.dart';
Expand Down
81 changes: 3 additions & 78 deletions pkg/dartdev/lib/src/resident_frontend_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
// BSD-style license that can be found in the LICENSE file.

import 'dart:convert';
import 'dart:io' show File, FileSystemException, InternetAddress, Socket;
import 'dart:io' show File, FileSystemException;

import 'package:args/args.dart';
import 'package:frontend_server/resident_frontend_server_utils.dart'
show sendAndReceiveResponse;
import 'package:path/path.dart' as p;

import 'commands/compilation_server.dart' show CompilationServerCommand;
Expand Down Expand Up @@ -51,51 +53,6 @@ File? getResidentCompilerInfoFileConsideringArgs(final ArgResults args) {

final String packageConfigName = p.join('.dart_tool', 'package_config.json');

final class ResidentCompilerInfo {
final String? _sdkHash;
final InternetAddress _address;
final int _port;

/// The SDK hash that kernel files compiled using the Resident Frontend
/// Compiler associated with this object will be stamped with.
String? get sdkHash => _sdkHash;

/// The address that the Resident Frontend Compiler associated with this
/// object is listening from.
InternetAddress get address => _address;

/// The port number that the Resident Frontend Compiler associated with this
/// object is listening on.
int get port => _port;

/// Extracts the value associated with a key from [entries], where [entries]
/// is a [String] with the format '$key1:$value1 $key2:$value2 $key3:$value3 ...'.
static String _extractValueAssociatedWithKey(String entries, String key) =>
RegExp('$key:' r'(\S+)(\s|$)').allMatches(entries).first[1]!;

static ResidentCompilerInfo fromFile(File file) {
final fileContents = file.readAsStringSync();

return ResidentCompilerInfo._(
sdkHash: fileContents.contains('sdkHash:')
? _extractValueAssociatedWithKey(fileContents, 'sdkHash')
: null,
address: InternetAddress(
_extractValueAssociatedWithKey(fileContents, 'address'),
),
port: int.parse(_extractValueAssociatedWithKey(fileContents, 'port')),
);
}

ResidentCompilerInfo._({
required String? sdkHash,
required int port,
required InternetAddress address,
}) : _sdkHash = sdkHash,
_port = port,
_address = address;
}

/// Removes the [serverInfoFile].
void cleanupResidentServerInfo(File serverInfoFile) {
if (serverInfoFile.existsSync()) {
Expand Down Expand Up @@ -208,38 +165,6 @@ Future<bool> isFileAotSnapshot(final File file) async {
return false;
}

// TODO: when frontend_server is migrated to null safe Dart, everything
// below this comment can be removed and imported from resident_frontend_server

/// Sends a compilation [request] to the Resident Frontend Compiler associated
/// with [serverInfoFile], and returns the compiler's JSON response.
///
/// Throws a [FileSystemException] if [serverInfoFile] cannot be accessed.
Future<Map<String, dynamic>> sendAndReceiveResponse(
String request,
File serverInfoFile,
) async {
Socket? client;
Map<String, dynamic> jsonResponse;
final residentCompilerInfo = ResidentCompilerInfo.fromFile(serverInfoFile);
try {
client = await Socket.connect(
residentCompilerInfo.address,
residentCompilerInfo.port,
);
client.write(request);
final data = String.fromCharCodes(await client.first);
jsonResponse = jsonDecode(data);
} catch (e) {
jsonResponse = <String, dynamic>{
responseSuccessString: false,
responseErrorString: e.toString(),
};
}
client?.destroy();
return jsonResponse;
}

/// Used to create compile requests for the run CLI command.
///
/// Returns a JSON string that the resident compiler will be able to interpret.
Expand Down
1 change: 1 addition & 0 deletions pkg/dartdev/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies:
dds_service_extensions: any
dtd_impl: any
front_end: any
frontend_server: any
http: any
kernel: any
logging: any
Expand Down
2 changes: 2 additions & 0 deletions pkg/dartdev/test/commands/run_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import 'dart:io';

import 'package:dartdev/src/resident_frontend_constants.dart';
import 'package:dartdev/src/resident_frontend_utils.dart';
import 'package:frontend_server/resident_frontend_server_utils.dart'
show ResidentCompilerInfo, sendAndReceiveResponse;
import 'package:kernel/binary/tag.dart' show sdkHashNull;
import 'package:path/path.dart' as path;
import 'package:pub_semver/pub_semver.dart';
Expand Down
2 changes: 2 additions & 0 deletions pkg/dartdev/test/resident_frontend_utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import 'dart:io';

import 'package:dartdev/src/resident_frontend_utils.dart';
import 'package:frontend_server/resident_frontend_server_utils.dart'
show ResidentCompilerInfo;
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
import 'utils.dart';
Expand Down
52 changes: 52 additions & 0 deletions pkg/front_end/lib/src/type_inference/for_in.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:kernel/ast.dart';

import '../base/instrumentation.dart' show InstrumentationValueForMember;
import '../codes/cfe_codes.dart';
import '../kernel/hierarchy/class_member.dart';
import '../kernel/internal_ast.dart';
import 'inference_results.dart';
import 'inference_visitor.dart';
Expand Down Expand Up @@ -259,6 +260,57 @@ class StaticForInVariable implements ForInVariable {
}
}

class ExtensionSetForInVariable implements ForInVariable {
final ExtensionSet extensionSet;
DartType? setterType;

ExtensionSetForInVariable(this.extensionSet);

@override
DartType computeElementType(InferenceVisitorBase visitor) {
ExpressionInferenceResult receiverResult = visitor.inferExpression(
extensionSet.receiver, const UnknownType(),
isVoidAllowed: false);

List<DartType> extensionTypeArguments =
visitor.computeExtensionTypeArgument(extensionSet.extension,
extensionSet.explicitTypeArguments, receiverResult.inferredType,
treeNodeForTesting: extensionSet);

DartType receiverType = visitor.getExtensionReceiverType(
extensionSet.extension, extensionTypeArguments);

ObjectAccessTarget target = new ExtensionAccessTarget(
receiverType,
extensionSet.target,
null,
ClassMemberKind.Setter,
extensionTypeArguments);

setterType = target.getSetterType(visitor);
return setterType!;
}

@override
Expression inferAssignment(InferenceVisitorBase visitor, DartType rhsType) {
assert(setterType != null);
Expression rhs = visitor.ensureAssignable(
setterType!, rhsType, extensionSet.value,
errorTemplate: templateForInLoopElementTypeNotAssignable,
nullabilityErrorTemplate:
templateForInLoopElementTypeNotAssignableNullability,
nullabilityPartErrorTemplate:
templateForInLoopElementTypeNotAssignablePartNullability,
isVoidAllowed: true);

extensionSet.value = rhs..parent = extensionSet;
ExpressionInferenceResult result = visitor.inferExpression(
extensionSet, const UnknownType(),
isVoidAllowed: true);
return result.expression;
}
}

class InvalidForInVariable implements ForInVariable {
final Expression? expression;

Expand Down
2 changes: 2 additions & 0 deletions pkg/front_end/lib/src/type_inference/inference_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,8 @@ class InferenceVisitorImpl extends InferenceVisitorBase
return new SuperPropertyForInVariable(syntheticAssignment);
} else if (syntheticAssignment is StaticSet) {
return new StaticForInVariable(syntheticAssignment);
} else if (syntheticAssignment is ExtensionSet) {
return new ExtensionSetForInVariable(syntheticAssignment);
} else if (syntheticAssignment is InvalidExpression || hasProblem) {
return new InvalidForInVariable(syntheticAssignment);
} else {
Expand Down
1 change: 1 addition & 0 deletions pkg/front_end/test/spell_checking_list_common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2941,6 +2941,7 @@ stable
stack
stacked
stage
stamped
stamps
standalone
standard
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

extension on String {
set foo(int value) {}
bar(List<int> input) {
foo = 42;
for (foo in input) {
print("inside loop");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
library;
import self as self;
import "dart:core" as core;

extension /* unnamed */ _extension#0 on core::String {
method bar = self::_extension#0|bar;
method tearoff bar = self::_extension#0|get#bar;
set foo = self::_extension#0|set#foo;
}
static extension-member method _extension#0|set#foo(lowered final core::String #this, core::int value) → void {}
static extension-member method _extension#0|bar(lowered final core::String #this, core::List<core::int> input) → dynamic {
self::_extension#0|set#foo(#this, 42);
for (final core::int #t1 in input) {
self::_extension#0|set#foo(#this, #t1);
core::print("inside loop");
}
}
static extension-member method _extension#0|get#bar(lowered final core::String #this) → (core::List<core::int>) → dynamic
return (core::List<core::int> input) → dynamic => self::_extension#0|bar(#this, input);
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
library;
import self as self;
import "dart:core" as core;

extension /* unnamed */ _extension#0 on core::String {
method bar = self::_extension#0|bar;
method tearoff bar = self::_extension#0|get#bar;
set foo = self::_extension#0|set#foo;
}
static extension-member method _extension#0|set#foo(lowered final core::String #this, core::int value) → void {}
static extension-member method _extension#0|bar(lowered final core::String #this, core::List<core::int> input) → dynamic {
self::_extension#0|set#foo(#this, 42);
for (final core::int #t1 in input) {
self::_extension#0|set#foo(#this, #t1);
core::print("inside loop");
}
}
static extension-member method _extension#0|get#bar(lowered final core::String #this) → (core::List<core::int>) → dynamic
return (core::List<core::int> input) → dynamic => self::_extension#0|bar(#this, input);
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
library;
import self as self;
import "dart:core" as core;

extension /* unnamed */ _extension#0 on core::String {
method bar = self::_extension#0|bar;
method tearoff bar = self::_extension#0|get#bar;
set foo = self::_extension#0|set#foo;
}
static extension-member method _extension#0|set#foo(lowered final core::String #this, core::int value) → void
;
static extension-member method _extension#0|bar(lowered final core::String #this, core::List<core::int> input) → dynamic
;
static extension-member method _extension#0|get#bar(lowered final core::String #this) → (core::List<core::int>) → dynamic
return (core::List<core::int> input) → dynamic => self::_extension#0|bar(#this, input);
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
library;
import self as self;
import "dart:core" as core;

extension /* unnamed */ _extension#0 on core::String {
method bar = self::_extension#0|bar;
method tearoff bar = self::_extension#0|get#bar;
set foo = self::_extension#0|set#foo;
}
static extension-member method _extension#0|set#foo(lowered final core::String #this, core::int value) → void {}
static extension-member method _extension#0|bar(lowered final core::String #this, core::List<core::int> input) → dynamic {
self::_extension#0|set#foo(#this, 42);
{
synthesized core::Iterator<core::int> :sync-for-iterator = input.{core::Iterable::iterator}{core::Iterator<core::int>};
for (; :sync-for-iterator.{core::Iterator::moveNext}(){() → core::bool}; ) {
final core::int #t1 = :sync-for-iterator.{core::Iterator::current}{core::int};
{
self::_extension#0|set#foo(#this, #t1);
core::print("inside loop");
}
}
}
}
static extension-member method _extension#0|get#bar(lowered final core::String #this) → (core::List<core::int>) → dynamic
return (core::List<core::int> input) → dynamic => self::_extension#0|bar(#this, input);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extension on String {
set foo(int value) {}
bar(List<int> input) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extension on String {
bar(List<int> input) {}
set foo(int value) {}
}
2 changes: 1 addition & 1 deletion pkg/frontend_server/OWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ file:/tools/OWNERS_CFE
file:/OWNERS

# Add the VM team as owners of ResidentFrontendServer-related files.
per-file lib/src/resident_frontend_server.dart, test/src/resident_frontend_server_test.dart = file:/tools/OWNERS_VM
per-file lib/resident_frontend_server_utils.dart,lib/src/resident_frontend_server.dart,test/src/resident_frontend_server_test.dart=file:/tools/OWNERS_VM
Loading

0 comments on commit ebcdfe1

Please sign in to comment.