typelead / eta-hackage

A set of patches to make Hackage compatible with the Eta language.
64 stars 31 forks source link

failure on Text.Regex.mkRegex #141

Closed joshsh closed 5 years ago

joshsh commented 5 years ago

From Gitter:

Joshua Shinavier @joshsh 15:06 can someone shed some light on the following stack trace:

 Exception in thread "main" eta.runtime.exception.EtaException: Prelude.undefined
        at base.ghc.TopHandler.runMainIO2(TopHandler.hs)
        at base.ghc.TopHandler$runMainIO2.apply1V(TopHandler.hs)
        at eta.runtime.exception.Exception.catch_(Exception.java:169)
        at main.Main.main3(Main.hs)
[...]
Caused by: eta.runtime.exception.EtaException: Prelude.undefined
        at base.ghc.Err.errorWithoutStackTrace(Err.hs:39)
        at base.ghc.Err$undefined.thunkEnter(Err.hs:39)
        at eta.runtime.thunk.CAF.evaluate(CAF.java:30)
[...]

the program in question runs normally when executed with stack exec, but throws this error when executed via gradle-eta

Joshua Shinavier @joshsh 15:49 it appears at the point in the program when file output occurs. File input succeeds. FWIW, an earlier version of this program (including the file output) ran via gradle-eta without problems.

Joshua Shinavier @joshsh 16:28 probably related to regex matching as opposed the file I/O itself. Here is more of the stack trace:

 Caused by: eta.runtime.exception.EtaException: Prelude.undefined
        at base.ghc.Err.errorWithoutStackTrace(Err.hs:39)
        at base.ghc.Err$undefined.thunkEnter(Err.hs:39)
        at eta.runtime.thunk.CAF.evaluate(CAF.java:30)
        at eta.runtime.stg.Closure.evaluateTail(Closure.java:33)
        at regex_compat.text.Regex$mkRegex1.thunkEnter(Regex.hs:43)
        at eta.runtime.thunk.CAF.evaluate(CAF.java:30)
        at regex_posix.text.regex.posix.String.$fRegexMaker_Regex_CompOption_ExecOption_ZMZN_$cmakeRegexOpts(String.hs:72)
        at main.data.schemas.Schema$$Llvl40$1.thunkEnter(Schema.hs)
        at eta.runtime.thunk.CAF.evaluate(CAF.java:30)
        at regex_posix.text.regex.posix.Wrap.wrapMatch1(Wrap.hs:588)
        at regex_posix.text.regex.posix.String.$fRegexContext_Regex_ZMZN_ZMZN4(String.hs:107)
        at regex_posix.text.regex.posix.String.$fRegexContext_Regex_ZMZN_ZMZN_$cmatchOnce(String.hs:80)
        at regex_posix.text.regex.posix.String.$fRegexContext_Regex_ZMZN_ZMZN_$cmatchOnceText(String.hs:76)
        at main.data.schemas.Schema.$LcheckName$1(Schema.hs:619)
line 619 is this:
     nameRegex = TR.mkRegex "^[A-Za-z][A-Za-z0-9]*$"

Rahul Muttineni @rahulmutt 22:40 @joshsh It could be referring to a unimplemented function in regex-posix - I just checked the patch and observed that there are some undefined’s sprinkled throughout so they need to be implemented. If possible, can you make a minimal example that causes this problem? I can go ahead and implement those. Do file an issue with the minimal example so that I can close it to let you know it’s been fixed.

Joshua Shinavier @joshsh 23:14 @rahulmutt, the following example reproduces the issue:

 import qualified Text.Regex as TR
import qualified Data.Maybe as Y

main = do
  let name = "foo"
  putStrLn $ show name ++ " is a legal name: " ++ (show $ minimalEtaFailureExample name)

minimalEtaFailureExample s = Y.isJust $ TR.matchRegex nameRegex s
  where
    nameRegex = TR.mkRegex "^[A-Za-z][A-Za-z0-9]*$"

this is via gradle-eta with:

 eta {
    version = '0.8.6b3'
    etlasVersion = '1.5.0.0' 
}
joshsh commented 5 years ago

Any insight into this issue?

rahulmutt commented 5 years ago

I've replaced the undefined's with proper implementations and you test case appears to work and give the same result across GHC and Eta. Feel free to file new issues if you encounter any more issues with the regex-posix patch.

You can update etlas via ./gradlew updateEtlas and do a clean build with gradle.

joshsh commented 5 years ago

Thank you; this works.