Skip to content

Commit

Permalink
Version 3.7.0-168.0.dev
Browse files Browse the repository at this point in the history
Merge 9c59339 into dev
  • Loading branch information
Dart CI committed Nov 20, 2024
2 parents 01cc572 + 9c59339 commit b15c4ea
Show file tree
Hide file tree
Showing 19 changed files with 94 additions and 103 deletions.
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2465,7 +2465,7 @@ This is a patch release that:
spawned via `Isolate.spawnUri`. See [`SendPort.send`] documentation for
the full list of restrictions.

[`SendPort.send`]: https://api.dart.dev/stable/dart-isolate/SendPort/send.html
[`SendPort.send`]: https://api.dart.dev/dart-isolate/SendPort/send.html

#### `dart:mirrors`

Expand All @@ -2474,8 +2474,8 @@ This is a patch release that:
previously used internally in dart2js. Both are no longer functional.

[#34233]: https://github.com/dart-lang/sdk/issues/34233
[`MirrorsUsed`]: https://api.dart.dev/stable/dart-mirrors/MirrorsUsed-class.html
[`Comment`]: https://api.dart.dev/stable/dart-mirrors/Comment-class.html
[`MirrorsUsed`]: https://api.dart.dev/dart-mirrors/MirrorsUsed-class.html
[`Comment`]: https://api.dart.dev/dart-mirrors/Comment-class.html

### Other libraries

Expand Down Expand Up @@ -5564,7 +5564,7 @@ Thanks to **Vincenzo di Cicco** for finding and reporting this issue.
This release also improves compatibility with ARMv8 processors (issue [40001][])
and dart:io stability (issue [40589][]).

[nodevalidator]: https://api.dart.dev/stable/dart-html/NodeValidator-class.html
[nodevalidator]: https://api.dart.dev/dart-html/NodeValidator-class.html
[cve-2020-8923]:
https://github.com/dart-lang/sdk/security/advisories/GHSA-hfq3-v9pv-p627
[40001]: https://github.com/dart-lang/sdk/issues/40001
Expand Down
8 changes: 4 additions & 4 deletions docs/gsoc/Dart-GSoC-2023-Project-Ideas.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Successfully completely this project will likely involve:

* Determining exactly what APIs should be make available in Dart.
* Creating a JNI bindings for those APIs using [`package:jnigen`](https://pub.dev/packages/jnigen).
* Creating a higher-level interface over the JNI bindings e.g. so the Dart developer can work with [Dart URIs](https://api.dart.dev/stable/dart-core/Uri-class.html) rather than [java.net.URI](https://developer.android.com/reference/java/net/URI).
* Creating a higher-level interface over the JNI bindings e.g. so the Dart developer can work with [Dart URIs](https://api.dart.dev/dart-core/Uri-class.html) rather than [java.net.URI](https://developer.android.com/reference/java/net/URI).
* Creating a [`package:http` `Client`](https://pub.dev/documentation/http/latest/http/Client-class.html) implementation using the interface above.
* Verifying that the `Client` implementation passes the [conformance tests](https://github.com/dart-lang/http/tree/main/pkgs/http_client_conformance_tests).

Expand All @@ -135,19 +135,19 @@ A good project proposal will describe what Java APIs are necessary to implement



## **Idea:** Refactor Plus packages to utilize new Dart 3 language features
## **Idea:** Refactor Plus packages to utilize new Dart 3 language features

- **Possible Mentor(s)**: Majid Hajian <[email protected]>
- **Difficulty**: Hard
- **Project size**: / Medium (175 hours)
- **Skills**: Dart

**Description**: Dart 3 introduces a few new language features. There are several features such as Records, pattern matching and new direct platform library interop which potentially helps to improve code readability and better API design for packages.
**Description**: Dart 3 introduces a few new language features. There are several features such as Records, pattern matching and new direct platform library interop which potentially helps to improve code readability and better API design for packages.

We would like to explore the possibilities of the new language features that could help to improve packages and create a new API (potentially) or refactor internal coding that make the package to take full advantage of Dart 3. We would like to also prepare a guideline after this refactoring for other maintainers to figure out what could be improved or changed.

We are using [Federated plugins](https://flutter.dev/to/federated-plugins), therefore this is likely to involve:

* refactoring `platform_interface` class for each package,
* refactoring app-facing and platform-specific-implementation packages,
* potentially removing native code and replacing it with direct dart API calls,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ abstract class InferenceVisitorBase implements InferenceVisitor {
StaticTypeContext get staticTypeContext => _inferrer.staticTypeContext;

DartType computeGreatestClosure(DartType type) {
return greatestClosure(type, const DynamicType(), bottomType);
return greatestClosure(type, topType: const DynamicType());
}

DartType computeGreatestClosure2(DartType type) {
return greatestClosure(type, coreTypes.objectNullableRawType, bottomType);
return greatestClosure(type, topType: coreTypes.objectNullableRawType);
}

DartType computeNullable(DartType type) {
Expand Down
9 changes: 4 additions & 5 deletions pkg/front_end/lib/src/type_inference/standard_bounds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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.

import 'package:kernel/ast.dart' show DartType, NeverType;
import 'package:kernel/ast.dart' show DartType;
import 'package:kernel/src/standard_bounds.dart';

import 'type_schema.dart' show UnknownType;
Expand All @@ -13,16 +13,15 @@ mixin TypeSchemaStandardBounds on StandardBounds {
DartType greatestClosureForLowerBound(DartType typeSchema) {
// - We replace all uses of `T1 <: T2` in the `DOWN` algorithm by `S1 <:
// S2` where `Si` is the greatest closure of `Ti` with respect to `_`.
return greatestClosure(typeSchema, coreTypes.objectNullableRawType,
const NeverType.nonNullable());
return greatestClosure(typeSchema,
topType: coreTypes.objectNullableRawType);
}

@override
DartType leastClosureForUpperBound(DartType typeSchema) {
// - We replace all uses of `T1 <: T2` in the `UP` algorithm by `S1 <: S2`
// where `Si` is the least closure of `Ti` with respect to `_`.
return leastClosure(typeSchema, coreTypes.objectNullableRawType,
const NeverType.nonNullable());
return leastClosure(typeSchema, topType: coreTypes.objectNullableRawType);
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,7 @@ class OperationsCfe
SharedTypeSchemaView<DartType> schema) {
return new SharedTypeView(type_schema_elimination.greatestClosure(
schema.unwrapTypeSchemaView(),
const DynamicType(),
const NeverType.nonNullable()));
topType: const DynamicType()));
}

@override
Expand Down
33 changes: 15 additions & 18 deletions pkg/front_end/lib/src/type_inference/type_schema_elimination.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import 'type_schema.dart' show UnknownType;
///
/// Note that the greatest closure of a type schema is always a supertype of any
/// type which matches the schema.
DartType greatestClosure(
DartType schema, DartType topType, DartType bottomType) {
return _TypeSchemaEliminationVisitor.run(false, schema, topType, bottomType);
DartType greatestClosure(DartType schema, {required DartType topType}) {
return _TypeSchemaEliminationVisitor.run(schema,
computeLeastClosure: false, topType: topType);
}

/// Returns the least closure of the given type [schema] with respect to `?`.
Expand All @@ -38,8 +38,9 @@ DartType greatestClosure(
///
/// Note that the least closure of a type schema is always a subtype of any type
/// which matches the schema.
DartType leastClosure(DartType schema, DartType topType, DartType bottomType) {
return _TypeSchemaEliminationVisitor.run(true, schema, topType, bottomType);
DartType leastClosure(DartType schema, {required DartType topType}) {
return _TypeSchemaEliminationVisitor.run(schema,
computeLeastClosure: true, topType: topType);
}

/// Visitor that computes least and greatest closures of a type schema.
Expand All @@ -48,16 +49,15 @@ DartType leastClosure(DartType schema, DartType topType, DartType bottomType) {
/// type, otherwise it returns the result of substituting `?` with `Null` or
/// `Object`, as appropriate.
class _TypeSchemaEliminationVisitor extends ReplacementVisitor {
final DartType topType;
final DartType bottomType;
final DartType _topType;

_TypeSchemaEliminationVisitor(this.topType, this.bottomType);
_TypeSchemaEliminationVisitor(this._topType);

@override
DartType? visitAuxiliaryType(AuxiliaryType node, Variance variance) {
bool isLeastClosure = variance == Variance.covariant;
bool computeLeastClosure = variance == Variance.covariant;
if (node is UnknownType) {
return isLeastClosure ? bottomType : topType;
return computeLeastClosure ? const NeverType.nonNullable() : _topType;
}
// Coverage-ignore-block(suite): Not run.
throw new UnsupportedError(
Expand All @@ -67,21 +67,18 @@ class _TypeSchemaEliminationVisitor extends ReplacementVisitor {
/// Runs an instance of the visitor on the given [schema] and returns the
/// resulting type. If the schema contains no instances of `?`, the original
/// schema object is returned to avoid unnecessary allocation.
static DartType run(bool isLeastClosure, DartType schema, DartType topType,
DartType bottomType) {
static DartType run(DartType schema,
{required bool computeLeastClosure, required DartType topType}) {
assert(topType == const DynamicType() ||
topType is InterfaceType &&
topType.nullability == Nullability.nullable &&
topType.classNode.enclosingLibrary.importUri.isScheme("dart") &&
topType.classNode.enclosingLibrary.importUri.path == "core" &&
topType.classNode.name == "Object");
assert(bottomType == const NeverType.nonNullable() ||
// Coverage-ignore(suite): Not run.
bottomType is NullType);
_TypeSchemaEliminationVisitor visitor =
new _TypeSchemaEliminationVisitor(topType, bottomType);
DartType? result = schema.accept1(
visitor, isLeastClosure ? Variance.covariant : Variance.contravariant);
new _TypeSchemaEliminationVisitor(topType);
DartType? result = schema.accept1(visitor,
computeLeastClosure ? Variance.covariant : Variance.contravariant);
return result ?? schema;
}
}
39 changes: 19 additions & 20 deletions pkg/front_end/lib/src/type_inference/type_schema_environment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -392,12 +392,10 @@ class TypeSchemaEnvironment extends HierarchyBasedTypeEnvironment
/// If [isContravariant] is `true`, then we are solving for a contravariant
/// type parameter which means we choose the upper bound rather than the
/// lower bound for normally covariant type parameters.
DartType solveTypeConstraint(
MergedTypeConstraint constraint, DartType topType, DartType bottomType,
{bool grounded = false, bool isContravariant = false}) {
assert(bottomType == const NeverType.nonNullable() ||
// Coverage-ignore(suite): Not run.
bottomType == const NullType());
DartType solveTypeConstraint(MergedTypeConstraint constraint,
{required DartType topType,
bool grounded = false,
bool isContravariant = false}) {
if (!isContravariant) {
// Prefer the known bound, if any.
if (isKnown(constraint.lower.unwrapTypeSchemaView())) {
Expand All @@ -411,13 +409,13 @@ class TypeSchemaEnvironment extends HierarchyBasedTypeEnvironment
// e.g. `Iterable<?>`
if (constraint.lower is! SharedUnknownTypeSchemaView<DartType>) {
return grounded
? leastClosure(
constraint.lower.unwrapTypeSchemaView(), topType, bottomType)
? leastClosure(constraint.lower.unwrapTypeSchemaView(),
topType: topType)
: constraint.lower.unwrapTypeSchemaView();
} else if (constraint.upper is! UnknownType) {
return grounded
? greatestClosure(
constraint.upper.unwrapTypeSchemaView(), topType, bottomType)
? greatestClosure(constraint.upper.unwrapTypeSchemaView(),
topType: topType)
: constraint.upper.unwrapTypeSchemaView();
} else {
return const UnknownType();
Expand All @@ -437,13 +435,13 @@ class TypeSchemaEnvironment extends HierarchyBasedTypeEnvironment
if (constraint.upper is! UnknownType) {
// Coverage-ignore-block(suite): Not run.
return grounded
? greatestClosure(
constraint.upper.unwrapTypeSchemaView(), topType, bottomType)
? greatestClosure(constraint.upper.unwrapTypeSchemaView(),
topType: topType)
: constraint.upper.unwrapTypeSchemaView();
} else if (constraint.lower is! UnknownType) {
return grounded
? leastClosure(
constraint.lower.unwrapTypeSchemaView(), topType, bottomType)
? leastClosure(constraint.lower.unwrapTypeSchemaView(),
topType: topType)
:
// Coverage-ignore(suite): Not run.
constraint.lower.unwrapTypeSchemaView();
Expand Down Expand Up @@ -535,9 +533,10 @@ class TypeSchemaEnvironment extends HierarchyBasedTypeEnvironment
new SharedTypeSchemaView(extendsConstraint), operations);
}

return solveTypeConstraint(constraint, coreTypes.objectNullableRawType,
const NeverType.nonNullable(),
grounded: true, isContravariant: isContravariant);
return solveTypeConstraint(constraint,
topType: coreTypes.objectNullableRawType,
grounded: true,
isContravariant: isContravariant);
}

void _mergeInConstraintsFromBound(
Expand Down Expand Up @@ -577,7 +576,7 @@ class TypeSchemaEnvironment extends HierarchyBasedTypeEnvironment
}

DartType t = solveTypeConstraint(constraint,
coreTypes.objectNullableRawType, const NeverType.nonNullable());
topType: coreTypes.objectNullableRawType);
if (!isKnown(t)) {
return t;
}
Expand All @@ -604,8 +603,8 @@ class TypeSchemaEnvironment extends HierarchyBasedTypeEnvironment
constraint = constraint.clone();
constraint.mergeInTypeSchemaUpper(
new SharedTypeSchemaView(extendsConstraint), operations);
return solveTypeConstraint(constraint, coreTypes.objectNullableRawType,
const NeverType.nonNullable());
return solveTypeConstraint(constraint,
topType: coreTypes.objectNullableRawType);
}

return t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ class TypeSchemaEliminationTest {
};

DartType greatestClosure(DartType schema) {
return typeSchemaElimination.greatestClosure(
schema, const DynamicType(), const NeverType.nonNullable());
return typeSchemaElimination.greatestClosure(schema,
topType: env.coreTypes.objectNullableRawType);
}

DartType leastClosure(DartType schema) {
return typeSchemaElimination.leastClosure(
schema, const DynamicType(), const NeverType.nonNullable());
return typeSchemaElimination.leastClosure(schema,
topType: env.coreTypes.objectNullableRawType);
}

void testGreatest(String type, String expectedClosure) {
Expand All @@ -45,47 +45,47 @@ class TypeSchemaEliminationTest {
}

void test_greatestClosure_contravariant() {
testGreatest("(UNKNOWN) ->* dynamic", "(Never) ->* dynamic");
testGreatest("({UNKNOWN foo}) ->* dynamic", "({Never foo}) ->* dynamic");
testGreatest("(UNKNOWN) -> dynamic", "(Never) -> dynamic");
testGreatest("({UNKNOWN foo}) -> dynamic", "({Never foo}) -> dynamic");
}

void test_greatestClosure_contravariant_contravariant() {
testGreatest("((UNKNOWN) ->* dynamic) ->* dynamic",
"((dynamic) ->* dynamic) ->* dynamic");
testGreatest("((UNKNOWN) -> dynamic) -> dynamic",
"((Object?) -> dynamic) -> dynamic");
}

void test_greatestClosure_covariant() {
testGreatest("() ->* UNKNOWN", "() ->* dynamic");
testGreatest("List<UNKNOWN>*", "List<dynamic>*");
testGreatest("() -> UNKNOWN", "() -> Object?");
testGreatest("List<UNKNOWN>", "List<Object?>");
}

void test_greatestClosure_function_multipleUnknown() {
testGreatest("(UNKNOWN, UNKNOWN, {UNKNOWN a, UNKNOWN b}) ->* UNKNOWN",
"(Never, Never, {Never a, Never b}) ->* dynamic");
testGreatest("(UNKNOWN, UNKNOWN, {UNKNOWN a, UNKNOWN b}) -> UNKNOWN",
"(Never, Never, {Never a, Never b}) -> Object?");
}

void test_greatestClosure_simple() {
testGreatest("UNKNOWN", "dynamic");
testGreatest("UNKNOWN", "Object?");
}

void test_leastClosure_contravariant() {
testLeast("(UNKNOWN) ->* dynamic", "(dynamic) ->* dynamic");
testLeast("({UNKNOWN foo}) ->* dynamic", "({dynamic foo}) ->* dynamic");
testLeast("(UNKNOWN) -> dynamic", "(Object?) -> dynamic");
testLeast("({UNKNOWN foo}) -> dynamic", "({Object? foo}) -> dynamic");
}

void test_leastClosure_contravariant_contravariant() {
testLeast("((UNKNOWN) ->* dynamic) ->* dynamic",
"((Never) ->* dynamic) ->* dynamic");
testLeast(
"((UNKNOWN) -> dynamic) -> dynamic", "((Never) -> dynamic) -> dynamic");
}

void test_leastClosure_covariant() {
testLeast("() ->* UNKNOWN", "() ->* Never");
testLeast("List<UNKNOWN>*", "List<Never>*");
testLeast("() -> UNKNOWN", "() -> Never");
testLeast("List<UNKNOWN>", "List<Never>");
}

void test_leastClosure_function_multipleUnknown() {
testLeast("(UNKNOWN, UNKNOWN, {UNKNOWN a, UNKNOWN b}) ->* UNKNOWN",
"(dynamic, dynamic, {dynamic a, dynamic b}) ->* Never");
testLeast("(UNKNOWN, UNKNOWN, {UNKNOWN a, UNKNOWN b}) -> UNKNOWN",
"(Object?, Object?, {Object? a, Object? b}) -> Never");
}

void test_leastClosure_simple() {
Expand Down
Loading

0 comments on commit b15c4ea

Please sign in to comment.