Skip to content

VM: Implement support for constants being evaluated by front end #36220

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
1 of 3 tasks
a-siva opened this issue Mar 14, 2019 · 13 comments
Closed
1 of 3 tasks

VM: Implement support for constants being evaluated by front end #36220

a-siva opened this issue Mar 14, 2019 · 13 comments
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P2 A bug or feature request we're likely to work on

Comments

@a-siva
Copy link
Contributor

a-siva commented Mar 14, 2019

This is the tracker issue for implementing support in the VM for constants being evaluated by the front end

  • Implement support in JIT mode
  • The bytecode compiler currently implements constant expression evaluation, with CFE doing it that becomes redundant
  • The AOT pipeline implements constant expression evaluation as a kernel to kernel transformation, with CFE doing it that becomes redundant

Language tracking issue: dart-lang/language#60
Frontend implementation tracking issue: #35079

@a-siva a-siva added the area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. label Mar 14, 2019
@a-siva a-siva added this to the Dart2.3 milestone Mar 14, 2019
@a-siva
Copy link
Contributor Author

a-siva commented Mar 14, 2019

/cc @aartbik @alexmarkov who should own this issue?

@aartbik
Copy link
Contributor

aartbik commented Mar 14, 2019

I marked us both as owner for now. Alex probably wants to do the bytecode side. I can help with the other stuff after consulting with Alex.

dart-bot pushed a commit that referenced this issue Mar 20, 2019
Rationale:
The constant evaluator deals with two sorts of
offsets, the true offset into the kernel data,
and the offset of a constant relative to the
start of the constant table (compensated for a
variable-size int prefix at the true base).
The DAG test was comparing the latter against
the former (which was always true, since the
true offsets are much larger). This fixes
this omission.

#36220

Change-Id: I71f37bfb2bd3432e52d5086e89a62115f0cacacd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/97421
Commit-Queue: Aart Bik <[email protected]>
Reviewed-by: Alexander Markov <[email protected]>
@a-siva a-siva added the P1 A high priority bug; for example, a single project is unusable or has many test failures label Mar 28, 2019
@dgrove
Copy link
Contributor

dgrove commented Apr 3, 2019

Any updates on this issue?

@aartbik
Copy link
Contributor

aartbik commented Apr 3, 2019

I am not aware of blocking VM work. For JIT, we could lazily instead of eagerly evaluate the constants in the constant table (which becomes larger) to reduce compile-time, and I have a prototype CL for that. For AOT, I don't think anything is not working, and removing code would be just a cleanup. I let Alex comment on bytecode status.

@a-siva
Copy link
Contributor Author

a-siva commented Apr 3, 2019

I think this issue can be taken off from the 2.3 milestone list, it is more for clean up work to remove the redundant constant expressions evaluation code from the AOT and bytecode paths once CFE has solid support for constant expressions evaluation.

@dgrove dgrove removed this from the Dart2.3 milestone Apr 3, 2019
@a-siva a-siva added P2 A bug or feature request we're likely to work on and removed P1 A high priority bug; for example, a single project is unusable or has many test failures labels May 24, 2019
dart-bot pushed a commit that referenced this issue Jun 21, 2019
Rationale:
Previously all constants were read from the constants table,
whether they were needed (at that point or at all) or not. This
CL replaces that eager reading with a lazy reading that makes
the raw bytes of the constants table available through
KernelProgramInfo and attaches a hashmap to KernelProgramInfo,
which maps offsets into the constant table to evaluated constants.
The maps starts empty and on a miss, the constant is evaluated,
but no sooner than when it it needed.

#36220

Change-Id: Ief4df3d70c950c4beb61d896632ce06cfd12d525
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/99088
Commit-Queue: Aart Bik <[email protected]>
Reviewed-by: Alexander Markov <[email protected]>
@aartbik
Copy link
Contributor

aartbik commented Jun 21, 2019

Lazy constant reading has been submitted. Items and ideas to follow up on:

(1) by setting the raw-bytes array and hash map from the start, we may be able to completely avoid the "pending" and "delayed" data structures; we should be evaluate every constant when needed first
(2) by peeking into pragma's we may avoid the cyclic detector altogether
(3) removed unused code and data structures when this stabilizes

@aartbik
Copy link
Contributor

aartbik commented Jun 21, 2019

Approved fails to follow-up on:

|vm-kernel-precomp-bare-linux-release-x64 |language_2/const_inference_test |RuntimeError
|vm-kernel-precomp-linux-product-x64      |language_2/const_inference_test |RuntimeError
|vm-kernel-precomp-linux-release-simarm64 |language_2/const_inference_test |RuntimeError
|vm-kernel-precomp-linux-release-x64      |language_2/const_inference_test |RuntimeError
|vm-kernel-precomp-mac-release-simarm64   |language_2/const_inference_test |RuntimeError
|vm-kernel-precomp-win-release-simarm64   |language_2/const_inference_test |RuntimeError
|vm-kernel-precomp-win-release-x64        |language_2/const_inference_test |RuntimeError
|vm-kernel-precomp-linux-debug-x64 |language_2/const_inference_test    |RuntimeError
|vm-kernel-precomp-bare-linux-release-simarm   |language_2/const_inference_test | RuntimeError
|vm-kernel-precomp-bare-linux-release-simarm64 |language_2/const_inference_test | RuntimeError
|vm-kernel-precomp-linux-release-simarm        |language_2/const_inference_test | RuntimeError
|vm-kernel-precomp-android-release-arm |language_2/const_inference_test |RuntimeError
|vm-kernel-precomp-linux-debug-x64 | language_2/cyclic_metadata_test/02 |Crash

@aartbik
Copy link
Contributor

aartbik commented Jun 21, 2019

A fix for the cyclic test crash is pending (see https://dart-review.googlesource.com/c/sdk/+/107000). As for the constant inference, the difference is right after canonicalize:

v16 <- Constant(#Closure: (Null) => Null from Function 'constFunction': static.) T{_Closure}
vs.
v16 <- Constant(#Closure: (dynamic) => dynamic from Function 'constFunction': static.) T{_Closure}

dart-bot pushed a commit that referenced this issue Jun 21, 2019
Rationale:
Due to the cycle breaking reading of VM annotations,
we should be prepared to see a class loaded inside
class loading wrap-up.

#36220

Change-Id: I46665989e489ada8ed2414a57a789b9c2d9c9f7a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107000
Reviewed-by: Alexander Markov <[email protected]>
Commit-Queue: Aart Bik <[email protected]>
@aartbik
Copy link
Contributor

aartbik commented Jun 21, 2019

The canonicalize difference happens in LoadFieldInstr::Canonicalize() with the following code

   if (Evaluate(instance()->BoundConstant(), &result)) {
      if (result.IsSmi() || result.IsOld()) {
          return flow_graph->GetConstant(result);
      }
  }

with Evaluate() returning the different values

v15 <- Constant(#Instance of 'C<Null>') T{C}
Instance of 'C<Null>'
Closure: (Null) => Null from Function 'constFunction': static.

v15 <- Constant(#Instance of 'C<Null>') T{C}
Instance of 'C<Null>'
Closure: (dynamic) => dynamic from Function 'constFunction': static.

Indeed, this is a difference already at constant evaluation level:

C2 Closure: (Null) => Null from Function 'constFunction': static
C2 Closure: (dynamic) => dynamic from Function 'constFunction': static. 

@aartbik
Copy link
Contributor

aartbik commented Jun 22, 2019

Fix for crash confirmed:

The following tests are now succeeding:

BOT/CONFIG TEST
vm-kernel-precomp-linux-debug-x64 language_2/cyclic_metadata_test/02

Fix for the failure is pending at https://dart-review.googlesource.com/c/sdk/+/107064

dart-bot pushed a commit that referenced this issue Jun 22, 2019
Rationale:
As shown in the comment, I was already not sure about
what argument to use. Clearly one of the two type
arguments is not needed. This fixes the
language_2/const_inference_test failure that
was temporarily approved.

#36220

Change-Id: I3dd8ddf0e3cf0e992164c005b08ffd59306041f7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107064
Reviewed-by: Aart Bik <[email protected]>
Commit-Queue: Aart Bik <[email protected]>
Auto-Submit: Aart Bik <[email protected]>
@aartbik
Copy link
Contributor

aartbik commented Jun 22, 2019

Confirmed fixes for all vm bots. Sample. below.

The following tests are now succeeding:

BOT/CONFIG TEST
vm-kernel-precomp-linux-product-x64 language_2/const_inference_test

dart-bot pushed a commit that referenced this issue Jul 18, 2019
Rationale:
Only look for "external" and "pragma" to avoid
cyclic or unloaded class evaluation

#37533
#36220


Change-Id: I78ef5dcd2c7e7dee0d196394320e994f8aa8a695
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/109300
Commit-Queue: Aart Bik <[email protected]>
Reviewed-by: Alexander Markov <[email protected]>
@aartbik
Copy link
Contributor

aartbik commented Jul 22, 2019

@a-siva any actionable items left for this?

@a-siva
Copy link
Contributor Author

a-siva commented Jul 23, 2019

I think there are no more known items, let me close it. If we find bugs we can open new issues for the failures.

@a-siva a-siva closed this as completed Jul 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P2 A bug or feature request we're likely to work on
Projects
None yet
Development

No branches or pull requests

4 participants