Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mpickering/fcad625093c51e122f18defdb947bd57 to your computer and use it in GitHub Desktop.
Save mpickering/fcad625093c51e122f18defdb947bd57 to your computer and use it in GitHub Desktop.
commit fd9986790de790e3bec7e5a7ac19fc6b2541b199
Author: Krzysztof Gogolewski <[email protected]>
Date: Mon Jun 9 12:44:07 2025 +0200
Fix EPT enforcement when mixing unboxed tuples and non-tuples
The code was assuming that an alternative cannot be returning a normal
datacon and an unboxed tuple at the same time. However, as seen in #26107,
this can happen when using a GADT to refine the representation type.
The solution is just to conservatively return TagDunno.
diff --git a/compiler/GHC/Stg/EnforceEpt/Types.hs b/compiler/GHC/Stg/EnforceEpt/Types.hs
index dc022ecd48d..318e7f984c2 100644
--- a/compiler/GHC/Stg/EnforceEpt/Types.hs
+++ b/compiler/GHC/Stg/EnforceEpt/Types.hs
@@ -39,8 +39,8 @@ type InferStgAlt = GenStgAlt 'InferTaggedBinders
combineAltInfo :: TagInfo -> TagInfo -> TagInfo
combineAltInfo TagDunno _ = TagDunno
combineAltInfo _ TagDunno = TagDunno
-combineAltInfo (TagTuple {}) TagProper = panic "Combining unboxed tuple with non-tuple result"
-combineAltInfo TagProper (TagTuple {}) = panic "Combining unboxed tuple with non-tuple result"
+combineAltInfo (TagTuple {}) TagProper = TagDunno -- This can happen with rep-polymorphic result, see #26107
+combineAltInfo TagProper (TagTuple {}) = TagDunno -- This can happen with rep-polymorphic result, see #26107
combineAltInfo TagProper TagProper = TagProper
combineAltInfo (TagTuple is1) (TagTuple is2) = TagTuple (zipWithEqual combineAltInfo is1 is2)
combineAltInfo (TagTagged) ti = ti
diff --git a/testsuite/tests/rep-poly/T26107.hs b/testsuite/tests/rep-poly/T26107.hs
new file mode 100644
index 00000000000..b045f3a6f0c
--- /dev/null
+++ b/testsuite/tests/rep-poly/T26107.hs
@@ -0,0 +1,14 @@
+{-# LANGUAGE GADTs, UnboxedTuples #-}
+module T26107 where
+
+import Data.Kind
+import GHC.Exts
+
+type T :: TYPE rep -> Type
+data T a where
+ A :: T Bool
+ B :: T (# #)
+
+f :: forall rep (a :: TYPE rep). T a -> a
+f A = True
+f B = (# #)
diff --git a/testsuite/tests/rep-poly/all.T b/testsuite/tests/rep-poly/all.T
index c80111962a5..fcedb6d666f 100644
--- a/testsuite/tests/rep-poly/all.T
+++ b/testsuite/tests/rep-poly/all.T
@@ -41,6 +41,7 @@ test('T23883a', normal, compile_fail, [''])
test('T23883b', normal, compile_fail, [''])
test('T23883c', normal, compile_fail, [''])
test('T23903', normal, compile_fail, [''])
+test('T26107', js_broken(22364), compile, ['-O'])
test('EtaExpandDataCon', normal, compile, ['-O'])
test('EtaExpandStupid1', normal, compile, ['-Wno-deprecated-flags'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment