[PR #1384] Implement power assertions #1059

Open
opened 2025-12-30 01:28:33 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/apple/pkl/pull/1384
Author: @bioball
Created: 12/23/2025
Status: 🔄 Open

Base: mainHead: power-asserts


📝 Commits (1)

  • 25cf821 Implement power assertions

📊 Changes

93 files changed (+1694 additions, -216 deletions)

View changed files

📝 pkl-cli/src/main/kotlin/org/pkl/cli/CliTestRunner.kt (+1 -0)
📝 pkl-cli/src/test/kotlin/org/pkl/cli/CliTestRunnerTest.kt (+35 -24)
📝 pkl-core/src/main/java/org/pkl/core/ast/ExpressionNode.java (+23 -2)
📝 pkl-core/src/main/java/org/pkl/core/ast/expression/binary/ComparatorNode.java (+3 -2)
📝 pkl-core/src/main/java/org/pkl/core/ast/expression/binary/GreaterThanNode.java (+9 -1)
📝 pkl-core/src/main/java/org/pkl/core/ast/expression/binary/LessThanNode.java (+9 -1)
📝 pkl-core/src/main/java/org/pkl/core/ast/expression/member/InvokeMethodVirtualNode.java (+9 -0)
📝 pkl-core/src/main/java/org/pkl/core/ast/frame/WriteFrameSlotNode.java (+6 -1)
📝 pkl-core/src/main/java/org/pkl/core/ast/internal/BlackholeNode.java (+6 -1)
📝 pkl-core/src/main/java/org/pkl/core/ast/internal/GetClassNode.java (+9 -1)
pkl-core/src/main/java/org/pkl/core/ast/internal/SyntheticNode.java (+29 -0)
📝 pkl-core/src/main/java/org/pkl/core/ast/lambda/ApplyVmFunction1Node.java (+5 -0)
📝 pkl-core/src/main/java/org/pkl/core/ast/type/TypeConstraintNode.java (+19 -3)
📝 pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java (+27 -11)
📝 pkl-core/src/main/java/org/pkl/core/ast/type/VmTypeMismatchException.java (+44 -24)
📝 pkl-core/src/main/java/org/pkl/core/repl/ReplServer.java (+2 -1)
pkl-core/src/main/java/org/pkl/core/runtime/PklTags.java (+27 -0)
pkl-core/src/main/java/org/pkl/core/runtime/PowerAssertions.java (+493 -0)
📝 pkl-core/src/main/java/org/pkl/core/runtime/TestRunner.java (+26 -6)
📝 pkl-core/src/main/java/org/pkl/core/runtime/VmBugException.java (+9 -5)

...and 73 more files

📄 Description

This adds power assertions to Pkl!

This implements the SPICE described in https://github.com/apple/pkl-evolution/pull/29

This follows the power assertions style of reporting also found in
Groovy, Kotlin, and others.

  • Literal values are not emitted in the diagram
  • Stdlib constructors of literals like List(1, 2) are also considered
    literals

Power assertions are added to:

  • Failing type constraints
  • Failing test facts

Power assertions are implemented as a truffle instrument to observe execution.
When an assertion fails, the instrument is created and the assertion is run again to observe facts.
This incurs runtime overhead to collect facts, but has no impact on code in the non-error case.

Samples:

module test
  facts
    ✘ math
       myList.fold(0, (a, b) -> a + b) == 5 (/Users/danielchao/code/apple/pkl/.dan-scripts/test.pkl:6)
       |      |                        |
       |      6                        false
       List(1, 2, 3)

0.0% tests pass [1/1 failed], 0.0% asserts pass [1/1 failed]
–– Pkl Error ––
Type constraint `this == this.capitalize()` violated.
Value: "fooey"

    this == this.capitalize()
    |    |  |    |
    |    |  |    "Fooey"
    |    |  "fooey"
    |    false
    "fooey"

1 | typealias CapitalizedString = String(this == this.capitalize())
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^
at test#foo (/Users/danielchao/code/apple/pkl/.dan-scripts/test.pkl:1)

3 | foo: CapitalizedString = "fooey"
                             ^^^^^^^
at test#foo (/Users/danielchao/code/apple/pkl/.dan-scripts/test.pkl:3)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/apple/pkl/pull/1384 **Author:** [@bioball](https://github.com/bioball) **Created:** 12/23/2025 **Status:** 🔄 Open **Base:** `main` ← **Head:** `power-asserts` --- ### 📝 Commits (1) - [`25cf821`](https://github.com/apple/pkl/commit/25cf82151c2aba613744f74e1109562112d6c854) Implement power assertions ### 📊 Changes **93 files changed** (+1694 additions, -216 deletions) <details> <summary>View changed files</summary> 📝 `pkl-cli/src/main/kotlin/org/pkl/cli/CliTestRunner.kt` (+1 -0) 📝 `pkl-cli/src/test/kotlin/org/pkl/cli/CliTestRunnerTest.kt` (+35 -24) 📝 `pkl-core/src/main/java/org/pkl/core/ast/ExpressionNode.java` (+23 -2) 📝 `pkl-core/src/main/java/org/pkl/core/ast/expression/binary/ComparatorNode.java` (+3 -2) 📝 `pkl-core/src/main/java/org/pkl/core/ast/expression/binary/GreaterThanNode.java` (+9 -1) 📝 `pkl-core/src/main/java/org/pkl/core/ast/expression/binary/LessThanNode.java` (+9 -1) 📝 `pkl-core/src/main/java/org/pkl/core/ast/expression/member/InvokeMethodVirtualNode.java` (+9 -0) 📝 `pkl-core/src/main/java/org/pkl/core/ast/frame/WriteFrameSlotNode.java` (+6 -1) 📝 `pkl-core/src/main/java/org/pkl/core/ast/internal/BlackholeNode.java` (+6 -1) 📝 `pkl-core/src/main/java/org/pkl/core/ast/internal/GetClassNode.java` (+9 -1) ➕ `pkl-core/src/main/java/org/pkl/core/ast/internal/SyntheticNode.java` (+29 -0) 📝 `pkl-core/src/main/java/org/pkl/core/ast/lambda/ApplyVmFunction1Node.java` (+5 -0) 📝 `pkl-core/src/main/java/org/pkl/core/ast/type/TypeConstraintNode.java` (+19 -3) 📝 `pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java` (+27 -11) 📝 `pkl-core/src/main/java/org/pkl/core/ast/type/VmTypeMismatchException.java` (+44 -24) 📝 `pkl-core/src/main/java/org/pkl/core/repl/ReplServer.java` (+2 -1) ➕ `pkl-core/src/main/java/org/pkl/core/runtime/PklTags.java` (+27 -0) ➕ `pkl-core/src/main/java/org/pkl/core/runtime/PowerAssertions.java` (+493 -0) 📝 `pkl-core/src/main/java/org/pkl/core/runtime/TestRunner.java` (+26 -6) 📝 `pkl-core/src/main/java/org/pkl/core/runtime/VmBugException.java` (+9 -5) _...and 73 more files_ </details> ### 📄 Description This adds power assertions to Pkl! This implements the SPICE described in https://github.com/apple/pkl-evolution/pull/29 This follows the power assertions style of reporting also found in Groovy, Kotlin, and others. * Literal values are not emitted in the diagram * Stdlib constructors of literals like `List(1, 2)` are also considered literals Power assertions are added to: * Failing type constraints * Failing test facts Power assertions are implemented as a truffle instrument to observe execution. When an assertion fails, the instrument is created and the assertion is run again to observe facts. This incurs runtime overhead to collect facts, but has no impact on code in the non-error case. Samples: ``` module test facts ✘ math myList.fold(0, (a, b) -> a + b) == 5 (/Users/danielchao/code/apple/pkl/.dan-scripts/test.pkl:6) | | | | 6 false List(1, 2, 3) 0.0% tests pass [1/1 failed], 0.0% asserts pass [1/1 failed] ``` ``` –– Pkl Error –– Type constraint `this == this.capitalize()` violated. Value: "fooey" this == this.capitalize() | | | | | | | "Fooey" | | "fooey" | false "fooey" 1 | typealias CapitalizedString = String(this == this.capitalize()) ^^^^^^^^^^^^^^^^^^^^^^^^^ at test#foo (/Users/danielchao/code/apple/pkl/.dan-scripts/test.pkl:1) 3 | foo: CapitalizedString = "fooey" ^^^^^^^ at test#foo (/Users/danielchao/code/apple/pkl/.dan-scripts/test.pkl:3) ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-30 01:28:33 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#1059