From 263820ad70d907813363cb4e1d47ef4e4cb46d36 Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Tue, 21 May 2024 21:01:58 +0000 Subject: [PATCH 1/4] Macro. Issue 46392. Use the same Identifier for all augmentations. Bug: https://github.com/dart-lang/sdk/issues/46392 Change-Id: Ib175cb3f0be6108c4f8b180526dd04e3ef3b2670 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/367280 Reviewed-by: Brian Wilkerson Commit-Queue: Konstantin Shcheglov --- .../lib/src/summary2/macro_declarations.dart | 10 +++---- pkg/analyzer/test/src/summary/macro_test.dart | 29 +++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/pkg/analyzer/lib/src/summary2/macro_declarations.dart b/pkg/analyzer/lib/src/summary2/macro_declarations.dart index 6a9272ee55e9..bd5ba4b5b020 100644 --- a/pkg/analyzer/lib/src/summary2/macro_declarations.dart +++ b/pkg/analyzer/lib/src/summary2/macro_declarations.dart @@ -1616,23 +1616,23 @@ class DeclarationBuilderFromNode { switch (parentNode) { case ast.ClassDeclaration(): var parentElement = parentNode.declaredElement!; - var typeElement = parentElement.augmentationTarget ?? parentElement; + var typeElement = parentElement.augmented.declaration; return _declaredIdentifier(parentNode.name, typeElement); case ast.EnumDeclaration(): var parentElement = parentNode.declaredElement!; - var typeElement = parentElement.augmentationTarget ?? parentElement; + var typeElement = parentElement.augmented.declaration; return _declaredIdentifier(parentNode.name, typeElement); case ast.ExtensionDeclaration(): var parentElement = parentNode.declaredElement!; - var typeElement = parentElement.augmentationTarget ?? parentElement; + var typeElement = parentElement.augmented.declaration; return _declaredIdentifier2(parentNode.name?.lexeme ?? '', typeElement); case ast.ExtensionTypeDeclaration(): var parentElement = parentNode.declaredElement!; - var typeElement = parentElement.augmentationTarget ?? parentElement; + var typeElement = parentElement.augmented.declaration; return _declaredIdentifier(parentNode.name, typeElement); case ast.MixinDeclaration(): var parentElement = parentNode.declaredElement!; - var typeElement = parentElement.augmentationTarget ?? parentElement; + var typeElement = parentElement.augmented.declaration; return _declaredIdentifier(parentNode.name, typeElement); default: // TODO(scheglov): other parents diff --git a/pkg/analyzer/test/src/summary/macro_test.dart b/pkg/analyzer/test/src/summary/macro_test.dart index 59190a2d5ffe..c0a46456c9ed 100644 --- a/pkg/analyzer/test/src/summary/macro_test.dart +++ b/pkg/analyzer/test/src/summary/macro_test.dart @@ -1302,6 +1302,35 @@ class MacroCodeGenerationTest extends MacroElementsBaseTest { ); } + test_class_addMethod2_augmentMethod2() async { + var library = await buildLibrary(r''' +import 'append.dart'; + +@DeclareInType(""" + @{{package:test/append.dart@AugmentDefinition}}('{}') + void foo();""") +@DeclareInType(""" + @{{package:test/append.dart@AugmentDefinition}}('{}') + void bar();""") +class A {} +'''); + + _assertMacroCode(library, r''' +augment library 'package:test/test.dart'; + +import 'package:test/append.dart' as prefix0; + +augment class A { + @prefix0.AugmentDefinition('{}') + void bar(); + @prefix0.AugmentDefinition('{}') + void foo(); + augment void foo() {} + augment void bar() {} +} +'''); + } + test_declarationsPhase_metadata_class_type() async { var library = await buildLibrary(r''' import 'code_generation.dart'; From e5e2c925c030956c4bdd60dcf1f9bbd450aa869b Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Tue, 21 May 2024 21:10:29 +0000 Subject: [PATCH 2/4] [docs] remove older pages Change-Id: I6567aa21fe036929fb036551901823dc2926468f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/367480 Reviewed-by: Hossein Yousefi Commit-Queue: Devon Carew --- docs/Building.md | 7 - docs/Chrome-63-Dart-Web-Libraries.md | 185 -------------------------- docs/Commit-Message-Best-Practices.md | 7 - docs/Publishing-package-analyzer.md | 22 --- docs/Writing-Web-Browser-Tests.md | 132 ------------------ 5 files changed, 353 deletions(-) delete mode 100644 docs/Chrome-63-Dart-Web-Libraries.md delete mode 100644 docs/Publishing-package-analyzer.md delete mode 100644 docs/Writing-Web-Browser-Tests.md diff --git a/docs/Building.md b/docs/Building.md index 13aeeb11df84..23acfd82abf0 100644 --- a/docs/Building.md +++ b/docs/Building.md @@ -1,10 +1,3 @@ -> [!IMPORTANT] -> This page was copied from https://github.com/dart-lang/sdk/wiki and needs review. -> Please [contribute](../CONTRIBUTING.md) changes to bring it up-to-date - -> removing this header - or send a CL to delete the file. - ---- - [Dependencies](#dependencies) [Getting the source](#source) diff --git a/docs/Chrome-63-Dart-Web-Libraries.md b/docs/Chrome-63-Dart-Web-Libraries.md deleted file mode 100644 index 0cca85b8ebcb..000000000000 --- a/docs/Chrome-63-Dart-Web-Libraries.md +++ /dev/null @@ -1,185 +0,0 @@ -> [!IMPORTANT] -> This page was copied from https://github.com/dart-lang/sdk/wiki and needs review. -> Please [contribute](../CONTRIBUTING.md) changes to bring it up-to-date - -> removing this header - or send a CL to delete the file. - ---- - -The Dart Web Libraries have not been updated since Chrome 50. With this release these libraries have been rev’d to the Chrome 63 APIs (WebIDLs). Below are the known differences between the Chrome 50 and Chrome 63 Dart Web libraries. These are the changes that have affected Dart user’s code: - -* Touch and TouchEvent change - - _initTouchEvent removed see [Chrome Change](https://www.chromestatus.com/features/4923255479599104) - - Example of [Migrating initTouchEvent to Map](https://developers.google.com/web/updates/2016/09/chrome-54-deprecations#use_of_inittouchevent_is_removed) -* TouchEvent constructor takes a map argument, strong mode catches these failures in our tests. -* Web_audio - - AudioBufferSourceNode extends AudioScheduledSourceNode there are two start methods - - AudioScheduledSourceNode.start can't be overloaded and will become operation void start2([num when]); - - AudioBufferSourceNode.start([num when, num grainOffset, num grainDuration]) is void start([num when, num grainOffset, num grainDuration]) -* Attributes of type double changed num see section "**Attributes Type Change double to num**" at the end of this document. -* onWheel event exposed -* Created for union of two kinds of canvas HTMLCanvasElement and OffscreenCanvas interface WebGLCanvas -* all other RenderingContext - - readonly attribute WebGLCanvas canvas; -* interface WebGLRenderingContext - - readonly attribute HTMLCanvasElement canvas; -* KeygenElement was removed in Chrome 57 -* IDBFactory.webkitGetDatabaseNames() constructor removed in Chrome -* Depreciated FileError and DomError have been removed use DomException - - error.code replaced with error.name (e.g., see fileapi_directory_test.dart) - - Additional because FileError is gone there is no easy way to determine which errors are File only errors. However, these are: - - NOT_FOUND_ERR - - SECURITY_ERR - - ABORT_ERR - - NO_MODIFICATION_ALLOWED_ERR - - INVALID_STATE_ERR - - SYNTAX_ERR - - INVALID_MODIFICATION_ERR - - QUOTA_EXCEEDED_ERR - - TYPE_MISMATCH_ERR -* registerElement and register maps to old style (Chrome 50) -* registerElement2 2nd parameter is a map {'prototype': xxx, 'extends': xxxx} not 2 separate arguments. -* List getClientRects() is now DomRectList getClientRects() -* Rectangle getBoundingClientRect() is now DomRect getBoundingClientRect() -* postMessage(/*any*/ message, String targetOrigin, [List transfer]) changed to void postMessage(/*any*/ message, String targetOrigin, [List transfer]) transfer can now be ArrayBuffer, MessagePort and ImageBitmap -* RTCPeerConnection.setLocalDescription and setRemoteDescription - - takes a Map setLocalDescription(Map description) description is a map e.g., {'type': localSessionDescription, 'sdp': fakeLensSdp} -* nounce removed from HtmlScriptElement added to HtmlElement - - https://codereview.chromium.org/2801243002 - - https://github.com/whatwg/html/issues/2369 -* Event.deepPath() was removed Chrome 54 - - https://developer.mozilla.org/en-US/docs/Web/API/Event/deepPath -* Event.scoped replaced by Event.composed - - https://developer.mozilla.org/en-US/docs/Web/API/Event/composed - -*** -Summary of API changes from Chrome 51 thru Chrome 63: -

-[https://developers.google.com/web/updates/tags/chrome51](https://developers.google.com/web/updates/tags/chrome51) -
-[https://developers.google.com/web/updates/tags/chrome52](https://developers.google.com/web/updates/tags/chrome52) -
-[https://developers.google.com/web/updates/tags/chrome53](https://developers.google.com/web/updates/tags/chrome53) -
-[https://developers.google.com/web/updates/tags/chrome54](https://developers.google.com/web/updates/tags/chrome54) -
-[https://developers.google.com/web/updates/tags/chrome55](https://developers.google.com/web/updates/tags/chrome55) -
-[https://developers.google.com/web/updates/tags/chrome56](https://developers.google.com/web/updates/tags/chrome56) -
-[https://developers.google.com/web/updates/tags/chrome57](https://developers.google.com/web/updates/tags/chrome57) -
-[https://developers.google.com/web/updates/tags/chrome58](https://developers.google.com/web/updates/tags/chrome58) -
-[https://developers.google.com/web/updates/tags/chrome59](https://developers.google.com/web/updates/tags/chrome59) -
-[https://developers.google.com/web/updates/tags/chrome60](https://developers.google.com/web/updates/tags/chrome60) -
-[https://developers.google.com/web/updates/tags/chrome61](https://developers.google.com/web/updates/tags/chrome61) -
-[https://developers.google.com/web/updates/tags/chrome62](https://developers.google.com/web/updates/tags/chrome62) -
-[https://developers.google.com/web/updates/tags/chrome63](https://developers.google.com/web/updates/tags/chrome63) -
- -*** -### Attributes Type Change double to num -* Accelerometer - - x, y, z -* AmbientLightSensor - - illuminance -* AnimationEffectTimingReadOnly - - delay, endDelay, iterationStart, iterations -* AnimationEvent - - elapsedTime -* AnimationPlaybackEvent - - currentTime, timelineTime -* AnimationTimeline - - currentTime -* BatteryManager - - chargingTime, dischargingTime, level -* BlobEvent - - timecode -* BudgetState - - budgetAt -* Coordinates - - accuracy, altitude, altitudeAccuracy, heading, latitude, longitude, speed -* CSSImageValue - - intrinsicHeight,intrinsicRatio, intrinsicWidth -* DeviceAcceleration - - x, y, z -* DeviceOrientationEvent - - alpha, beta, gamma -* DeviceRotationRate - - alpha, beta, gamma -* Event - - timeStamp -* GamepadButton - - value -* Gyroscope - - x, y, z -* IntersectionObserverEntry - - intersectionRatio, time -* Magnetometer - - x, y, z -* HTMLMediaElement - - duration -* MediaKeySession - - expiration -* MediaSettingsRange - - max. min, step -* MouseEvent - - clientX, clientY, pageX, pageY, screenX, screenY -* Navigator - - deviceMemory -* NetworkInformation - - downlink, downlinkMax -* PaintSize - - height, width -* PaintWorkletGlobalScope - - devicePixelRatio -* Performance - - timeOrigin -* PerformanceEntry - - duration, startTime -* PerformanceNavigationTiming - - domComplete, domContentLoadedEventEnd, domContentLoadedEventStart, domInteractive, loadEventEnd, loadEventStart, redirectCount, unloadEventEnd, unloadEventStart -* PerformanceResourceTiming - - connectEnd, connectStart, domainLookupEnd, domainLookupStart, encodedBodySize, fetchStart, redirectStart, requestStart, responseEnd, responseStart, secureConnectionStart, workerStart -* PointerEvent - - height, pressure, tangentialPressure, width -* HTMLProgressElement - - position -* RTCRtpContributingSource - - timestamp -* ScrollState - - deltaGranularity, deltaX, deltaY, velocityX, velocityY -* Sensor - - timestamp -* SpeechRecognitionAlternative - - confidence -* SpeechSynthesisEvent - - elapsedTime -* TextMetrics - - actualBoundingBoxAscent, actualBoundingBoxDescent, actualBoundingBoxLeft, actualBoundingBoxRight, alphabeticBaseline, emHeightAscent, emHeightDescent, fontBoundingBoxAscent, fontBoundingBoxDescent, hangingBaseline, ideographicBaseline, width -* Touch - - clientX, clientY, force, pageX, pageY, radiusX, radiusY, rotationAngle, screenX, screenY -* TransitionEvent - - elapsedTime -* VRFrameOfReference - - emulatedHeight -* VRStageBoundsPoint - - x, z -* VRStageParameters - - sizeX, sizeZ -* VideoPlaybackQuality - - creationTime -* VisualViewport - - height, offsetLeft, offsetTop, pageLeft, pageTop, sca, width -* WheelEvent - - deltaX, deltaY, deltaZ -* Window - - devicePixelRatio, pageXOffset, pageYOffset -* WorkerPerformance - - timeOrigin -* XPathResult - - numberValue diff --git a/docs/Commit-Message-Best-Practices.md b/docs/Commit-Message-Best-Practices.md index 2f079aabb2bc..6084d0d1c7b0 100644 --- a/docs/Commit-Message-Best-Practices.md +++ b/docs/Commit-Message-Best-Practices.md @@ -1,10 +1,3 @@ -> [!IMPORTANT] -> This page was copied from https://github.com/dart-lang/sdk/wiki and needs review. -> Please [contribute](../CONTRIBUTING.md) changes to bring it up-to-date - -> removing this header - or send a CL to delete the file. - ---- - 1. First line is a capitalized, short (50 chars or less) summary, * Please include the component for which the change is being made in the first line * **[Analyzer]** short (50 chars or less) summary diff --git a/docs/Publishing-package-analyzer.md b/docs/Publishing-package-analyzer.md deleted file mode 100644 index 9402e3c3a393..000000000000 --- a/docs/Publishing-package-analyzer.md +++ /dev/null @@ -1,22 +0,0 @@ -> [!IMPORTANT] -> This page was copied from https://github.com/dart-lang/sdk/wiki and needs review. -> Please [contribute](../CONTRIBUTING.md) changes to bring it up-to-date - -> removing this header - or send a CL to delete the file. - ---- - -## Publishing an alpha version - -`package:analyzer` depends on kernel and front_end. We push those last two packages for the benefit of `package:analyzer`, but their APIs don't currently follow semver, so we set analyzer to depend on exact versions. - -Publishing a new alpha version of package analyzer involves a few steps: -- rev package:analyzer to a new alpha version (`0.31.0-alpha.0` ==> `0.31.0-alpha.1`) -- rev package:front_end to a new alpha version; update its version of package:kernel (see the next line) -- rev package:kernel to a new alpha version; update its version of package:front_end -- update the kernel and front_end version in `package:analyzer`'s pubspec -- commit a CL with the above changes -- publish `package:analyzer`, `package:kernel`, and `package:front_end` - -## Publishing a new stable version - -Many packages depend on `package:analyzer`. These packages often have version constraints that have an upper bound on the last major version of the analyzer. Publishing a new major version of `package:analyzer` requires careful orchestration with other major packages in the Dart ecosystem (in particular, `package:test`, and to a lesser extent, `package:angular`). diff --git a/docs/Writing-Web-Browser-Tests.md b/docs/Writing-Web-Browser-Tests.md deleted file mode 100644 index 762b338440cc..000000000000 --- a/docs/Writing-Web-Browser-Tests.md +++ /dev/null @@ -1,132 +0,0 @@ -> [!IMPORTANT] -> This page was copied from https://github.com/dart-lang/sdk/wiki and needs review. -> Please [contribute](../CONTRIBUTING.md) changes to bring it up-to-date - -> removing this header - or send a CL to delete the file. - ---- - -# Who is this article for? - -If you are writing tests of core parts of the Dart SDK, there are special -tools to run these tests on browsers. If you are writing tests for a package -that is not part of the Dart SDK distribution, then -[package:test](http://github.com/dart-lang/test/blob/master/README.md), -previously called "unittest", is the best way for you to write your unit tests -for browsers and the standalone Dart vm. Published Dart packages are -automatically tested using [Drone.io](http://readme.drone.io/pub/overview). - -The remainder of this article is about the browser test infrastructure for -core Dart libraries and tools in the Dart repository. These test suites -are run by the tools/test.py tool, -and can be run on web browsers as well as the standalone Dart vm. -In the most common case, Dart scripts are wrapped in an automatically-created -HTML wrapper page, and compiled to JS using dart2js, to run on web browsers. - -Usually, this is the best way to test dart:html or other web features, -but a few complex cases require us to write a custom html file, rather -than using the HTML wrapper file. - - -# Details - -A test script testing Dart's web libraries, for example a test in -tests/html, will create the DOM elements it needs to test in the test -script itself. WebPlatformTest tests in the test/co19 test suite will -add HTML or DOM elements to the document, and then operate on them. -This is the best way to create and test a web page. For example, the -test -WebPlatformTest/html/semantics/tabular-data/the-table-element/insertRow-method\_t01.dart -contains the following Dart code: - -```dart -const String htmlEL = r''' -
- - -
-
-
-'''; - -void main() { - document.body.appendHtml(htmlEL); - ... -} -``` - -## Running Tests - -When a test is run on a browser, the wrapper HTML file, and the -modified or compiled Dart scripts are put into a directory called -generated\_tests, under the build directory that the Dart executable -and SDK are built in. The test server runs a local HTTP server, that -serves files from the build directory, and also from the Dart -repository root, and starts a browser that runs the tests fetched from -this server. To debug a test, you can start this HTTP server, and -then open the test's web page manually in a browser. The output of -test.py includes the command lines necessary to do this. - -## Custom HTML Tests - -If a test requires a custom HTML file, and cannot be written by adding -DOM elements to a page after it is loaded, then the test scripts allow -you to write the HTML file separately, and use it instead. There are -two systems for doing this. The first system adds a custom HTML file -to the test called foo\_test.dart by putting an HTML file called -foo\_test.html in the same directory. The second system creates a -test from any file ending in `_htmltest.html` in that directory, like -bar\_htmltest.html. - -### `_test.html` custom HTML files - -To be filled in - -### `_htmltest.html` tests - -An HTML file with a name that ends in `_htmltest.html` will be read by -the test infrastructure, and metadata about what scripts are used and -what messages the test should post to the document window is read from -an annotation in that file. - -The annotation is a JSON dictionary, embedded between two delimiters, -and it can be put inside an HTML comment so that the unprocessed page -looks like valid HTML: - -```html - -``` - -The test will pass if the web page posts all the strings in the -expectedMessages property to its top-level window, for example by -executing lines like - -```javascript -window.postMessage('squid', '*'); -``` - -Scripts in the 'scripts' property of the annotation will be -automatically copied from the test directory to the generated-test -directory, and compiled from dart to js if necessary. The script tags -using Dart scripts should be written exactly like - -```html - -``` -in order for the test generation to find and modify them. - -In order for the test framework to catch all errors in this HTML test, -the first script that executes on this page must be: - -```html - -``` - This allows the test framework -to attach an error handler to the window at the first opportunity, -before the scripts being tested have run. From ffbbdb5a10a73d598db54823bcc1ce3feda59d07 Mon Sep 17 00:00:00 2001 From: Ryan Macnak Date: Tue, 21 May 2024 21:29:49 +0000 Subject: [PATCH 3/4] [vm, service] Treat the object id ring as strong during major GC. The id ring was treated as a strong root during minor GC and a weak root during major GC. Before mark-through-new-space, new-space objects could not be collected during a major GC, so in practice the policy was that the id ring was strong for all new-space objects. After mark-through-new-space, new-space object can be collected during a major GC, so service ids could expire very quickly, especially for object just created using the service protocol and not otherwise reachable from the Dart program. Given that service id zones have still not been implemented, this makes it impossible to reliably interact with such an object. TEST=ci Bug: https://github.com/flutter/flutter/issues/148704 Change-Id: I0f15c00414f996fad49bcb137c7f1c15bb4955c4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/367440 Reviewed-by: Derek Xu Reviewed-by: Alexander Aprelev Commit-Queue: Ryan Macnak --- runtime/vm/heap/marker.cc | 46 ++++++------------------------- runtime/vm/heap/marker.h | 1 - runtime/vm/object_id_ring_test.cc | 16 +++++------ 3 files changed, 16 insertions(+), 47 deletions(-) diff --git a/runtime/vm/heap/marker.cc b/runtime/vm/heap/marker.cc index aa841c4008ee..623ad6fb7974 100644 --- a/runtime/vm/heap/marker.cc +++ b/runtime/vm/heap/marker.cc @@ -699,7 +699,8 @@ void GCMarker::Epilogue() {} enum RootSlices { kIsolate = 0, - kNumFixedRootSlices = 1, + kObjectIdRing = 1, + kNumFixedRootSlices = 2, }; void GCMarker::ResetSlices() { @@ -727,6 +728,12 @@ void GCMarker::IterateRoots(ObjectPointerVisitor* visitor) { visitor, ValidationPolicy::kDontValidateFrames); break; } + case kObjectIdRing: { + TIMELINE_FUNCTION_GC_DURATION(Thread::Current(), + "ProcessObjectIdTable"); + isolate_group_->VisitObjectIdRingPointers(visitor); + break; + } } MonitorLocker ml(&root_slices_monitor_); @@ -740,7 +747,6 @@ void GCMarker::IterateRoots(ObjectPointerVisitor* visitor) { enum WeakSlices { kWeakHandles = 0, kWeakTables, - kObjectIdRing, kRememberedSet, kNumWeakSlices, }; @@ -759,9 +765,6 @@ void GCMarker::IterateWeakRoots(Thread* thread) { case kWeakTables: ProcessWeakTables(thread); break; - case kObjectIdRing: - ProcessObjectIdTable(thread); - break; case kRememberedSet: ProcessRememberedSet(thread); break; @@ -851,39 +854,6 @@ void GCMarker::ProcessRememberedSet(Thread* thread) { store_buffer->PushBlock(writing, StoreBuffer::kIgnoreThreshold); } -class ObjectIdRingClearPointerVisitor : public ObjectPointerVisitor { - public: - explicit ObjectIdRingClearPointerVisitor(IsolateGroup* isolate_group) - : ObjectPointerVisitor(isolate_group) {} - - void VisitPointers(ObjectPtr* first, ObjectPtr* last) override { - for (ObjectPtr* current = first; current <= last; current++) { - ObjectPtr obj = *current; - ASSERT(obj->IsHeapObject()); - if (!obj->untag()->IsMarked()) { - // Object has become garbage. Replace it will null. - *current = Object::null(); - } - } - } - -#if defined(DART_COMPRESSED_POINTERS) - void VisitCompressedPointers(uword heap_base, - CompressedObjectPtr* first, - CompressedObjectPtr* last) override { - UNREACHABLE(); // ObjectIdRing is not compressed. - } -#endif -}; - -void GCMarker::ProcessObjectIdTable(Thread* thread) { -#ifndef PRODUCT - TIMELINE_FUNCTION_GC_DURATION(thread, "ProcessObjectIdTable"); - ObjectIdRingClearPointerVisitor visitor(isolate_group_); - isolate_group_->VisitObjectIdRingPointers(&visitor); -#endif // !PRODUCT -} - class ParallelMarkTask : public ThreadPool::Task { public: ParallelMarkTask(GCMarker* marker, diff --git a/runtime/vm/heap/marker.h b/runtime/vm/heap/marker.h index b9755bb35ae5..d799b2b56b7d 100644 --- a/runtime/vm/heap/marker.h +++ b/runtime/vm/heap/marker.h @@ -62,7 +62,6 @@ class GCMarker { void ProcessWeakHandles(Thread* thread); void ProcessWeakTables(Thread* thread); void ProcessRememberedSet(Thread* thread); - void ProcessObjectIdTable(Thread* thread); // Called by anyone: finalize and accumulate stats from 'visitor'. template diff --git a/runtime/vm/object_id_ring_test.cc b/runtime/vm/object_id_ring_test.cc index 8ece9933a053..d391e8918311 100644 --- a/runtime/vm/object_id_ring_test.cc +++ b/runtime/vm/object_id_ring_test.cc @@ -195,7 +195,7 @@ TEST_CASE(ObjectIdRingScavengeMoveTest) { EXPECT_EQ(3, list_length); } -// Test that the ring table is updated with nulls when the old GC collects. +// Test that the ring table is updated when major GC runs. ISOLATE_UNIT_TEST_CASE(ObjectIdRingOldGCTest) { Isolate* isolate = thread->isolate(); ObjectIdRing* ring = isolate->EnsureObjectIdRing(); @@ -229,16 +229,16 @@ ISOLATE_UNIT_TEST_CASE(ObjectIdRingOldGCTest) { UntaggedObject::ToAddr(raw_obj2)); // Exit scope. Freeing String handle. } - // Force a GC. No reference exist to the old string anymore. It should be - // collected and the object id ring will now return the null object for - // those ids. + // Force a GC. No other reference to the old string exists, but the service id + // should keep it alive. GCTestHelper::CollectOldSpace(); ObjectPtr raw_object_moved1 = ring->GetObjectForId(raw_obj_id1, &kind); - EXPECT_EQ(ObjectIdRing::kCollected, kind); - EXPECT_EQ(Object::null(), raw_object_moved1); + EXPECT_EQ(ObjectIdRing::kValid, kind); + EXPECT(raw_object_moved1->IsOneByteString()); ObjectPtr raw_object_moved2 = ring->GetObjectForId(raw_obj_id2, &kind); - EXPECT_EQ(ObjectIdRing::kCollected, kind); - EXPECT_EQ(Object::null(), raw_object_moved2); + EXPECT_EQ(ObjectIdRing::kValid, kind); + EXPECT(raw_object_moved2->IsOneByteString()); + EXPECT_EQ(raw_object_moved1, raw_object_moved2); } // Test that the ring table correctly reports an entry as expired when it is From bd8f87d477cc515caf2d2a2f4a6b5f540486e4f2 Mon Sep 17 00:00:00 2001 From: Kallen Tu Date: Tue, 21 May 2024 22:15:11 +0000 Subject: [PATCH 4/4] [wildcard-variables] Test non-binding behaviour with top-level declarations. Added a little section for late wildcard variables too. This CL tests mixing top-level wildcard declarations with local wildcard declarations and the non-shadowing, non-binding behaviour. Bug: https://github.com/dart-lang/sdk/issues/55652 Change-Id: I72e7cfb1b2d80a3934af355579c36252881cf3fb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/367241 Reviewed-by: Lasse Nielsen Commit-Queue: Kallen Tu --- .../local_declaration_local_test.dart | 6 +++ .../non_binding/class_members_test.dart | 50 +++++++++++++++++++ .../non_binding/top_level_function_test.dart | 28 +++++++++++ .../non_binding/top_level_typedef_test.dart | 36 +++++++++++++ .../non_binding/top_level_variable_test.dart | 34 +++++++++++++ 5 files changed, 154 insertions(+) create mode 100644 tests/language/wildcard_variables/non_binding/class_members_test.dart create mode 100644 tests/language/wildcard_variables/non_binding/top_level_function_test.dart create mode 100644 tests/language/wildcard_variables/non_binding/top_level_typedef_test.dart create mode 100644 tests/language/wildcard_variables/non_binding/top_level_variable_test.dart diff --git a/tests/language/wildcard_variables/multiple/local_declaration_local_test.dart b/tests/language/wildcard_variables/multiple/local_declaration_local_test.dart index 23a36831f609..26deefa37a01 100644 --- a/tests/language/wildcard_variables/multiple/local_declaration_local_test.dart +++ b/tests/language/wildcard_variables/multiple/local_declaration_local_test.dart @@ -16,4 +16,10 @@ void main() { int _; final _; + + late int _; + late int _ = 2; + + late final int _; + late final int _ = 2; } diff --git a/tests/language/wildcard_variables/non_binding/class_members_test.dart b/tests/language/wildcard_variables/non_binding/class_members_test.dart new file mode 100644 index 000000000000..b21a5b0d93d1 --- /dev/null +++ b/tests/language/wildcard_variables/non_binding/class_members_test.dart @@ -0,0 +1,50 @@ +// 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. + +// Test the interactions between a wildcard class members, which are binding, +// with local non-binding wildcard variables. + +// SharedOptions=--enable-experiment=wildcard-variables + +import 'package:expect/expect.dart'; + +void main() { + InstanceMember().member(); + StaticMember().member(); +} + +class InstanceMember { + var _ = 2; + + void member<_, _>() { + int _ = _; + int _ = 2; + const _ = 2; + int _() => 2; + _ = 3; + Expect.equals(3, _); + + int _() => 2; + + int foo<_>([int _ = 5]) => _; + Expect.equals(3, foo()); + } +} + +class StaticMember { + static const _ = 2; + + void member<_, _>() { + int _ = _; + int _ = 2; + const _ = 2; + const _ = _ - 1; + int _() => 2; + _ = 3; + Expect.equals(3, _); + + int foo<_>([int _ = _ + 1]) => _; + Expect.equals(3, foo()); + } +} diff --git a/tests/language/wildcard_variables/non_binding/top_level_function_test.dart b/tests/language/wildcard_variables/non_binding/top_level_function_test.dart new file mode 100644 index 000000000000..ce1bc1dd1918 --- /dev/null +++ b/tests/language/wildcard_variables/non_binding/top_level_function_test.dart @@ -0,0 +1,28 @@ +// 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. + +// Test the interactions between a wildcard top-level function, which is +// binding, with local non-binding wildcard variables. + +// SharedOptions=--enable-experiment=wildcard-variables + +import 'package:expect/expect.dart'; + +int _(int _) => 2; + +void main() { + int _ = 1; + const _ = 1; + int _() => 1; + Expect.equals(2, _(1)); +} + +class Clas<_> { + void member<_>() { + int _ = 1; + const _ = 1; + int _() => 1; + Expect.equals(2, _(1)); + } +} diff --git a/tests/language/wildcard_variables/non_binding/top_level_typedef_test.dart b/tests/language/wildcard_variables/non_binding/top_level_typedef_test.dart new file mode 100644 index 000000000000..87be98acdd61 --- /dev/null +++ b/tests/language/wildcard_variables/non_binding/top_level_typedef_test.dart @@ -0,0 +1,36 @@ +// 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. + +// Test the interactions between a wildcard typedef, which is binding, with +// local non-binding wildcard variables. + +// SharedOptions=--enable-experiment=wildcard-variables + +import 'package:expect/expect.dart'; + +typedef _ = Type; + +_ function<_ extends _>([_ _ = _]) => _; + +void main<_ extends _>() { + _ _ = _; + final _ _ = _; + const _ _ = _; + _ foo<_ extends _>([_ _ = int]) => _; + _ bar<_ extends _>([_ _ = _]) => int; + Expect.type(foo()); + Expect.type(bar()); +} + +class CConst { + static const _ = 42; + void member<_>() { + var _ = _; + final _ = _; + const _ = _; + int _() => 1; + int foo<_>([String _ = "$_"]) => _; + _ = foo(); + } +} diff --git a/tests/language/wildcard_variables/non_binding/top_level_variable_test.dart b/tests/language/wildcard_variables/non_binding/top_level_variable_test.dart new file mode 100644 index 000000000000..00f63e0d9e2b --- /dev/null +++ b/tests/language/wildcard_variables/non_binding/top_level_variable_test.dart @@ -0,0 +1,34 @@ +// 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. + +// Test the interactions between a wildcard top-level variable, which is +// binding, with local non-binding wildcard variables. + +// SharedOptions=--enable-experiment=wildcard-variables + +import 'package:expect/expect.dart'; + +var _ = 2; + +void main() { + Clas().member(); + + int _ = _; + int _ = 2; + _ = 3; + Expect.equals(3, _); +} + +class Clas<_> { + void member<_>() { + int _ = _; + int _ = 2; + Expect.equals(2, _); + _ = 4; + Expect.equals(4, _); + + int foo<_>([int _ = 5]) => _; + Expect.equals(4, foo()); + } +}