From 344e149a89bd2fc7dd73d538b6fbef8db8192a8d Mon Sep 17 00:00:00 2001 From: Sigmund Cherem Date: Sat, 14 Mar 2020 03:04:37 +0000 Subject: [PATCH] [ddc, dart2js] readd dart:mirrors Technically almost no user of ddc should be able to reach this compile-time error if they are using webdev (it appears a couple users do invoke it directly, though). Project sass demonstrated that users of dart2js can notice this breaking change. Given that we are bundling many breaking changes for null-safety on the next release, it seems like making imports to dart:mirrors a compile-time error is not strictly necessary at this time. One idea is to change this to a compile-time error in our tools when users opt-in their libraries or when they enable strong null-safety mode. Change-Id: I7f12657eba508e2d071dda60087a21475a303d9f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/139494 Reviewed-by: Nicholas Shahan Commit-Queue: Sigmund Cherem --- CHANGELOG.md | 16 +++---- .../js_runtime/lib/mirrors_patch_cfe.dart | 20 +++++++++ sdk/lib/libraries.json | 15 +++++++ sdk/lib/libraries.yaml | 15 +++++++ .../js_runtime/lib/mirrors_patch_cfe.dart | 44 +++++++++++++++++++ sdk_nnbd/lib/libraries.json | 15 +++++++ sdk_nnbd/lib/libraries.yaml | 15 +++++++ 7 files changed, 132 insertions(+), 8 deletions(-) create mode 100644 sdk_nnbd/lib/_internal/js_runtime/lib/mirrors_patch_cfe.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 5826b893d54..9c994ce29fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -113,10 +113,14 @@ additional details see the [announcement]. `external`. Previously the external could be omitted in some cases with DDC but doing so would cause incorrect behavior with `dart2js`. * JS interop classes with an index operator are now static errors. -* Removed the `dart:mirrors` library from the SDK. Use of this library on the - web has been unsupported and prevented by the Dart build systems since Dart - v2.0.0. All known exception cases have been cleaned up. This change makes DDC - and dart2js now issue a compile-time error directly as well. +* All remaining support from the `dart:mirrors` library has been removed. + Use of this library on the web has been unsupported and prevented by the Dart + build systems since Dart v2.0.0. All known exception cases have been cleaned + up. This change makes DDC and dart2js now behave consistently. + + The library can still be imported on web apps, but all APIs throw. In a future + breaking change release, imports to this library will likely become a + compile-time error. [announcement]: https://github.com/dart-lang/sdk/issues/38994 @@ -128,10 +132,6 @@ additional details see the [announcement]. forgiving. Corresponding type parameter bounds now only need to be mutual subtypes rather than structurally equal up to renaming of bound type variables and equating all top types. -* Removed the `dart:mirrors` library from the SDK. Use of this library on the - web has been unsupported and prevented by the Dart build systems since Dart - v2.0.0. All known exception cases have been cleaned up. This change makes DDC - and dart2js now issue a compile-time error directly as well. * **Breaking Change**: Types are now normalized. See [normalization] for the full specification. Types will now be printed in their normal form, and mutual subtypes with the same normal form will now be considered equal. diff --git a/sdk/lib/_internal/js_runtime/lib/mirrors_patch_cfe.dart b/sdk/lib/_internal/js_runtime/lib/mirrors_patch_cfe.dart index 59408456ab8..4265799540c 100644 --- a/sdk/lib/_internal/js_runtime/lib/mirrors_patch_cfe.dart +++ b/sdk/lib/_internal/js_runtime/lib/mirrors_patch_cfe.dart @@ -24,3 +24,23 @@ ClassMirror reflectClass(Type key) => throw new UnsupportedError(_message); @patch TypeMirror reflectType(Type key, [List typeArguments]) => throw new UnsupportedError(_message); + +@patch +abstract class MirrorSystem { + Map get libraries; + IsolateMirror get isolate; + TypeMirror get dynamicType; + TypeMirror get voidType; + TypeMirror get neverType; + + @patch + LibraryMirror findLibrary(Symbol libraryName) => + throw new UnsupportedError(_message); + + @patch + static String getName(Symbol symbol) => throw new UnsupportedError(_message); + + @patch + static Symbol getSymbol(String name, [LibraryMirror library]) => + throw new UnsupportedError(_message); +} diff --git a/sdk/lib/libraries.json b/sdk/lib/libraries.json index f4ba2c47eac..54dbc0d2aa6 100644 --- a/sdk/lib/libraries.json +++ b/sdk/lib/libraries.json @@ -217,6 +217,11 @@ "uri": "math/math.dart", "patches": "_internal/js_runtime/lib/math_patch.dart" }, + "mirrors": { + "uri": "mirrors/mirrors.dart", + "patches": "_internal/js_runtime/lib/mirrors_patch_cfe.dart", + "supported": false + }, "typed_data": { "uri": "typed_data/typed_data.dart", "patches": "_internal/js_runtime/lib/typed_data_patch.dart" @@ -322,6 +327,11 @@ "uri": "math/math.dart", "patches": "_internal/js_runtime/lib/math_patch.dart" }, + "mirrors": { + "uri": "mirrors/mirrors.dart", + "patches": "_internal/js_runtime/lib/mirrors_patch_cfe.dart", + "supported": false + }, "typed_data": { "uri": "typed_data/typed_data.dart", "patches": "_internal/js_runtime/lib/typed_data_patch.dart" @@ -428,6 +438,11 @@ "patches": "_internal/js_dev_runtime/patch/isolate_patch.dart", "supported": false }, + "mirrors": { + "uri": "mirrors/mirrors.dart", + "patches": "_internal/js_runtime/lib/mirrors_patch_cfe.dart", + "supported": false + }, "math": { "uri": "math/math.dart", "patches": "_internal/js_dev_runtime/patch/math_patch.dart" diff --git a/sdk/lib/libraries.yaml b/sdk/lib/libraries.yaml index cbf00806eee..8944e123efe 100644 --- a/sdk/lib/libraries.yaml +++ b/sdk/lib/libraries.yaml @@ -214,6 +214,11 @@ dart2js: uri: "math/math.dart" patches: "_internal/js_runtime/lib/math_patch.dart" + mirrors: + uri: "mirrors/mirrors.dart" + patches: "_internal/js_runtime/lib/mirrors_patch_cfe.dart" + supported: false + typed_data: uri: "typed_data/typed_data.dart" patches: "_internal/js_runtime/lib/typed_data_patch.dart" @@ -317,6 +322,11 @@ dart2js_server: uri: "math/math.dart" patches: "_internal/js_runtime/lib/math_patch.dart" + mirrors: + uri: "mirrors/mirrors.dart" + patches: "_internal/js_runtime/lib/mirrors_patch_cfe.dart" + supported: false + typed_data: uri: "typed_data/typed_data.dart" patches: "_internal/js_runtime/lib/typed_data_patch.dart" @@ -421,6 +431,11 @@ dartdevc: patches: "_internal/js_dev_runtime/patch/isolate_patch.dart" supported: false + mirrors: + uri: "mirrors/mirrors.dart" + patches: "_internal/js_runtime/lib/mirrors_patch_cfe.dart" + supported: false + math: uri: "math/math.dart" patches: "_internal/js_dev_runtime/patch/math_patch.dart" diff --git a/sdk_nnbd/lib/_internal/js_runtime/lib/mirrors_patch_cfe.dart b/sdk_nnbd/lib/_internal/js_runtime/lib/mirrors_patch_cfe.dart new file mode 100644 index 00000000000..cd961a023a9 --- /dev/null +++ b/sdk_nnbd/lib/_internal/js_runtime/lib/mirrors_patch_cfe.dart @@ -0,0 +1,44 @@ +// Copyright (c) 2012, 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. + +// Patch library for dart:mirrors. + +import 'dart:_js_helper' show patch; +import 'dart:mirrors'; + +const String _message = 'dart:mirrors is no longer supported for web apps'; + +@patch +MirrorSystem currentMirrorSystem() => throw new UnsupportedError(_message); + +@patch +InstanceMirror reflect(dynamic reflectee) => + throw new UnsupportedError(_message); + +@patch +ClassMirror reflectClass(Type key) => throw new UnsupportedError(_message); + +@patch +TypeMirror reflectType(Type key, [List typeArguments]) => + throw new UnsupportedError(_message); + +@patch +abstract class MirrorSystem { + Map get libraries; + IsolateMirror get isolate; + TypeMirror get dynamicType; + TypeMirror get voidType; + TypeMirror get neverType; + + @patch + LibraryMirror findLibrary(Symbol libraryName) => + throw new UnsupportedError(_message); + + @patch + static String getName(Symbol symbol) => throw new UnsupportedError(_message); + + @patch + static Symbol getSymbol(String name, [LibraryMirror library]) => + throw new UnsupportedError(_message); +} diff --git a/sdk_nnbd/lib/libraries.json b/sdk_nnbd/lib/libraries.json index 208de69dee5..4960b8b5fda 100644 --- a/sdk_nnbd/lib/libraries.json +++ b/sdk_nnbd/lib/libraries.json @@ -217,6 +217,11 @@ "uri": "math/math.dart", "patches": "_internal/js_runtime/lib/math_patch.dart" }, + "mirrors": { + "uri": "mirrors/mirrors.dart", + "patches": "_internal/js_runtime/lib/mirrors_patch_cfe.dart", + "supported": false + }, "typed_data": { "uri": "typed_data/typed_data.dart", "patches": "_internal/js_runtime/lib/typed_data_patch.dart" @@ -322,6 +327,11 @@ "uri": "math/math.dart", "patches": "_internal/js_runtime/lib/math_patch.dart" }, + "mirrors": { + "uri": "mirrors/mirrors.dart", + "patches": "_internal/js_runtime/lib/mirrors_patch_cfe.dart", + "supported": false + }, "typed_data": { "uri": "typed_data/typed_data.dart", "patches": "_internal/js_runtime/lib/typed_data_patch.dart" @@ -428,6 +438,11 @@ "patches": "_internal/js_dev_runtime/patch/isolate_patch.dart", "supported": false }, + "mirrors": { + "uri": "mirrors/mirrors.dart", + "patches": "_internal/js_runtime/lib/mirrors_patch_cfe.dart", + "supported": false + }, "math": { "uri": "math/math.dart", "patches": "_internal/js_dev_runtime/patch/math_patch.dart" diff --git a/sdk_nnbd/lib/libraries.yaml b/sdk_nnbd/lib/libraries.yaml index 8dd0eeb92d4..b37041a3f67 100644 --- a/sdk_nnbd/lib/libraries.yaml +++ b/sdk_nnbd/lib/libraries.yaml @@ -214,6 +214,11 @@ dart2js: uri: "math/math.dart" patches: "_internal/js_runtime/lib/math_patch.dart" + mirrors: + uri: "mirrors/mirrors.dart" + patches: "_internal/js_runtime/lib/mirrors_patch_cfe.dart" + supported: false + typed_data: uri: "typed_data/typed_data.dart" patches: "_internal/js_runtime/lib/typed_data_patch.dart" @@ -317,6 +322,11 @@ dart2js_server: uri: "math/math.dart" patches: "_internal/js_runtime/lib/math_patch.dart" + mirrors: + uri: "mirrors/mirrors.dart" + patches: "_internal/js_runtime/lib/mirrors_patch_cfe.dart" + supported: false + typed_data: uri: "typed_data/typed_data.dart" patches: "_internal/js_runtime/lib/typed_data_patch.dart" @@ -421,6 +431,11 @@ dartdevc: patches: "_internal/js_dev_runtime/patch/isolate_patch.dart" supported: false + mirrors: + uri: "mirrors/mirrors.dart" + patches: "_internal/js_runtime/lib/mirrors_patch_cfe.dart" + supported: false + math: uri: "math/math.dart" patches: "_internal/js_dev_runtime/patch/math_patch.dart"