Skip to content

Conversation

@bioball
Copy link
Member

@bioball bioball commented Dec 23, 2025

Reference implementation: apple/pkl#1384

@bioball bioball force-pushed the power-asserts branch 2 times, most recently from d9e8369 to 0a6bedf Compare December 25, 2025 05:35
----

Literal values include stdlib types like IntSeq, List, Map whose members are also literal.
Here, `List(1, 2, 3)` is excluded because it's considered a literal:
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this also work for Map()? What about Listing of literals?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, already mentioned Map on line 127.

Didn't include this for objects, because there's a lot of sugar that can happen with object literals. But, maybe we can support this for objects that have explicitly declared types, e.g. new Listing { 1; 2; 3 }.


[source,pkl]
----
assert(1 == 2)
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this a future direction, but would assert short circuit if it fails, like throw?
If so it has the same problem as throw, which is, it doesn't compose.
If we can solve this, we'd be able to replace throw as the way to show custom messages.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think this would be the replacement for throw, but, I'm also not sure if this should be short-circuiting or not.

bioball added a commit to apple/pkl that referenced this pull request Jan 21, 2026
This adds power assertions to Pkl!

This implements the SPICE described in
apple/pkl-evolution#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.

---------

Co-authored-by: Islon Scherer <[email protected]>
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.

2 participants