Skip to content

Need to decide how to handle forwarding semi-stubs #31649

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

Open
stereotype441 opened this issue Dec 13, 2017 · 9 comments
Open

Need to decide how to handle forwarding semi-stubs #31649

stereotype441 opened this issue Dec 13, 2017 · 9 comments
Labels

Comments

@stereotype441
Copy link
Member

stereotype441 commented Dec 13, 2017

There's an ugly corner case in the front end's forwarding stub handling logic that we need to figure out how to handle properly. I'm calling it a "forwarding semi-stub". Consider the following code (adapted from pkg/front_end/testcases/runtime_checks_new/abstract_override_becomes_forwarding_stub.dart):

class B {
  void f(num x) {}
}
abstract class I<T> {
  void f(T x);
}
class C extends B implements I<num> {
  void f(num x);
}

From one point of view, C::f is not a forwarding stub, because it's an actual abstract method that appears in the user's source code; it's not inserted by the front end. This is the point of view that makes sense for the analyzer, since it cares only about what appears in the user's source code and doesn't need to know about runtime type checks.

From another point of view, C::f is a forwarding stub, because it's a place where a runtime type check needs to be inserted in order to ensure that the appropriate error is thrown when code like this is executed:

main() {
  I<Object> i = new C();
  i.f("oops");
}

We need to decide how this should be represented in kernel. I will follow up with a comment with more information about how it is currently represented.

I will also add a language_2 test verifying that the correct type checks occur in this situation, as well as analyzer tests to make sure that the analyzer behaves correctly.

@stereotype441
Copy link
Member Author

Currently the front end tries to represent a semi-forwarding stub as follows:

  • Procedure.isForwardingStub = false
  • Procedure.function.body = (call to super)
  • Procedure.isAbstract = false

However, after it sets this up, KernelFunctionBuilder.body= winds up setting the body to null, so as a result the semi-forwarding stub winds up looking just like an abstract method without a body, which is no good.

@stereotype441
Copy link
Member Author

Note: borrowing the terminology from #31562 (comment), a forwarding semi-stub needs to have a "super target" (since at runtime there is a super method that needs to be invoked) but it does not need an "interface target" (since the interface target is only needed to ensure that analyzer navigation and error messages refer to a method that exists in the source code, and a forwarding semi-stub corresponds to a method that actually exists in the source code).

@stereotype441
Copy link
Member Author

CC: @sjindel-google

@sjindel-google
Copy link
Contributor

sjindel-google commented Dec 14, 2017

Why can't we represent them the same way as regular forwarding stubs? I.e.:

  • Procedure.isForwardingStub = true
  • Procedure.function.body = (call to super)

We can add another bit to indicate to the analyzer the function existed as an abstract method in the original source. I feel strongly that we shouldn't complicate the semantics of forwarding stubs any more than necessary.

@stereotype441
Copy link
Member Author

@sjindel-google sounds good to me. I'll add it to my list to update the front end accordingly.

@stereotype441
Copy link
Member Author

@sjindel-google do you think you could add the additional bit to indicate to the analyzer that the function existed as an abstract method in the original source? (isForwardingSemiStub, or another name of your choosing) Or should I ask someone else for that?

@sjindel-google
Copy link
Contributor

I can add the bit.

@stereotype441
Copy link
Member Author

Thanks! I'll work on this as soon as I can.

whesse pushed a commit that referenced this issue Dec 15, 2017
Change-Id: I93ada8e3fb00029f5af18753c62deb78b944728d
Reviewed-on: https://dart-review.googlesource.com/29743
Reviewed-by: Samir Jindel <[email protected]>
Commit-Queue: Paul Berry <[email protected]>
@sjindel-google sjindel-google added this to the 2.0 milestone Jan 10, 2018
whesse pushed a commit that referenced this issue Jan 11, 2018
See #31649 for more details about forwarding semi-stubs.

Change-Id: Iaf1153be5ac7f66503b93a362b66ac9585462f6c
Reviewed-on: https://dart-review.googlesource.com/33820
Reviewed-by: Dmitry Stefantsov <[email protected]>
Reviewed-by: Samir Jindel <[email protected]>
Reviewed-by: Konstantin Shcheglov <[email protected]>
Commit-Queue: Paul Berry <[email protected]>
whesse pushed a commit that referenced this issue Jan 11, 2018
This reverts commit 379801e.

Reason for revert: Broke buildbots

Original change's description:
> Fix handling of forwarding semi-stubs in the front end.
> 
> See #31649 for more details about forwarding semi-stubs.
> 
> Change-Id: Iaf1153be5ac7f66503b93a362b66ac9585462f6c
> Reviewed-on: https://dart-review.googlesource.com/33820
> Reviewed-by: Dmitry Stefantsov <[email protected]>
> Reviewed-by: Samir Jindel <[email protected]>
> Reviewed-by: Konstantin Shcheglov <[email protected]>
> Commit-Queue: Paul Berry <[email protected]>

[email protected],[email protected],[email protected],[email protected],[email protected]

Change-Id: I6b37f1143183e889a5b52cb8b0a5427991b306c0
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/34280
Reviewed-by: Paul Berry <[email protected]>
Commit-Queue: Paul Berry <[email protected]>
whesse pushed a commit that referenced this issue Jan 17, 2018
See #31649 for more details about forwarding semi-stubs.

Change-Id: I2af7fb0c5de01d7732279a6ca8254985f396683a
Reviewed-on: https://dart-review.googlesource.com/35003
Reviewed-by: Konstantin Shcheglov <[email protected]>
Reviewed-by: Samir Jindel <[email protected]>
Commit-Queue: Paul Berry <[email protected]>
@kmillikin
Copy link

I agree that we'd like to clean up all the forwarding stubs. Ideally, the analyzer would never see them at all.

I don't think it's really connected to the Dart 2 stable release.

@kmillikin kmillikin removed this from the Dart2Stable milestone May 24, 2018
@kmillikin kmillikin added legacy-area-front-end Legacy: Use area-dart-model instead. front-end-kernel and removed legacy-area-front-end Legacy: Use area-dart-model instead. area-kernel labels Sep 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants