Skip to content

Conversation

@sgrekhov
Copy link
Contributor

No description provided.

@sgrekhov sgrekhov requested review from eernstg and srujzs July 10, 2025 10:14
@sgrekhov
Copy link
Contributor Author

I guess that typedef tests in this PR are wrong and we simply should expect an error/warnings. But, please, confirm first. And I'll update the tests accordingly if needed.

Copy link

@srujzs srujzs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

}
}

@JSExport()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a warning so users don't think it makes a difference, but I don't even know if this declaration appears in the CFE, so we might not be able to bubble up a warning here.

IIRC, typedefs are resolved early, so we would never even see CAlias as a type in the kernel.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnniwinther, perhaps you could help us a bit here—does the generated Kernel code allow a backend (in particular, a backend compiling to JS) to detect that there is a type alias whose metadata includes a JSExport? Otherwise, we probably can't emit a warning that this metadata has no effect.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @johnniwinther, I can see that you're on vacation right now. Hope you're having a great time! ;-)

We're planning to land this PR now, but it would still be helpful to get your comment on the above question when you're back.

In particular, it looks like backends can't emit diagnostic messages about metadata on type aliases, because the type aliases are gone when the program has been translated to Kernel code. There may also be other situations where backends just can't emit diagnostic messages because the information is gone.

Do you see a way to allow backends to improve on this situation? Perhaps the declaration of JSExport could have a pragma specifying the kinds of declarations that are appropriate for this type to be used as metadata?

Copy link
Member

@eernstg eernstg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I think it would be helpful to add a comment about the tests that seem to assume that we can do super invocations of members of another object (like otherObject.super.m(), or even otherObject.super<SomeType>.m() because every superinvocation must specify a class from which the search should start, except that this is implicit when the superinvocation occurs inside that class).

One more thing came up, and I asked for input from @johnniwinther in order to clarify the situation around type aliases and Kernel code.

}
}

@JSExport()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnniwinther, perhaps you could help us a bit here—does the generated Kernel code allow a backend (in particular, a backend compiling to JS) to detect that there is a type alias whose metadata includes a JSExport? Otherwise, we probably can't emit a warning that this metadata has no effect.

Copy link
Contributor Author

@sgrekhov sgrekhov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typos fixed and the description updated. PTAL.

@sgrekhov sgrekhov requested a review from eernstg July 14, 2025 13:34
Copy link
Member

@eernstg eernstg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Just continuing one thread)

@eernstg
Copy link
Member

eernstg commented Jul 15, 2025

We could proceed as follows:

All the errors/warnings that we'd ideally want to have are expected in these tests.

Some of those expectations may fail because the implementation of the diagnostics hasn't been completed at this time. Others may fail because it's difficult to do at all (e.g., type aliases may just be gone completely in Kernel code, and it might be a major refactoring effort to change that).

So we'd just approve all the failures with references to suitable issues.

Some tests would then start working as soon as the diagnostics have been implemented. For other tests, we'd clarify the situation; if the desired diagnostic turns out to be impractical to emit (e.g., errors/warnings about type aliases) then the test expectations would be adjusted accordingly.

With a plan along those lines, we could land this PR now.

@sgrekhov, is it true that every desired diagnostic message is expected at this time, or do we have some locations where no message is expected even though we'd like to have it?

@sgrekhov
Copy link
Contributor Author

In this PR jsExport_A06_t04 and jsExport_A06_t07 have no expected diagnostic messages. See dart-lang/sdk#61093. All other tests are passing, but I’m also keeping in mind that we’re waiting for clarification regarding annotated typedefs. For now, the typedef-related tests are passing, but we’ll likely need to update them to expect a warning and create a corresponding SDK issue.

Copy link
Member

@eernstg eernstg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a couple of comments. I found one location where I believe we should expect a diagnostic message (following the plan I suggested).

}
}

@JSExport()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @johnniwinther, I can see that you're on vacation right now. Hope you're having a great time! ;-)

We're planning to land this PR now, but it would still be helpful to get your comment on the above question when you're back.

In particular, it looks like backends can't emit diagnostic messages about metadata on type aliases, because the type aliases are gone when the program has been translated to Kernel code. There may also be other situations where backends just can't emit diagnostic messages because the information is gone.

Do you see a way to allow backends to improve on this situation? Perhaps the declaration of JSExport could have a pragma specifying the kinds of declarations that are appropriate for this type to be used as metadata?

typedef void Foo();
// ^^^
// [analyzer] unspecified
// [web] unspecified
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This expectation is good: It fails for now, and we may not be able to fix it, but right now we just want to expect all the diagnostic messages that we want to have.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be possible for backends to report errors on typedef declarations but not uses through a typedef. So it should be possible to report an error here.

@eernstg
Copy link
Member

eernstg commented Jul 15, 2025

In this PR jsExport_A06_t04 and jsExport_A06_t07 have no expected diagnostic messages

OK, so they would be in the same category: We want those diagnostic messages because @JSExport(...) can't possibly be useful on a local declaration (I think! ;-).

@sgrekhov
Copy link
Contributor Author

Tests updated to expect a warning in case of typedef annotated with @anonymous. dart-lang/sdk#61116

eernstg added 2 commits July 15, 2025 11:35
Fix typo in comment
Fix typo in comment
Copy link
Member

@eernstg eernstg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, landing!

@eernstg eernstg merged commit 07fe586 into dart-lang:master Jul 15, 2025
2 checks passed
copybara-service bot pushed a commit to dart-lang/sdk that referenced this pull request Jul 18, 2025
2025-07-17 sgrekhov22@gmail.com dart-lang/co19#3180. Add `@staticInterop` tests. Part 1. (dart-lang/co19#3256)
2025-07-15 sgrekhov22@gmail.com dart-lang/co19#3180. Add tests checking `name` value (dart-lang/co19#3255)
2025-07-15 sgrekhov22@gmail.com dart-lang/co19#3180. Add `anonymous` annotation tests (dart-lang/co19#3254)
2025-07-15 sgrekhov22@gmail.com dart-lang/co19#3180. Add JSExport tests. Part 4. (dart-lang/co19#3253)

Cq-Include-Trybots: luci.dart.try:analyzer-linux-release-try,dart2js-minified-linux-d8-try
Change-Id: Ice01c51e219f0ca68f92390db029ca3f8a65b7a8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/441140
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Erik Ernst <eernst@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants