Do not activate power assertions when a single union member containing a type constraint fails#1462
Merged
HT154 merged 3 commits intoapple:mainfrom Mar 25, 2026
Merged
Conversation
6bfa733 to
48617a1
Compare
HT154
commented
Mar 5, 2026
holzensp
reviewed
Mar 10, 2026
Collaborator
holzensp
left a comment
There was a problem hiding this comment.
Not the prettiest, but I can't think of something prettier. No blockers.
Comment on lines
+1058
to
+1068
| localContext.setInTypeTest(wasInTypeTest); | ||
| if (VmContext.get(this).getPowerAssertionsEnabled() | ||
| && (!wasInTypeTest || localContext.hasActiveTracker())) { | ||
| for (var i = 0; i < elementTypeNodes.length; i++) { | ||
| try { | ||
| elementTypeNodes[i].executeEagerly(frame, value); | ||
| } catch (VmTypeMismatchException e) { | ||
| typeMismatches[i] = e; | ||
| } | ||
| } | ||
| } |
Collaborator
There was a problem hiding this comment.
My spidey senses tingle at the lack of DRYness. I don't want to insist on DRYness per se, but would like to ask the question out loud; worth a private static helper or similar.
Contributor
Author
There was a problem hiding this comment.
This is certainly possible, but I'm hesitant to do it without more context here, i.e. why does executeLazily use @ExplodeLoop but executeEagerly does not? Was this not already DRY'd up because of some optimization?
4604dc2 to
80f733a
Compare
stackoverflow
approved these changes
Mar 24, 2026
Contributor
stackoverflow
left a comment
There was a problem hiding this comment.
Looks good. Some nits.
dd1ed2d to
3cca13f
Compare
HT154
added a commit
that referenced
this pull request
Mar 25, 2026
…g a type constraint fails (#1462) Prior to this change, this code would activate powers assertions / instrumentation permanently: ```pkl foo: String(contains("a")) | String(contains("b")) = "boo" ``` This is because the `contains("a")` constraint would fail, triggering power assertions, but the subsequent check of the union's `contains("b")` branch would succeed. As observed in #1419, once instrumentation is enabled, all subsequent evaluation slows significantly. As with #1419, the fix here is to disable power assertions via `VmLocalContext` until we know that all union members failed type checking; then, each member is re-executed with power assertions allowed to provide the improved user-facing error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prior to this change, this code would activate powers assertions / instrumentation permanently:
This is because the
contains("a")constraint would fail, triggering power assertions, but the subsequent check of the union'scontains("b")branch would succeed.As observed in #1419, once instrumentation is enabled, all subsequent evaluation slows significantly.
As with #1419, the fix here is to disable power assertions via
VmLocalContextuntil we know that all union members failed type checking; then, each member is re-executed with power assertions allowed to provide the improved user-facing error.