IntersectMBO / plutus

The Plutus language implementation and tools
Apache License 2.0
1.57k stars 479 forks source link

Build failure with text-2.1.2 #6703

Closed neilmayhew closed 14 hours ago

neilmayhew commented 22 hours ago

Summary

When built with text-2.1.2 (uploaded 2024-10-26T13:22:01Z) in the package set, the following errors occur:

src/PlutusLedgerApi/Common/Eval.hs:117:34: error: [GHC-87543]
    Ambiguous occurrence ‘show’.
    It could refer to
       either ‘PlutusCore.show’,
              imported from ‘PlutusCore’ at src/PlutusLedgerApi/Common/Eval.hs:23:1-17
              (and originally defined in ‘GHC.Show’),
           or ‘Text.show’,
              imported from ‘Data.Text’ at src/PlutusLedgerApi/Common/Eval.hs:45:1-24.
    |
117 |             ["Internal error: ", show ll, " does not support protocol version ", show pv]
    |                                  ^^^^

src/PlutusLedgerApi/Common/Eval.hs:117:82: error: [GHC-87543]
    Ambiguous occurrence ‘show’.
    It could refer to
       either ‘PlutusCore.show’,
              imported from ‘PlutusCore’ at src/PlutusLedgerApi/Common/Eval.hs:23:1-17
              (and originally defined in ‘GHC.Show’),
           or ‘Text.show’,
              imported from ‘Data.Text’ at src/PlutusLedgerApi/Common/Eval.hs:45:1-24.
    |
117 |             ["Internal error: ", show ll, " does not support protocol version ", show pv]
    |                                                                                  ^^^^

It seems that Data.Text added a show function in 2.1.2 and PlutusLedgerApi.Common.Eval has

import Data.Text as Text

A similar problem occurs in AnyProgram.Run.

Steps to reproduce the behavior

diff --git a/cabal.project b/cabal.project
index 22be30739..a388d351e 100644
--- a/cabal.project
+++ b/cabal.project
@@ -14,7 +14,7 @@ repository cardano-haskell-packages
 -- update either of these.
 index-state:
   -- Bump both the following dates if you need newer packages from Hackage
-  , hackage.haskell.org 2024-10-16T00:00:00Z
+  , hackage.haskell.org 2024-11-20T00:00:00Z
   -- Bump this if you need newer packages from CHaP
   , cardano-haskell-packages 2024-10-16T00:00:00Z

@@ -99,3 +99,4 @@ constraints:
   -- The API has changed for version 2.2, ledger depends on the old version and ledger will not
   -- be updated until after the Conway release.
   , cardano-crypto-class ^>= 2.1
+  , any.text source
diff --git a/flake.lock b/flake.lock
index 2b0526946..5c3df2eaa 100644
--- a/flake.lock
+++ b/flake.lock
@@ -279,11 +279,11 @@
     "hackage": {
       "flake": false,
       "locked": {
-        "lastModified": 1729124899,
-        "narHash": "sha256-cmb4iMcgk5+jUGMiZGNMzPCAnG17Kz9J6WIitYM17Fc=",
+        "lastModified": 1732148935,
+        "narHash": "sha256-zRj4ndWzyY9JFG3c8SCIxlFHefgS0YEazpq580gE3dk=",
         "owner": "input-output-hk",
         "repo": "hackage.nix",
-        "rev": "138edf81c8bcc4209e9706966f7feece70c37a96",
+        "rev": "834ac92115c32dabf23abd6b61f925e4d6edc9db",
         "type": "github"
       },
       "original": {

The any.text source constraint is copied from cardano-api where I first noticed the problem during release integration.

Actual Result

See the error message in the description.

Expected Result

Build succeeds.

Describe the approach you would take to fix this

Using import Data.Text as Text hiding (show) isn't ideal because it prevents building with an older version of text. Ideally, Data.Text would be imported qualified, but I assume the team prefers it done unqualified. So the remaining option is to qualify the use of show as PlutusCore.show.

This problem doesn't need to be solved right away, because we can work around it in cardano-api with an additional constraint, text <2.1.2. However, it would be better in the long term if this was fixed, since having to add a constraint in a different project to make this one build isn't ideal.

System info

OS: NixOS Version: unstable Plutus: 1.33.1.0-159-gefaadc5ce

neilmayhew commented 21 hours ago

I see there are only of a few places where Data.Text is an open, unqualified import:

plutus-core/executables/plutus/AnyProgram/Compile.hs:import Data.Text
plutus-core/executables/plutus/AnyProgram/Run.hs:import Data.Text as Text
plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Evaluation/Machine/SteppableCek/DebugDriver.hs:import Data.Text
plutus-ledger-api/src/PlutusLedgerApi/Common/Eval.hs:import Data.Text as Text
plutus-metatheory/src/Untyped.hs:import Data.Text as T hiding (map)

I wonder if it would be good to change these to closed or qualified imports.