[XL] Change in dart/sdk[main]: [record_use] Default argument values

0 views
Skip to first unread message

Daco Harkes (Gerrit)

unread,
Mar 5, 2026, 8:34:17 AM (5 days ago) Mar 5
to Nate Biggs, Commit Queue, Alexander Markov, dart2js-te...@google.com, rev...@dartlang.org
Attention needed from Nate Biggs

Daco Harkes voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention is currently required from:
  • Nate Biggs
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I4aa0626964b907438ff7a2a0647dd20cfbacf75a
Gerrit-Change-Number: 485760
Gerrit-PatchSet: 2
Gerrit-Owner: Daco Harkes <dacoh...@google.com>
Gerrit-Reviewer: Daco Harkes <dacoh...@google.com>
Gerrit-Reviewer: Nate Biggs <nate...@google.com>
Gerrit-CC: Alexander Markov <alexm...@google.com>
Gerrit-Attention: Nate Biggs <nate...@google.com>
Gerrit-Comment-Date: Thu, 05 Mar 2026 13:34:12 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

Nate Biggs (Gerrit)

unread,
Mar 6, 2026, 12:55:50 AM (4 days ago) Mar 6
to Daco Harkes, Commit Queue, Alexander Markov, dart2js-te...@google.com, rev...@dartlang.org
Attention needed from Daco Harkes

Nate Biggs added 3 comments

File pkg/compiler/lib/src/js_backend/annotations.dart
Line 503, Patchset 2 (Latest): bool hasNoElision(MemberEntity member) {
Nate Biggs . unresolved

We're modifying the runtime behavior of programs somewhat significantly with these record use annotations. As a user of the annotations I wouldn't want my code to get worse because I'm using them.

Suppose a package owner decides to add one of these annotations on a class/member. Some users of that package might not use the record use data but they still have to pay the penalty for it.

This applies to both the inlining and now this eliding logic. I know it makes the tracking a bit easier to do these but I wonder if we can't find a way to preserve the runtime optimizations.

Line 504, Patchset 2 (Latest): if (_hasPragma(member, PragmaAnnotation.noElision) ||
Nate Biggs . unresolved

Similar to what we did with inlining can we use the `implies` map here?

Line 508, Patchset 2 (Latest): final cls = member.enclosingClass;
Nate Biggs . unresolved

I don't think putting `@RecordUse` on a class should mean the constructor doesn't have it's fields elided. I think they should have to put the annotation on the constructor itself.

Though see above comment.

Open in Gerrit

Related details

Attention is currently required from:
  • Daco Harkes
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I4aa0626964b907438ff7a2a0647dd20cfbacf75a
Gerrit-Change-Number: 485760
Gerrit-PatchSet: 2
Gerrit-Owner: Daco Harkes <dacoh...@google.com>
Gerrit-Reviewer: Daco Harkes <dacoh...@google.com>
Gerrit-Reviewer: Nate Biggs <nate...@google.com>
Gerrit-CC: Alexander Markov <alexm...@google.com>
Gerrit-Attention: Daco Harkes <dacoh...@google.com>
Gerrit-Comment-Date: Fri, 06 Mar 2026 05:55:48 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
unsatisfied_requirement
satisfied_requirement
open
diffy

Daco Harkes (Gerrit)

unread,
Mar 6, 2026, 9:21:18 AM (4 days ago) Mar 6
to Nate Biggs, Commit Queue, Alexander Markov, dart2js-te...@google.com, rev...@dartlang.org
Attention needed from Nate Biggs

Daco Harkes voted and added 3 comments

Votes added by Daco Harkes

Commit-Queue+1

3 comments

File pkg/compiler/lib/src/js_backend/annotations.dart
Line 503, Patchset 2: bool hasNoElision(MemberEntity member) {
Nate Biggs . resolved

We're modifying the runtime behavior of programs somewhat significantly with these record use annotations. As a user of the annotations I wouldn't want my code to get worse because I'm using them.

Suppose a package owner decides to add one of these annotations on a class/member. Some users of that package might not use the record use data but they still have to pay the penalty for it.

This applies to both the inlining and now this eliding logic. I know it makes the tracking a bit easier to do these but I wonder if we can't find a way to preserve the runtime optimizations.

Daco Harkes

Some users of that package might not use the record use data but they still have to pay the penalty for it.

The users of the package will never see the record use data. The package link hook itself will see it.

I know it makes the tracking a bit easier to do these but I wonder if we can't find a way to preserve the runtime optimizations.

For the TFA based ones which happen after constant folding we can. If we record before TFA and then filter the recordings. But I believe that is more complicated than the current approach. So, I'd rather postpone such approach until we have a use case in which we want both the recordings (binary size reduction of app) and the optimizations (speed).

Line 504, Patchset 2: if (_hasPragma(member, PragmaAnnotation.noElision) ||
Nate Biggs . resolved

Similar to what we did with inlining can we use the `implies` map here?

Daco Harkes

Done.

Unfortunately, we cannot do it not with the enclosing class.

Line 508, Patchset 2: final cls = member.enclosingClass;
Nate Biggs . resolved

I don't think putting `@RecordUse` on a class should mean the constructor doesn't have it's fields elided. I think they should have to put the annotation on the constructor itself.

Though see above comment.

Daco Harkes

I believe it should. Because we record const instances _and_ all constructor calls to give a complete picture of all instances.

Maybe we should consider having more precise control in the record use annotations: E.g. for static calls you might not be interested in some parameters, so it's fine to elide those. And of const instances you might not be interested in some fields and for constructor calls you might not be interested in some parameters. https://github.com/dart-lang/native/issues/3206 Lets discuss on that issue.

Open in Gerrit

Related details

Attention is currently required from:
  • Nate Biggs
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I4aa0626964b907438ff7a2a0647dd20cfbacf75a
Gerrit-Change-Number: 485760
Gerrit-PatchSet: 3
Gerrit-Owner: Daco Harkes <dacoh...@google.com>
Gerrit-Reviewer: Daco Harkes <dacoh...@google.com>
Gerrit-Reviewer: Nate Biggs <nate...@google.com>
Gerrit-CC: Alexander Markov <alexm...@google.com>
Gerrit-Attention: Nate Biggs <nate...@google.com>
Gerrit-Comment-Date: Fri, 06 Mar 2026 14:21:13 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: Nate Biggs <nate...@google.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Sigmund Cherem (Gerrit)

unread,
Mar 6, 2026, 3:44:08 PM (3 days ago) Mar 6
to Daco Harkes, Sigmund Cherem, Commit Queue, Alexander Markov, dart2js-te...@google.com, rev...@dartlang.org
Attention needed from Daco Harkes

Sigmund Cherem added 5 comments

File pkg/compiler/lib/src/js_backend/annotations.dart
Line 508, Patchset 2: final cls = member.enclosingClass;
Nate Biggs . unresolved

I don't think putting `@RecordUse` on a class should mean the constructor doesn't have it's fields elided. I think they should have to put the annotation on the constructor itself.

Though see above comment.

Daco Harkes

I believe it should. Because we record const instances _and_ all constructor calls to give a complete picture of all instances.

Maybe we should consider having more precise control in the record use annotations: E.g. for static calls you might not be interested in some parameters, so it's fine to elide those. And of const instances you might not be interested in some fields and for constructor calls you might not be interested in some parameters. https://github.com/dart-lang/native/issues/3206 Lets discuss on that issue.

Sigmund Cherem

For my education - can you share a bit more (or link to a doc with details) why we need to avoid eliding the parameters? I understand that it is different than what the user wrote, but ideally they are not making decisions based on the parameters that weren't used.

Part of the implication is whether we could have a special marker to indicate an elided parameter, rather than recomputing the default value. This would still preserve the "shape" the developer expects, but have a special indicator that clarifies that the parameter was not relevant.

Line 510, Patchset 3 (Latest): (classPragmaAnnotations[cls]?.contains(PragmaAnnotation.recordUse) ??
Sigmund Cherem . unresolved

A few thoughts. Not sure if this was already discussed with Nate.

(a) Now that you have the `implies` above - does that mean that noElision is also in the class? Could we check for that instead so we don't encode the implication in multiple places? (I'd still include a comment to explain this is motivated by the record-use scenario, though.)

(b) This is looking very much like the idea of hierarchical metadata that Stephen was pursuing in the past. See for example how late variables are annotated here and the use of DirectiveContet.parent. Would that be a cleaner approach?

File pkg/compiler/lib/src/ssa/codegen.dart
Line 2602, Patchset 3 (Latest): final value = _findConstant(arguments[argumentIndex++]);
Sigmund Cherem . unresolved

mmm... this increment seems premature, the query on the next line should be based on the previous index, correct?

Line 2610, Patchset 3 (Latest): if (argumentIndex <
Sigmund Cherem . unresolved

nit: let's combine with the above to reduce duplicate logic. Suggestion, pushdown the condition to the definition of `value`, so the entire body of this closure may look like:

```
bool value = argumentIndex < arguments.length
? _findConstant(arguments[argumentIndex])
: defaultValue;
if (argumentIndex < ...positionalParameters) {
positionalArguments.add(argumentValue);
} else {
namedArguments[name!] = argumentValue;
}
argumentIndex++;
```
Line 2678, Patchset 3 (Latest): } else if (argumentIndex < arguments.length) {
Sigmund Cherem . unresolved

ditto - hopefully this can also be combined into a single block

Open in Gerrit

Related details

Attention is currently required from:
  • Daco Harkes
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I4aa0626964b907438ff7a2a0647dd20cfbacf75a
Gerrit-Change-Number: 485760
Gerrit-PatchSet: 3
Gerrit-Owner: Daco Harkes <dacoh...@google.com>
Gerrit-Reviewer: Daco Harkes <dacoh...@google.com>
Gerrit-Reviewer: Sigmund Cherem <sig...@google.com>
Gerrit-CC: Alexander Markov <alexm...@google.com>
Gerrit-Attention: Daco Harkes <dacoh...@google.com>
Gerrit-Comment-Date: Fri, 06 Mar 2026 20:44:05 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Daco Harkes <dacoh...@google.com>
Comment-In-Reply-To: Nate Biggs <nate...@google.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Daco Harkes (Gerrit)

unread,
Mar 9, 2026, 4:52:17 AM (22 hours ago) Mar 9
to Sigmund Cherem, Commit Queue, Alexander Markov, dart2js-te...@google.com, rev...@dartlang.org
Attention needed from Sigmund Cherem

Daco Harkes voted and added 5 comments

Votes added by Daco Harkes

Commit-Queue+1

5 comments

File pkg/compiler/lib/src/js_backend/annotations.dart
Line 508, Patchset 2: final cls = member.enclosingClass;
Nate Biggs . unresolved

I don't think putting `@RecordUse` on a class should mean the constructor doesn't have it's fields elided. I think they should have to put the annotation on the constructor itself.

Though see above comment.

Daco Harkes

I believe it should. Because we record const instances _and_ all constructor calls to give a complete picture of all instances.

Maybe we should consider having more precise control in the record use annotations: E.g. for static calls you might not be interested in some parameters, so it's fine to elide those. And of const instances you might not be interested in some fields and for constructor calls you might not be interested in some parameters. https://github.com/dart-lang/native/issues/3206 Lets discuss on that issue.

Sigmund Cherem

For my education - can you share a bit more (or link to a doc with details) why we need to avoid eliding the parameters? I understand that it is different than what the user wrote, but ideally they are not making decisions based on the parameters that weren't used.

Part of the implication is whether we could have a special marker to indicate an elided parameter, rather than recomputing the default value. This would still preserve the "shape" the developer expects, but have a special indicator that clarifies that the parameter was not relevant.

Daco Harkes

We are not always computing the default value. Parameter elision can also happen if only one value was ever passed to a function. That value then gets inlined in the body of that function. This value does not have to be the default value. And the consumer of the recorded uses needs to know what that value was.

Line 510, Patchset 3: (classPragmaAnnotations[cls]?.contains(PragmaAnnotation.recordUse) ??
Sigmund Cherem . resolved

A few thoughts. Not sure if this was already discussed with Nate.

(a) Now that you have the `implies` above - does that mean that noElision is also in the class? Could we check for that instead so we don't encode the implication in multiple places? (I'd still include a comment to explain this is motivated by the record-use scenario, though.)

(b) This is looking very much like the idea of hierarchical metadata that Stephen was pursuing in the past. See for example how late variables are annotated here and the use of DirectiveContet.parent. Would that be a cleaner approach?

Daco Harkes

RE A: The `implies` only works for pragmas within a single definition. But for recording instances the record-use pragma is only on the class and it has effects to not remove any constructors parameters and also not remove any fields. We cannot express this in `implies`.

I've added a comment.

RE B: Oh interesting TIL! I don't think that would work here though. We only want to put the no-elision on the constructors when the record-use pragma is on the class, we don't want to put it on all methods too.

File pkg/compiler/lib/src/ssa/codegen.dart
Line 2602, Patchset 3: final value = _findConstant(arguments[argumentIndex++]);
Sigmund Cherem . resolved

mmm... this increment seems premature, the query on the next line should be based on the previous index, correct?

Daco Harkes

Done

Line 2610, Patchset 3: if (argumentIndex <
Sigmund Cherem . resolved

nit: let's combine with the above to reduce duplicate logic. Suggestion, pushdown the condition to the definition of `value`, so the entire body of this closure may look like:

```
bool value = argumentIndex < arguments.length
? _findConstant(arguments[argumentIndex])
: defaultValue;
if (argumentIndex < ...positionalParameters) {
positionalArguments.add(argumentValue);
} else {
namedArguments[name!] = argumentValue;
}
argumentIndex++;
```
Daco Harkes

Done

Line 2678, Patchset 3: } else if (argumentIndex < arguments.length) {
Sigmund Cherem . resolved

ditto - hopefully this can also be combined into a single block

Daco Harkes

Done

Open in Gerrit

Related details

Attention is currently required from:
  • Sigmund Cherem
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I4aa0626964b907438ff7a2a0647dd20cfbacf75a
Gerrit-Change-Number: 485760
Gerrit-PatchSet: 3
Gerrit-Owner: Daco Harkes <dacoh...@google.com>
Gerrit-Reviewer: Daco Harkes <dacoh...@google.com>
Gerrit-Reviewer: Sigmund Cherem <sig...@google.com>
Gerrit-CC: Alexander Markov <alexm...@google.com>
Gerrit-Attention: Sigmund Cherem <sig...@google.com>
Gerrit-Comment-Date: Mon, 09 Mar 2026 08:52:12 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: Sigmund Cherem <sig...@google.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Sigmund Cherem (Gerrit)

unread,
Mar 9, 2026, 11:23:01 AM (16 hours ago) Mar 9
to Daco Harkes, Sigmund Cherem, Commit Queue, Alexander Markov, dart2js-te...@google.com, rev...@dartlang.org
Attention needed from Daco Harkes

Sigmund Cherem added 1 comment

File pkg/compiler/lib/src/js_backend/annotations.dart
Line 508, Patchset 2: final cls = member.enclosingClass;
Nate Biggs . unresolved

I don't think putting `@RecordUse` on a class should mean the constructor doesn't have it's fields elided. I think they should have to put the annotation on the constructor itself.

Though see above comment.

Daco Harkes

I believe it should. Because we record const instances _and_ all constructor calls to give a complete picture of all instances.

Maybe we should consider having more precise control in the record use annotations: E.g. for static calls you might not be interested in some parameters, so it's fine to elide those. And of const instances you might not be interested in some fields and for constructor calls you might not be interested in some parameters. https://github.com/dart-lang/native/issues/3206 Lets discuss on that issue.

Sigmund Cherem

For my education - can you share a bit more (or link to a doc with details) why we need to avoid eliding the parameters? I understand that it is different than what the user wrote, but ideally they are not making decisions based on the parameters that weren't used.

Part of the implication is whether we could have a special marker to indicate an elided parameter, rather than recomputing the default value. This would still preserve the "shape" the developer expects, but have a special indicator that clarifies that the parameter was not relevant.

Daco Harkes

We are not always computing the default value. Parameter elision can also happen if only one value was ever passed to a function. That value then gets inlined in the body of that function. This value does not have to be the default value. And the consumer of the recorded uses needs to know what that value was.

Sigmund Cherem

Another high-level question, we can take this offline too.

Is record-use always enabled? or is there a compiler flag to decide whether we are recording the data? Having a flag makes some of these debates and nuanced conditions less controversial, since choices that affect performance/code-size only happy when users opt-in, and we can iterate on their performance implication without affecting all existing users.

Open in Gerrit

Related details

Attention is currently required from:
  • Daco Harkes
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I4aa0626964b907438ff7a2a0647dd20cfbacf75a
Gerrit-Change-Number: 485760
Gerrit-PatchSet: 4
Gerrit-Owner: Daco Harkes <dacoh...@google.com>
Gerrit-Reviewer: Daco Harkes <dacoh...@google.com>
Gerrit-Reviewer: Sigmund Cherem <sig...@google.com>
Gerrit-CC: Alexander Markov <alexm...@google.com>
Gerrit-Attention: Daco Harkes <dacoh...@google.com>
Gerrit-Comment-Date: Mon, 09 Mar 2026 15:22:58 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
unsatisfied_requirement
satisfied_requirement
open
diffy

Daco Harkes (Gerrit)

unread,
Mar 9, 2026, 11:32:05 AM (16 hours ago) Mar 9
to Sigmund Cherem, Commit Queue, Alexander Markov, dart2js-te...@google.com, rev...@dartlang.org
Attention needed from Sigmund Cherem

Daco Harkes added 1 comment

File pkg/compiler/lib/src/js_backend/annotations.dart
Line 508, Patchset 2: final cls = member.enclosingClass;
Nate Biggs . unresolved

I don't think putting `@RecordUse` on a class should mean the constructor doesn't have it's fields elided. I think they should have to put the annotation on the constructor itself.

Though see above comment.

Daco Harkes

I believe it should. Because we record const instances _and_ all constructor calls to give a complete picture of all instances.

Maybe we should consider having more precise control in the record use annotations: E.g. for static calls you might not be interested in some parameters, so it's fine to elide those. And of const instances you might not be interested in some fields and for constructor calls you might not be interested in some parameters. https://github.com/dart-lang/native/issues/3206 Lets discuss on that issue.

Sigmund Cherem

For my education - can you share a bit more (or link to a doc with details) why we need to avoid eliding the parameters? I understand that it is different than what the user wrote, but ideally they are not making decisions based on the parameters that weren't used.

Part of the implication is whether we could have a special marker to indicate an elided parameter, rather than recomputing the default value. This would still preserve the "shape" the developer expects, but have a special indicator that clarifies that the parameter was not relevant.

Daco Harkes

We are not always computing the default value. Parameter elision can also happen if only one value was ever passed to a function. That value then gets inlined in the body of that function. This value does not have to be the default value. And the consumer of the recorded uses needs to know what that value was.

Sigmund Cherem

Another high-level question, we can take this offline too.

Is record-use always enabled? or is there a compiler flag to decide whether we are recording the data? Having a flag makes some of these debates and nuanced conditions less controversial, since choices that affect performance/code-size only happy when users opt-in, and we can iterate on their performance implication without affecting all existing users.

Daco Harkes

It is behind a flag right now. We will enable the flag in AOT by default for link hooks. (It's not enable-able at all for JIT, we don't record anything in JIT.)

I think my high level view here is that if we get a ton of adoption, everyone relies on it to tree-shake their assets, and then some Dart code is slow, we have a business case for optimizing performance. Right now, we have a business case for correctness only.

Open in Gerrit

Related details

Attention is currently required from:
  • Sigmund Cherem
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I4aa0626964b907438ff7a2a0647dd20cfbacf75a
Gerrit-Change-Number: 485760
Gerrit-PatchSet: 4
Gerrit-Owner: Daco Harkes <dacoh...@google.com>
Gerrit-Reviewer: Daco Harkes <dacoh...@google.com>
Gerrit-Reviewer: Sigmund Cherem <sig...@google.com>
Gerrit-CC: Alexander Markov <alexm...@google.com>
Gerrit-Attention: Sigmund Cherem <sig...@google.com>
Gerrit-Comment-Date: Mon, 09 Mar 2026 15:32:00 +0000
unsatisfied_requirement
satisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages