Skip to content
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

reproduction: Use of fromString @BuiltinByteStringHex with inscrutable content #6963

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Unisay
Copy link
Contributor

@Unisay Unisay commented Mar 20, 2025

@Unisay Unisay self-assigned this Mar 20, 2025
@Unisay Unisay added Do not merge No Changelog Required Add this to skip the Changelog Check labels Mar 20, 2025
@@ -0,0 +1,11 @@
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -fplugin PlutusTx.Plugin #-}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Peculiar fact: with this compiler option the error is:

    GHC Core to PLC plugin: Error: 
    Unexpected error during compilation, please report this to the Plutus team:
    Use of fromString @PlutusTx.Builtins.HasOpaque.BuiltinByteStringHex with inscrutable content: 
    GHC.Types.: @GHC.Types.Char 
      (GHC.Types.C# 'f'#) 
      (GHC.Base.build @GHC.Types.Char (\ (@b) -> GHC.CString.unpackFoldrCString# @b "0"#))

but without it the error is different (even more confusing):

GHC Core to PLC plugin: Error: Unsupported feature: 
Literal string (maybe you need to use OverloadedStrings)
Context: Compiling expr: "f0"#
Context: Compiling expr: GHC.Base.build
                           @GHC.Types.Char
                           (\ (@b) -> GHC.CString.unpackFoldrCString# @b "f0"#)

Copy link
Member

Choose a reason for hiding this comment

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

There's no reason to put {-# OPTIONS_GHC -fplugin PlutusTx.Plugin #-} in this module.
@Unisay can you post the entire GHC core for this module?

Copy link
Contributor Author

@Unisay Unisay Mar 20, 2025

Choose a reason for hiding this comment

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

Without this pragma the GHC's recompilation avoidance mechanism would not recompile this module whenever something in the plugin changes; For this reason I always add it in tests.

However, my point was different: the presence/absense of this pragrma does change the compilation error, while my expectation was that it shouldn't make any difference.

can you post the entire GHC core for this module?

Sure.

==================== Tidy Core ====================
Result size of Tidy Core
  = {terms: 23, types: 8, coercions: 2, joins: 0/0}

-- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0}
ByteStringLiterals.Lib.$trModule4 :: ghc-prim:GHC.Prim.Addr#
[GblId,
 Unf=Unf{Src=<vanilla>, TopLvl=True,
         Value=True, ConLike=True, WorkFree=True, Expandable=True,
         Guidance=IF_ARGS [] 150 0}]
ByteStringLiterals.Lib.$trModule4
  = "plutus-tx-plugin-1.42.0.0-inplace-plutus-tx-plugin-tests"#

-- RHS size: {terms: 2, types: 0, coercions: 0, joins: 0/0}
ByteStringLiterals.Lib.$trModule3 :: ghc-prim:GHC.Types.TrName
[GblId,
 Unf=Unf{Src=<vanilla>, TopLvl=True,
         Value=True, ConLike=True, WorkFree=True, Expandable=True,
         Guidance=IF_ARGS [] 10 10}]
ByteStringLiterals.Lib.$trModule3
  = ghc-prim:GHC.Types.TrNameS ByteStringLiterals.Lib.$trModule4

-- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0}
ByteStringLiterals.Lib.$trModule2 :: ghc-prim:GHC.Prim.Addr#
[GblId,
 Unf=Unf{Src=<vanilla>, TopLvl=True,
         Value=True, ConLike=True, WorkFree=True, Expandable=True,
         Guidance=IF_ARGS [] 70 0}]
ByteStringLiterals.Lib.$trModule2 = "ByteStringLiterals.Lib"#

-- RHS size: {terms: 2, types: 0, coercions: 0, joins: 0/0}
ByteStringLiterals.Lib.$trModule1 :: ghc-prim:GHC.Types.TrName
[GblId,
 Unf=Unf{Src=<vanilla>, TopLvl=True,
         Value=True, ConLike=True, WorkFree=True, Expandable=True,
         Guidance=IF_ARGS [] 10 10}]
ByteStringLiterals.Lib.$trModule1
  = ghc-prim:GHC.Types.TrNameS ByteStringLiterals.Lib.$trModule2

-- RHS size: {terms: 3, types: 0, coercions: 0, joins: 0/0}
ByteStringLiterals.Lib.$trModule :: ghc-prim:GHC.Types.Module
[GblId,
 Unf=Unf{Src=<vanilla>, TopLvl=True,
         Value=True, ConLike=True, WorkFree=True, Expandable=True,
         Guidance=IF_ARGS [] 10 10}]
ByteStringLiterals.Lib.$trModule
  = ghc-prim:GHC.Types.Module
      ByteStringLiterals.Lib.$trModule3 ByteStringLiterals.Lib.$trModule1

-- RHS size: {terms: 6, types: 1, coercions: 0, joins: 0/0}
ByteStringLiterals.Lib.hex1 [InlPrag=INLINABLE]
  :: PlutusTx.Builtins.Internal.BuiltinByteString
[GblId,
 Unf=Unf{Src=StableUser, TopLvl=True,
         Value=False, ConLike=False, WorkFree=False, Expandable=False,
         Guidance=IF_ARGS [] 80 0
         Tmpl= src<test/ByteStringLiterals/Lib.hs:12:1-10>
               PlutusTx.Builtins.HasOpaque.stringToBuiltinByteStringHex
                 (ghc-prim:GHC.Types.:
                    @ghc-prim:GHC.Types.Char
                    (ghc-prim:GHC.Types.C# 'f'#)
                    (GHC.Base.build
                       @ghc-prim:GHC.Types.Char
                       (\ (@b_iafj) ->
                          ghc-prim:GHC.CString.unpackFoldrCString# @b_iafj "0"#)))}]
ByteStringLiterals.Lib.hex1
  = src<test/ByteStringLiterals/Lib.hs:12:1-10>
    PlutusTx.Builtins.HasOpaque.stringToBuiltinByteStringHex
      (ghc-prim:GHC.Types.:
         @ghc-prim:GHC.Types.Char
         (ghc-prim:GHC.Types.C# 'f'#)
         (ghc-prim:GHC.CString.unpackCString# "0"#))

-- RHS size: {terms: 1, types: 0, coercions: 2, joins: 0/0}
hex [InlPrag=INLINABLE] :: BuiltinByteStringHex
[GblId,
 Unf=Unf{Src=<vanilla>, TopLvl=True,
         Value=False, ConLike=False, WorkFree=True, Expandable=True,
         Guidance=ALWAYS_IF(arity=0,unsat_ok=True,boring_ok=True)}]
hex
  = ByteStringLiterals.Lib.hex1
    `cast` (Sym (PlutusTx.Builtins.HasOpaque.N:BuiltinByteStringHex[0])
            :: PlutusTx.Builtins.Internal.BuiltinByteString
               ~R# BuiltinByteStringHex)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Do not merge No Changelog Required Add this to skip the Changelog Check
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants