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

Optimize away EmptyDataDecls, unknown, and Ptr in the FFI #338

Open
bergmark opened this issue Oct 5, 2013 · 1 comment
Open

Optimize away EmptyDataDecls, unknown, and Ptr in the FFI #338

bergmark opened this issue Oct 5, 2013 · 1 comment

Comments

@bergmark
Copy link
Member

bergmark commented Oct 5, 2013

data Text
data JQuery

select :: Text -> Fay JQuery
select = ffi "$(%1)"

currently produces:

Test.select = function($p1){
  return new Fay$$$(function(){
    return new Fay$$Monad(Fay$$jsToFay(["user","JQuery",[]],$(Fay$$fayToJs(["user","Text",[]],$p1))));
  });
};

This is unnecessary, we know that an EmptyDataDecl won't result in any transcoding. This can be fixed manually by:

select :: Ptr Text -> Fay (Ptr JQuery)
select = ffi "$(%1)"
Test.select = function($p1){
  return new Fay$$$(function(){
    return new Fay$$Monad($($p1));
  });
};

The compiler can easily do this instead of the user, just keep track of all types that are EmptyDataDecls (Fay.Compiler.InitialPass) and turn the type into x or Ptr Foo while compiling FFI declarations (Fay.Compiler.FFI).

@bergmark
Copy link
Member Author

bergmark commented Oct 7, 2013

Also, all calls with the argument ["unknown"] and ["ptr"] can be dropped. This can be done in the FFI or in the optimizer.

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

No branches or pull requests

1 participant