Skip to content

[Records] Core library updates #49727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
itsjustkevin opened this issue Aug 19, 2022 · 8 comments
Closed

[Records] Core library updates #49727

itsjustkevin opened this issue Aug 19, 2022 · 8 comments
Assignees
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.

Comments

@itsjustkevin
Copy link
Contributor

itsjustkevin commented Aug 19, 2022

Expected updates:

  • Add Record class as superclass of all record types.

  • Add abstract == and hashCode on Record with documentation stating how record equality and hashcode is computed.

  • Consider: static bool identical(Record, Record) on class Record, doing deep structure equivalence checks.

  • Add documentation to identical saying how it works for record types.

  • Add documentation to identityHashCode saying how it works for record types (arbitrarily).

  • Add documentation to Expando, WeakReference and Finalizer saying that they do not work with record objects.

Add more as needed.

@a-siva a-siva added the area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. label Aug 19, 2022
@lrhn
Copy link
Member

lrhn commented Jan 2, 2023

We could now add divmod to int as effectively:

(int quotient, int remainder) divmod(int divisor) => (this ~/ divisor, this.remainder(divisor));

Backends can optimize this to ensure we only do one low-level divmod operation, like they try to do now for close-by ~/ and .remainder operations, but users can trust the optimization more this way.

(Could also have divremainder for the above, and make divmod use % and a compatible division instead.)

The usual concern would be whether it should be num.divmod and work on all combinations of integers and doubles, and then we'll have to add language specification rules to type int.divmod(int) as (int, int).

@lrhn
Copy link
Member

lrhn commented Jan 9, 2023

Another possible related addition would be an extension method on Iterable<E> which provides the index along with the value, Iterable<(int, E)> get indexed;. Q.v. #49928.
It would make a lot of the *Indexed extension methods in package:collection unnecessary.

@vsmenon
Copy link
Member

vsmenon commented Feb 6, 2023

Is there any work left here?

@lrhn
Copy link
Member

lrhn commented Mar 3, 2023

There is significant work left. I've started on it, but is focusing on modifiers right now.

Concrete plans:

  • Iterable.indexed extension method
  • Some kind of parallel wait on records of futures, say await (future1, future2, future3).wait or await ~(future1, future2, future3).
  • Possibly parallelizing iterables and streams too: (iterable1, iterable2, iterable3).zip.

@mit-mit
Copy link
Member

mit-mit commented Apr 10, 2023

I think this was completed in https://dart-review.googlesource.com/c/sdk/+/288903, @lrhn ?

@lrhn
Copy link
Member

lrhn commented Apr 10, 2023

I don't think we ever got around to documenting identical and equals for records. I'll do that tomorrow. It's DartDoc only, so it should be uncontroversial.

@mit-mit
Copy link
Member

mit-mit commented Apr 10, 2023

Yeah, but we'll have to cherry pick it, so please file a request for that

@lrhn
Copy link
Member

lrhn commented Apr 16, 2023

The change is cherry-pick requested. Only thing we need to decide if whether we want to do something about dart:mirrors too. (And that's been answered with "no", so I think we're done now.)

@lrhn lrhn closed this as completed May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.
Projects
None yet
Development

No branches or pull requests

5 participants