Skip to content

Conversation

Unisay
Copy link
Contributor

@Unisay Unisay commented Jun 19, 2025

@Unisay Unisay requested a review from SeungheonOh June 19, 2025 14:02
@Unisay Unisay self-assigned this Jun 19, 2025
Copy link
Contributor

github-actions bot commented Jun 19, 2025

PR Preview Action v1.6.2

🚀 View preview at
https://IntersectMBO.github.io/plutus/pr-preview/pr-7162/

Built to branch gh-pages at 2025-07-25 16:13 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@Unisay Unisay force-pushed the yura/Cannot-construct-a-value-of-type branch from 97d926e to 07b20e0 Compare June 19, 2025 14:25
@Unisay Unisay force-pushed the yura/Cannot-construct-a-value-of-type branch from 07b20e0 to da0e24d Compare July 10, 2025 13:52
@Unisay Unisay force-pushed the yura/Cannot-construct-a-value-of-type branch from da0e24d to 9e42a6c Compare July 25, 2025 11:50
Unisay added 2 commits July 25, 2025 18:09
…iltin types

Add intelligent detection of stage violations when using PlutusTx builtin types.

The previous error message "Cannot construct a value of type: BuiltinUnit" was
cryptic and unhelpful for users encountering stage violations. This change
introduces:

- Template Haskell-based detection of builtin types from PlutusTx.Builtins.Internal
- Module-aware type checking to avoid false positives
- Comprehensive error messages explaining stage violations and how to fix them
- Clear guidance on moving functions to top-level scope

The improved error message explains the root cause (stage violation), provides
actionable solutions (move to top-level, check variable scope), and maintains
the original technical context for advanced debugging.

This addresses the confusing error reported in plutus-private#1626 while
maintaining full compatibility with existing functionality.
Document investigation into disabling mkSimplPass for better error messages.

This investigation explored whether removing the GHC simplifier pass could
improve error messages for stage violations. While disabling the pass does
provide clearer errors, it breaks legitimate plugin functionality that depends
on pre-inlining.

The investigation concludes that targeted error message improvements (like the
stage violation detection) are more practical than removing core functionality.
These notes preserve the analysis for future reference and provide context for
the chosen approach.
@Unisay Unisay requested a review from zliu41 July 25, 2025 16:11
Copy link
Collaborator

@SeungheonOh SeungheonOh left a comment

Choose a reason for hiding this comment

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

I prefer adding special handling for providing better error message instead of disabling simplpass entirely. It seems writing a new simplifier(or rather, unfolder) would require some changes to GHC itself which would be undesirable.

- **Solutions**:
- Move functions to top-level
- Generate minimal unfoldings during desugaring (GHC enhancement needed)
- Create lightweight unfolding pass (lighter than full simplifier)
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this possible without making changes to GHC itself? From what I can see(which can be very wrong), we can only really change the plugin pass and the plugin pass doesn't have access to other stages of compilation.

This would be very easy if we have whole compilation pipeline under control.

OtherCon []
```
- **Root cause**: GHC #16615 - local bindings lack unfoldings without simplifier
- **Pattern**: Functions marked `{-# INLINEABLE #-}` but defined after their use site
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's probably also the case for function marked inlineable but defined on the other module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants