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

Interesting pattern match failure #1

Open
mikesol opened this issue Jun 30, 2020 · 6 comments
Open

Interesting pattern match failure #1

mikesol opened this issue Jun 30, 2020 · 6 comments
Assignees

Comments

@mikesol
Copy link
Collaborator

mikesol commented Jun 30, 2020

Using the ffi index at https://github.com/mikesol/purescript-python-ffi-index, I was able to provoke a pattern match failure running Main.purs in this repo. Below is a stack trace. I'm not exactly sure what provokes this, but as the error comes up deep in the Haskell compiler, I thought it'd be interesting to report it here.

Traceback (most recent call last):
  File "/home/meeshkan-abel/mike/paff/.venv/bin/pspy", line 8, in <module>
    sys.exit(cmd_pspy())
  File "/home/meeshkan-abel/mike/paff/.venv/lib/python3.7/site-packages/purescripto/pspy.py", line 20, in cmd_pspy
    wisepy2.wise(pspy)()
  File "/home/meeshkan-abel/mike/paff/.venv/lib/python3.7/site-packages/wisepy2.py", line 117, in parse_arg
    return fn(*args, **kwargs)
  File "/home/meeshkan-abel/mike/paff/.venv/lib/python3.7/site-packages/purescripto/configure.py", line 205, in pspy
    mod = import_module("{}.{}.pure".format(conf.PyPack, conf.EntryModule))
  File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/meeshkan-abel/mike/pjx/pjx/Main/pure.py", line 3, in <module>
    __ps__ = LoadPureScript(__file__, __name__)
  File "/home/meeshkan-abel/mike/paff/.venv/lib/python3.7/site-packages/purescripto/purescript_loader.py", line 45, in LoadPureScript
    exec(code, man_made_globals)
  File "src/Main.purs", line 1, in pjx.Main.pure$
    module Main where
  File "src/Main.purs", line 19, in None
    result <- AX.request r
  File ".spago/affjax/v10.1.0/src/Affjax.purs", line 1, in None
    module Affjax
  File ".spago/affjax/v10.1.0/src/Affjax.purs", line 243, in None
    ResponseFormat.Ignore coe -> const $ coe (pure unit)
Exception: Failed pattern match at pjx.Affjax.pure (line 237, column 18 - line 243, column 57): ps_Json
@mikesol
Copy link
Collaborator Author

mikesol commented Jun 30, 2020

@Hong-Xiang @thautwarm I've pinged you in case you have time to check it out. It could be that there's an error somewhere in the python code, but that winds up getting obfuscated by the error emitted from the Haskell code.

@thautwarm
Copy link
Member

I've found that in https://github.com/purescript-contrib/purescript-affjax/blob/master/src/Affjax.purs#L241 ,

both ResponseFormat.Json and req.responseFormat are all a Python dictionary whose field ".t" is <function ps_Json at ??>, however their addresses are different.

I use pdb to find what's wrong with it, this seems quite strange:

(Pdb) p (ps_req["responseFormat"][".t"], ps_Affjax_ResponseFormat["Json"])
True
(Pdb) p (ps_req["responseFormat"][".t"], ps_Affjax_ResponseFormat["Json"])
(<function ps_Json at 0x000001A503103CA8>, <function ps_Json at 0x000001A502CAF4C8>)

Is there any copy in our codebase invoked on functions? @Hong-Xiang @mikesol

@thautwarm
Copy link
Member

@mikesol Besides, about how to use pdb to debug:

  1. Change following line

    "data-format": "Compressed",

    to "data-format" : "Pretty",

  2. run spago build, and when you want to debug the module Affjax,
    delete

    • ./purescript-affjax/purescript_affjax/Affjax/pure.zip.py.
    • ./purescript-affjax/purescript_affjax/Affjax/__pycache__/.
  3. open ./purescript-affjax/purescript_affjax/Affjax/pure.raw.py, search Exception: Failed pattern match at pjx.Affjax.pure (line 237, column 18 - line 243, column 57), you'll find where it is.

  4. if you want to use PDB exactly before evaluating some expression EXP, replace it with

     block(
        call(var("breakpoint")),
        EXP
      )
  5. pspy --run

@thautwarm
Copy link
Member

I found the generated code for Affjax.ResponseFormat is executed twice.

thautwarm added a commit to purescript-python/purescripto that referenced this issue Jun 30, 2020
@thautwarm
Copy link
Member

thautwarm commented Jun 30, 2020

@mikesol Please try installing purescripto 0.8.9 from source, which seems to solve this issue.

@thautwarm
Copy link
Member

The new traceback:

called ajax
STARTING
Exception in thread Thread-5:
Traceback (most recent call last):
  File "C:\Users\twshere\Softwares\lib\threading.py", line 926, in _bootstrap_inner
    self.run()
  File "C:\Users\twshere\Softwares\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\twshere\Desktop\FS\dev\github\pspy-test\purescript-affjax\purescript_affjax\ffi\Affjax.py", line 67, in _toThreading
    if options.username and options.password:
AttributeError: 'dict' object has no attribute 'username'

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

No branches or pull requests

3 participants