Skip to content

Finish implementation of optional new and const #32553

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
peter-ahe-google opened this issue Mar 16, 2018 · 16 comments
Closed

Finish implementation of optional new and const #32553

peter-ahe-google opened this issue Mar 16, 2018 · 16 comments
Assignees
Labels
front-end-fasta legacy-area-front-end Legacy: Use area-dart-model instead. P1 A high priority bug; for example, a single project is unusable or has many test failures
Milestone

Comments

@peter-ahe-google
Copy link
Contributor

peter-ahe-google commented Mar 16, 2018

When I originally implemented support for optional new and const, I wasn't aware about a feature that we call "magic" const, also I wasn't aware that default values of named parameters aren't implicitly const (see #32430).

Magic const is described in implicit-creation.md.

Let's look at some examples, assume these definitions are given:

class A {
  const A();

  int get length => 0;
}
const dynamic a = const A();
const dynamic b = "";
class C {
  final x;
  const C(this.x);
}

Is this expression a compile time constant:

C(a)

According to the magic-const feature, it is. So this means that the compiler should treat this as:

const C(a)

Unfortunately, that's not what I implemented. Because there's no context that requires a const, I implemented treating it as:

new C(a)

Obviously, this is a bug, and we want to fix it immediately. However, we estimate that it will take some time, and when the fix lands, it will be a breaking change. Why? It has to do with canonicalization of compile-time constants. This is the simplest example I can think of: Object() == Object(). This should evaluate to true, but we're currently evaluating it to false.

To eliminate the risk of breaking users that start relying on optional new and const, we decided to implement a stop-gap measure and report an error when we can't correctly infer const.

In case you're wondering why fixing this will take some time, the reason is that we need to implement compile-time constant evaluation in the new front-end. Previously we hadn't implemented that because the backends took care of it themselves. But to correctly pick const or new, we now need to evaluate the (potentially) constant expressions. For example:

C(b.length) // Is a compile-time constant.
C(a.length) // Isn't a compile-time constant.
@peter-ahe-google
Copy link
Contributor Author

Unfortunately, I haven't gotten to this yet. Next week is vacation.

@peter-ahe-google
Copy link
Contributor Author

@stefantsov will take a look at this next week.

@chloestefantsova
Copy link
Contributor

The issue is being handled in CL 48481.

@chloestefantsova
Copy link
Contributor

Hmm... I'm blocked by a strange issue: when I try to create an instance of a Visitor subclass as a field in the BodyBuilder class or even as a local variable, the following test starts crashing:

python tools/test.py -m release -c dartk service/type_arguments_test

@chloestefantsova
Copy link
Contributor

I'm investigating. Will try to resolve the issue before the weekend.

@chloestefantsova
Copy link
Contributor

So, I've created a GitHub issue for the surprising behavior described above #32717. I also implemented a work-around. Working on fixing other minor issues.

@chloestefantsova
Copy link
Contributor

CL 48481 landed. With it all of the tests that were marked as CompileTimeError due to the "implementation limit" are now passing. In addition to that, some other tests started passing as well. There is still some work to be done to insert new and const in more places where it's possible. I think it's quite doable in a couple of days. After that we may close this issue.

@dgrove dgrove added the P1 A high priority bug; for example, a single project is unusable or has many test failures label Mar 30, 2018
@dgrove
Copy link
Contributor

dgrove commented Mar 30, 2018

Dropping to P1 now that CL 48481 has landed.

@JekCharlsonYu JekCharlsonYu removed the P0 A serious issue requiring immediate resolution label Mar 30, 2018
@tvolkert
Copy link
Contributor

tvolkert commented Apr 2, 2018

Linking to #32737 for archeology's sake

@DanTup
Copy link
Collaborator

DanTup commented Apr 3, 2018

Is this one a known/expected issue? Using flutter master (dated 30 hours ago):

compiler message: lib/stock_row.dart:40:29: Error: The keyword 'const' or 'new' is required here. Due to an implementation limit, the compiler isn't able to infer 'const' or 'new' here.
compiler message:                     bottom: BorderSide(color: Theme.of(context).dividerColor))),
compiler message:                             ^

@kmillikin
Copy link

@DanTup that's (probably) expected. We're still not done implementing this feature. As Dima said:

There is still some work to be done to insert new and const in more places where it's possible. I think it's quite doable in a couple of days. After that we may close this issue.

We had a few days off due to the Easter holidays, but we're back to working actively on this issue.

@DanTup
Copy link
Collaborator

DanTup commented Apr 3, 2018

I thought that might be the case, but since I had it on my screen I figured it was worth pasting in in case it'd been missed. Thanks!

@chloestefantsova
Copy link
Contributor

I'm actively working on the constness evaluator. CL 49122 and CL 49140 are going to fix some of the issues.

@JekCharlsonYu
Copy link
Contributor

closed as duplicate of #32737

@tvolkert
Copy link
Contributor

tvolkert commented Apr 3, 2018

Not yet closed?

@JekCharlsonYu
Copy link
Contributor

closed as duplicate of #32737 (one more time)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
front-end-fasta legacy-area-front-end Legacy: Use area-dart-model instead. P1 A high priority bug; for example, a single project is unusable or has many test failures
Projects
None yet
Development

No branches or pull requests

7 participants