-
Notifications
You must be signed in to change notification settings - Fork 35
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
"Majestic" PGF runtime #130
Comments
For the current status look at branch 'majestic':
https://github.com/GrammaticalFramework/gf-core/tree/majestic/src/runtime/c
The subfolder 'doc' contains documentation for the decisions that I made so
far. My ambition is that the doc folder would develop into a living book
documenting the internals. Hopefully, it will help new developers to jump
in later.
What works so far:
- the C runtime can read the abstract syntax of a .pgf and build an .ngf
file from it. The .ngf is the actual database. Some of the abstract syntax
functions in the API are implemented as well.
- the old Haskell runtime is gone, the folder runtime/haskell contains the
new Haskell binding. There are two top-level modules PGF and PGF2. PGF
tries to emulate the API of the old Haskell runtime, while PGF2 should be
compatible with the API of the C runtime. Everything that already works in
the C library has also a binding in the Haskell runtime. There is also a
testsuite that I use to test the Haskell binding together with the actual
runtime.
- most of the code in the Python binding is commented out. It compiles, but
the only thing that you can do there is to load a grammar. I only needed
that in order to test that it is possible to load the runtime dynamically.
- the code for the compiler comes from the branch 'c-runtime'. In that
branch the compiler runs on top of the C runtime instead of the Haskell
one. In the new branch the compiler doesn't compile yet since not
everything in the runtime is implemented yet. Part of the compiler must be
updated anyway, since if we want dynamically changing grammars, the grammar
building API would have to change anyway.
Current milestones:
- Finish the rest of the readonly API for the abstract syntax
- Add API that can add/remove abstract functions and categories
- Implement proper transactions
- Modify the compiler to make it possible to compile grammars with only
abstract syntax
- Modify the compiler to produce an extended version PMCFG which would not
blow up in size so easily
- Load the new PMCFG in the runtime
- Continue with the different API functions for the concrete syntax.
Perhaps linearization should be the first to start with.
If you want to join the effort then we should schedule a meeting and decide
how to proceed.
…On Mon, 9 Aug 2021 at 11:05, John J. Camilleri ***@***.***> wrote:
@krangelov <https://github.com/krangelov> has mentioned at the summer
school his ideas on completely reimagining the PGF format as a database.
@anka-213 <https://github.com/anka-213> has expressed his interest in
contributing, and I ***@***.*** <https://github.com/johnjcamilleri>)
also think I could be of use here. I'm creating this issue to be the home
of that discussion.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#130>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEYFSZHT3E245XBNRLP5A2TT36K4HANCNFSM5BZSYMKQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email>
.
|
Wow, this seems a lot more advanced than you let on! I will take some time to better understand how it works. |
Hi @krangelov, pretty cool work! I remember hearing something about using SQLite for this work, which would give you transactions for free and also a platform-independent format (I'm assuming it would take the role of the .ngf files). Have you decided against it? I'm just curious and would love to contribute (I don't think I can, but I'll follow the discussion and if it turns out I can I'll say something!) |
I tried using SQLite but it quickly becomes very cumbersome to work in this
way. It means that every time when I must follow a pointer from one
structure to another, I must open/close a cursor and do a few more
function calls until I get what I want. In addition everything must be
serialized/deserialized to a platform independent format.
I am not planning to use it anymore, but here is an interesting spin off
project from the experiment:
https://github.com/krangelov/daison
It is a NoSQL database where you can use list comprehensions instead of
SQL. Hopefully, something similar will be available for storing auxiliary
information in grammars.
…On Tue, 10 Aug 2021 at 13:23, bc² ***@***.***> wrote:
Hi @krangelov <https://github.com/krangelov>, pretty cool work! I
remember hearing something about using SQLite for this work, which would
give you transactions for free and also a platform-independent format (I'm
assuming it would take the role of the .ngf files). Have you decided
against it? I'm just curious and would love to contribute (I don't think I
can, but I'll follow the discussion and if it turns out I can I'll say
something!)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#130 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEYFSZHVMCVEN7KNYJIHQRDT4ED2JANCNFSM5BZSYMKQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email>
.
|
Yes, it looks majestic to me, and the documents read well! Although the details about memory addresses are tricky.
I agree that linearization would be the first thing to make available, so that we can see if this is all we need of a linearization format in a large-scale setting.
Aarne
…________________________________
From: John J. Camilleri ***@***.***>
Sent: Tuesday, August 10, 2021 12:10:35 PM
To: GrammaticalFramework/gf-core
Cc: Subscribed
Subject: Re: [GrammaticalFramework/gf-core] Next-generation PGF (#130)
Wow, this seems a lot more advanced than you let on! I will take some time to better understand how it works.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub<#130 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAWBQXNCW6VC573ASGXGO53T4D3JVANCNFSM5BZSYMKQ>.
|
@krangelov I see, thanks for the explanation! and daison looks interesting indeed! |
I figure the best way I can start contributing to this effort is to be your first user! Which probably means I will have lots of annoying setup questions. To start with, I tried to build the runtime using the instructions from the old C runtime, which failed. I set up a CI workflow here which documents what I tried and also contains the current error I get. I'm happy to contribute to other kinds of documentation (as library docs and how-to guides) as I learn more. Going forward, we should add whatever testsuite you have (mentioned earlier) to this workflow. |
To be explicit, I am trying:
and getting:
What am I doing wrong? |
I added expr.cxx to the repo, so it should compile now.
To run the testsuite, you should run:
cabal test
in runtime/haskell.
…On Thu, 12 Aug 2021 at 13:07, John J. Camilleri ***@***.***> wrote:
To be explicit, I am trying:
autoreconf -i
./configure
make
and getting:
make[1]: Entering directory '/home/runner/work/gf-core/gf-core/src/runtime/c'
CXX pgf/db.lo
CXX pgf/text.lo
CXX pgf/pgf.lo
CXX pgf/reader.lo
make[1]: *** No rule to make target 'pgf/expr.cxx', needed by 'pgf/expr.lo'. Stop.
make[1]: Leaving directory '/home/runner/work/gf-core/gf-core/src/runtime/c'
What am I doing wrong?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#130 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEYFSZGP7DCQCBVLQJY4LGLT4OTQ5ANCNFSM5BZSYMKQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email>
.
|
Thanks Krasimir, the CI workflow now builds everything and runs the tests successfully. |
As far as I can see, nothing is commented out in I added a simple test to load the import pgf
import sys
sys.stdout.write("loading...")
sys.stdout.flush();
gr = pgf.readPGF("../haskell/tests/basic.pgf")
sys.stdout.write("\n") but I get a segmentation fault. The CI output is here, and I get the same locally. |
Actually commented out means that it is disabled with:
#if 0
#endif
You can see that on line 42. Comments in C/C++ are not recursive and are
not as nice as in Haskell.
Otherwise the Python binding used to work until I broke it while developing
the Haskell binding. You can find the comment:
/*TO BE FIXED*/
on line 3516.
I am working on the coming Python course now, but I hope to return to the
runtime soon.
…On Tue, 24 Aug 2021 at 09:14, John J. Camilleri ***@***.***> wrote:
most of the code in the Python binding is commented out. It compiles, but
the only thing that you can do there is to load a grammar. I only needed
that in order to test that it is possible to load the runtime dynamically.
As far as I can see, nothing is commented out in
src/runtime/python/pypgf.c?
I added a simple test
<https://github.com/GrammaticalFramework/gf-core/blob/majestic/src/runtime/python/test.py>
to load the basic.pgf file from Python:
import pgfimport sys
sys.stdout.write("loading...")sys.stdout.flush();gr = pgf.readPGF("../haskell/tests/basic.pgf")sys.stdout.write("\n")
but I get a segmentation fault. The CI output is here
<https://github.com/GrammaticalFramework/gf-core/runs/3408397541?check_suite_focus=true>,
and I get the same locally.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#130 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEYFSZFRZ2FZ54U4FWVSWDDT6NBDXANCNFSM5BZSYMKQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email>
.
|
Ah, thanks for the clarification! |
Hi Krasimir, |
I would appreciate it if you could start updating the Python bindings.
Before that give me about a week to finish and push some local changes that
I have. After that we could have a chat about what needs to be done.
…On Thu, 26 Aug 2021 at 08:58, John J. Camilleri ***@***.***> wrote:
Hi Krasimir,
I'm not experienced in C++, but I think this work is so important to the
future of GF that it is worth me taking time to learn C++ itself as well as
the internal details of how this new runtime works. I might be slow
initially, but perhaps you can think of some simpler tasks to give me now,
to help me get up to speed?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#130 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEYFSZHWW5IJZ3DTV3NWYEDT6XQYTANCNFSM5BZSYMKQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email>
.
|
The Python binding works again. I also reached the milestone where all
essential functions for the abstract syntax work.
There are a lot of low hanging fruits in the Python binding. These
functions should be easy to add:
pgf_readNGF -- analogous to readNGF in the Haskell runtime, it
can be built by modifying pgf_readPGF
pgf_bootNGF -- analogous to bootNGF in the Haskell runtime, it
can be built by modifying pgf_readPGF
These are also easy to restore from the old code:
PGF_getAbstractName
PGF_getCategories
PGF_getFunctions
PGF_functionsByCat
The next bigger chunk is:
PGF_functionType -- get the type of a function
PGF_getStartCat -- get the type for the start category
Expr_repr -- to show an expression as a string
pgf_readExpr -- read an expression from a string
Type_repr -- to show a type as a string
pgf_readType -- read an expression from a string
The last six functions require that the marshalling of abstract expressions
and types is implemented for Python as well. I started writing the
documentation about how this works.
…On Thu, 26 Aug 2021 at 11:47, Krasimir Angelov ***@***.***> wrote:
I would appreciate it if you could start updating the Python bindings.
Before that give me about a week to finish and push some local changes that
I have. After that we could have a chat about what needs to be done.
On Thu, 26 Aug 2021 at 08:58, John J. Camilleri ***@***.***>
wrote:
> Hi Krasimir,
> I'm not experienced in C++, but I think this work is so important to the
> future of GF that it is worth me taking time to learn C++ itself as well as
> the internal details of how this new runtime works. I might be slow
> initially, but perhaps you can think of some simpler tasks to give me now,
> to help me get up to speed?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#130 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AEYFSZHWW5IJZ3DTV3NWYEDT6XQYTANCNFSM5BZSYMKQ>
> .
> Triage notifications on the go with GitHub Mobile for iOS
> <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
> or Android
> <https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email>
> .
>
|
Great, I will start working on getting these implemented. |
Checklist for Python bindings: Reading from file
Restore from old code
Require marshalling of abstract expressions
|
So I have managed to implement the simpler functions for getting categories/functions by restoring old code, but one thing I can't figure out is how the error handing is supposed to work. Namely, the For now the old error-handling code is commented out like so: static PyObject*
PGF_getCategories(PGFObject *self, void *closure)
{
PyObject* categories = PyList_New(0);
if (categories == NULL)
return NULL;
// GuPool* tmp_pool = gu_local_pool();
//
// Create an exception frame that catches all errors.
// GuExn* err = gu_new_exn(tmp_pool);
PyPGFClosure clo = { { pgf_collect_cats }, self, categories };
pgf_iter_categories(self->pgf, &clo.fn);
// if (!gu_ok(err)) {
// Py_DECREF(categories);
// gu_pool_free(tmp_pool);
// return NULL;
// }
//
// gu_pool_free(tmp_pool);
return categories;
} Any pointers here? |
pgf_iter_categories & pgf_iter_functions doesn't really generate any
errors. That is why the parameter has disappeared. Other functions that may
fail now take PgfExn as a parameter. See pgf_read_pgf for example.
…On Mon, 30 Aug 2021 at 23:29, John J. Camilleri ***@***.***> wrote:
So I have managed to implement the simpler functions for getting
categories/functions by restoring old code, but one thing I can't figure
out is how the error handing is supposed to work. Namely, the GuExn* err
parameter seems to have disappeared from functions such as
pgf_iter_categories.
For now the old error-handling code is commented out like so:
static PyObject*PGF_getCategories(PGFObject *self, void *closure)
{
PyObject* categories = PyList_New(0);
if (categories == NULL)
return NULL;
// GuPool* tmp_pool = gu_local_pool();
//
// Create an exception frame that catches all errors.
// GuExn* err = gu_new_exn(tmp_pool);
PyPGFClosure clo = { { pgf_collect_cats }, self, categories };
pgf_iter_categories(self->pgf, &clo.fn);
// if (!gu_ok(err)) {
// Py_DECREF(categories);
// gu_pool_free(tmp_pool);
// return NULL;
// }
//
// gu_pool_free(tmp_pool);
return categories;
}
Any pointers here?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#130 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEYFSZEZRYLD6LWDGRLBGXLT7PZ5JANCNFSM5BZSYMKQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Ok, what about the cases below? It seems possible that static void
pgf_collect_funs(PgfItor* fn, PgfText* key, void* value)
{
PgfText* name = key;
PyPGFClosure* clo = (PyPGFClosure*) fn;
PyObject* py_name = NULL;
py_name = PyString_FromString(name->text);
if (py_name == NULL) {
// gu_raise(err, PgfExn);
goto end;
}
if (PyList_Append((PyObject*) clo->collection, py_name) != 0) {
// gu_raise(err, PgfExn);
goto end;
}
end:
Py_XDECREF(py_name);
} |
These error should be handled. When the Python API reports an error it also
raises a Python exception. We just have to detect that and stop the
iteration. I changed the iterator API to receive PgfExn like in the old
runtime. I also updated the Python code to compile but I didn't fix the
error handling. You just have to set
err.type = PGF_EXN_OTHER_ERROR;
when a problem on the Python side is encountered. This will stop the
iterator. At the end you should also release the reference to the partly
constructed list.
Another issue is that you should not use PyString_FromString anymore. This
function expects that the input string is null terminated, while the new
API allows input strings that contain the zero character \0. Instead you
can use:
PyString_FromStringAndSize(name->text, name->size);
This would be also more efficient since Python would not need to compute
the length itself.
…On Tue, 31 Aug 2021 at 08:33, John J. Camilleri ***@***.***> wrote:
Ok, what about the cases below? It seems possible that PyString_FromString
and PyList_Append can fail. Do you think it's safe to ignore those too?
static voidpgf_collect_funs(PgfItor* fn, PgfText* key, void* value)
{
PgfText* name = key;
PyPGFClosure* clo = (PyPGFClosure*) fn;
PyObject* py_name = NULL;
py_name = PyString_FromString(name->text);
if (py_name == NULL) {
// gu_raise(err, PgfExn);
goto end;
}
if (PyList_Append((PyObject*) clo->collection, py_name) != 0) {
// gu_raise(err, PgfExn);
goto end;
}
end:
Py_XDECREF(py_name);
}
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#130 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEYFSZATOLJXOLBBBW44QC3T7RZT3ANCNFSM5BZSYMKQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Thanks Krasimir. On the subject of strings, does this look right to you?: static PyObject*
PGF_functionsByCat(PGFObject* self, PyObject *args)
{
const char* c;
if (!PyArg_ParseTuple(args, "s", &c))
return NULL;
const size_t s = strlen(c);
PgfText* catname = (PgfText*) alloca(sizeof(PgfText)+s);
strcpy(catname->text, c);
catname->size = s;
... I need to read the parameter from |
I changed functionsByCat to use s# instead. In this way you get both the
string and its length. This will work even if the function is called with a
string containing the zero character.
Also instead of strcpy I used:
memcpy(catname->text, s, size+1);
Python always adds one zero character at the end and I copy that one as
well. The idea is that although PgfText may contain strings containing
'\0', most of the time that character is not used. If I append it at the
end of the string then when I debug the runtime through gdb it correctly
shows me the string as long as it doesn't contain '\0'.
Best Regards,
Krasimir
…On Tue, 31 Aug 2021 at 10:21, John J. Camilleri ***@***.***> wrote:
Thanks Krasimir. On the subject of strings, does this look right to you?:
static PyObject*PGF_functionsByCat(PGFObject* self, PyObject *args)
{
const char* c;
if (!PyArg_ParseTuple(args, "s", &c))
return NULL;
const size_t s = strlen(c);
PgfText* catname = (PgfText*) alloca(sizeof(PgfText)+s);
strcpy(catname->text, c);
catname->size = s;
...
I need to read the parameter from args into a PgfText (previously PgfCId).
But PyArg_ParseTuple wants to put it into a char*, so I have to do this
allocation + copy. I'm guessing strlen also works on null-terminated
strings, but maybe here this is the correct solution since the string in
the arguments not coming from the runtime?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#130 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEYFSZHJOLXCC6AZDHZX7CTT7SGH7ANCNFSM5BZSYMKQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
I've starting working on the marshalling in the Python bindings (see 3ecb937). I think it's starting to make sense, but I'd like to run a few things by you.
|
- What should TypeObject contain (see expr.h)? Currently I have just a
PgfText* in there for the type, but it needs more structure for the
hypotheses etc. But am I correct in that we do *not* need a PgfType* in
there anymore?
In TypeObject, I would put something like:
typedef struct {
PyObject_HEAD
PyList* hypos;
PyString *cat;
PyList* exprs;
} TypeObject;
In this way all fields use native Python types. The list hypos should
contain tuples with binding type, variable and the type of the variable.
The list exprs should contain objects of type ExprObject.
- Next, when building a type object to return in the unmarshaller (see
dtyp in marshaller.c), I am allocating a TypeObject and then returning
it by casting it to a PgfType. Is that right?
Yes. That is right
- Then, when using something which is created by the unmarshaller (see
pgf_readType in pypgf.c), I just cast it back to a TypeObject* again.
I think this aligns with what you wrote in the documentation, but would
appreciate if you you confirm this.
Exactly!
|
Understood! |
In the process I've come across another portability problem, namely the initialisation of flexible array members, which is apparently a GCC extension:
References:
This seems to be used in two places, for the definitions of
|
Another issue related to the use of unsigned ints and uint32_t PgfExprParser::getc()
{
uint32_t ch = pgf_utf8_decode((const uint8_t **) &pos);
if (pos - ((const char*) &inp->text) > inp->size) {
ch = EOF;
}
return ch;
}
|
Also:
Removing it from |
I've pushed my current changes (WIP) to the branch |
On Tue, 12 Oct 2021 at 14:59, John J. Camilleri ***@***.***> wrote:
In the process I've come across another portability problem, namely the
initialisation of flexible array members, which is apparently a GCC
extension:
pgf/pgf.cxx:34:34: error: initialization of flexible array member is not allowed
PgfText master = {size: 6, text: {'m','a','s','t','e','r',0}};
It is a pity that it doesn't work with CLang but you found a good
workaround.
|
I refactored the code to avoid using EOF. Using it was a bad idea anyway.
…On Tue, 12 Oct 2021 at 15:23, John J. Camilleri ***@***.***> wrote:
Another issue related to the use of unsigned ints and EOF:
uint32_t PgfExprParser::getc()
{
uint32_t ch = pgf_utf8_decode((const uint8_t **) &pos);
if (pos - ((const char*) &inp->text) > inp->size) {
ch = EOF;
}
return ch;
}
pgf/expr.cxx:368:7: error: case value evaluates to -1, which cannot be narrowed to type 'uint32_t' (aka 'unsigned int') [-Wc++11-narrowing]
case EOF:
^
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#130 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEYFSZETNPYFMJXDIXKGPNLUGQZGJANCNFSM5BZSYMKQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
librt is needed ipc.cxx but that module is not used yet. That is why
removing it worked. It will have to be reconsidered later.
…On Tue, 12 Oct 2021 at 15:26, John J. Camilleri ***@***.***> wrote:
Also:
ld: library not found for -lrt
Removing it from libpgf_la_LIBADD in Makefile.am seems to allow
everything to compile.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#130 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEYFSZFOINJEGBP2IPXFSOLUGQZPFANCNFSM5BZSYMKQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
I also fixed the issue with the wildcard.
…On Tue, 12 Oct 2021 at 18:50, Krasimir Angelov ***@***.***> wrote:
librt is needed ipc.cxx but that module is not used yet. That is why
removing it worked. It will have to be reconsidered later.
On Tue, 12 Oct 2021 at 15:26, John J. Camilleri ***@***.***>
wrote:
> Also:
>
> ld: library not found for -lrt
>
> Removing it from libpgf_la_LIBADD in Makefile.am seems to allow
> everything to compile.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#130 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AEYFSZFOINJEGBP2IPXFSOLUGQZPFANCNFSM5BZSYMKQ>
> .
> Triage notifications on the go with GitHub Mobile for iOS
> <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
> or Android
> <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
>
>
|
From what I understand, whatever is provided by |
Well, compiling now works on macOS (yay!), but |
I compiled and run a minimal example. Putting all details here for reference. Code #include "pgf/pgf.h"
int main () {
PgfRevision rev;
PgfExn err;
PgfDB *obj = pgf_read_pgf("/Users/john/repositories/GF/gf-core-majestic/src/runtime/haskell/tests/basic.pgf", &rev, &err);
} Command clang -lpgf -L/usr/local/lib main.c
lldb -o run ./a.out Output
Backtrace
Since this doesn't happen in Linux (inside Docker), I first suspected that the culprit is this workaround for #ifndef MREMAP_MAYMOVE
if (munmap(ms, old_size) == -1)
throw pgf_systemerror(errno);
malloc_state* new_ms =
(malloc_state*) mmap(0, new_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
#else
malloc_state* new_ms =
(malloc_state*) mremap(ms, old_size, new_size, MREMAP_MAYMOVE);
#endif However I a set breakpoint there which did not get triggered, so that can't be the problem? 69 if (db != NULL)
70 delete db; |
Slightly more investigation reveals that the read itself isn't working. If I comment out that destructor code, |
Also, loading from NGF with |
I suspect the failure is in the mmap call in the constructor PgfDB::PgfDB:
int mflags = (fd < 0) ? (MAP_PRIVATE | MAP_ANONYMOUS) : MAP_SHARED;
ms = (malloc_state*)
mmap(NULL, file_size, PROT_READ | PROT_WRITE, mflags, fd, 0);
Can you verify that?
When pgf_read_pgf is used it calls the constructor with NULL for the file
name. This one the other hand tells it to create an anonymous memory mapped
file. Maybe anonymous files work differently on Mac.
…On Wed, 13 Oct 2021 at 15:03, John J. Camilleri ***@***.***> wrote:
Also, loading from NGF with pgf_read_ngf seems to work perfectly well.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#130 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEYFSZGHPW7GMBWQNFZU5RTUGV7QLANCNFSM5BZSYMKQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
This page:
https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/mmap.2.html
says that on Mac MAP_ANON should be used. On Linux MAP_ANON is deprecated
but is otherwise a synonym to MAP_ANONYMOUS.
…On Wed, 13 Oct 2021 at 17:10, Krasimir Angelov ***@***.***> wrote:
I suspect the failure is in the mmap call in the constructor PgfDB::PgfDB:
int mflags = (fd < 0) ? (MAP_PRIVATE | MAP_ANONYMOUS) : MAP_SHARED;
ms = (malloc_state*)
mmap(NULL, file_size, PROT_READ | PROT_WRITE, mflags, fd, 0);
Can you verify that?
When pgf_read_pgf is used it calls the constructor with NULL for the file
name. This one the other hand tells it to create an anonymous memory mapped
file. Maybe anonymous files work differently on Mac.
On Wed, 13 Oct 2021 at 15:03, John J. Camilleri ***@***.***>
wrote:
> Also, loading from NGF with pgf_read_ngf seems to work perfectly well.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#130 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AEYFSZGHPW7GMBWQNFZU5RTUGV7QLANCNFSM5BZSYMKQ>
> .
> Triage notifications on the go with GitHub Mobile for iOS
> <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
> or Android
> <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
>
>
|
I've stepped through in the debugger but I cannot see anything going wrong with the call to
I couldn't find the documentation online, so here's a gist of it: man mmap It seems to be this call in
I know that |
To have access to the symbol information in the debugger, try this:
- open Makefile (not Makefile.am) and find this line:
CXXFLAGS = -g -O2
- replace it:
CXXFLAGS = -g3 -O0
- recompile everything by doing this:
make clean
make
- now start the debugger again.
Do you know if there is any way to get a virtual Mac on Ubuntu? I can
emulate Windows by using Wine but I don't know about Mac.
Best Regards,
Krasimir
…On Thu, 14 Oct 2021 at 09:00, John J. Camilleri ***@***.***> wrote:
I've stepped through in the debugger but I cannot see anything going wrong
with the call to mmap. The check with MAP_FAILED immediately afterwards
is false.
That page you linked is outdated, plus seems to be for iOS not macOS. When
I run man mmap on my system it says:
MAP_ANONYMOUS Synonym for MAP_ANON.
I couldn't find the documentation online, so here's a gist of it: man mmap
<https://gist.github.com/johnjcamilleri/1cdc73d25420302035fb40df1aac2d75#file-mmap>
It seems to be this call in PgfReader::read_pgf which is causing the
crash:
read_abstract(ref<PgfAbstr>::from_ptr(&pgf->abstract));
I know that read_absract is never reached. When I try to print
pgf->abstract in the debugger I get the message "Couldn't lookup symbols"
(maybe I need to recompile the runtime with/out some flags).
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#130 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEYFSZFZYZB75PTXT3HPD53UGZ5YVANCNFSM5BZSYMKQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Thanks! Either I was doing something wrong before, or turning off optimisation has changed things a little, such that now it seems that the call to abstract->funs = read_namespace<PgfAbsFun>(&PgfReader::read_absfun); in
No, I know nothing about emulating macOS in Ubuntu. A quick search seems to indicate that it's actively discouraged by Apple. You could test things in a GitHub Actions workflow (which I will set up for macOS anyway) although testing by pushing & waiting is hardly optimal either. Perhaps we should schedule a meeting and debug together. |
Do you have time tomorrow for a meeting? I am available between 13:00-14:00
and 15:00-16:00.
…On Thu, 14 Oct 2021 at 10:59, John J. Camilleri ***@***.***> wrote:
Thanks! Either I was doing something before, or turning off optimisation
has changed things a little, such that now it seems the call to
abstract->funs = read_namespace<PgfAbsFun>(&PgfReader::read_absfun);
in PgfReader::read_abstract is the source. At some point it seems to
"crash" and then the destructor of PgfDB suddenly gets called:
Process 99205 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x0000000100140a1c libpgf.0.dylib`PgfReader::read_absfun(this=0x00007ffeefbff888) at reader.cxx:382:9
379 ref<PgfAbsFun> PgfReader::read_absfun()
380 {
381 ref<PgfAbsFun> absfun =
-> 382 read_name<PgfAbsFun>(&PgfAbsFun::name);
383 absfun->ref_count = 1;
384 ref<PgfExprFun> efun =
385 ref<PgfExprFun>::from_ptr((PgfExprFun*) &absfun->name);
Target 0: (a.out) stopped.
(lldb) n
Process 99205 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x100189058)
frame #0: 0x000000010012a7f7 libpgf.0.dylib`PgfDB::~PgfDB(this=0x00000001003044d0) at db.cxx:369:17
366 PgfDB::~PgfDB() {
367 if (ms != NULL) {
368 size_t size =
-> 369 ms->top + chunksize(ptr(ms,ms->top)) + sizeof(size_t);
370
371 munmap(ms,size);
372 }
Target 0: (a.out) stopped.
No, I know nothing about emulating macOS in Ubuntu. A quick search seems
to indicate that it's actively discouraged by Apple. You could test things
in a GitHub Actions workflow (which I will set up for macOS anyway)
although testing by pushing & waiting is hardly optimal either. Perhaps we
should schedule a meeting and debug together.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#130 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEYFSZBM32EN4JGHVDVBBXLUG2LVHANCNFSM5BZSYMKQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
I understand what you're suggesting and tried to make the changes in the
More generally, what is the reason that this needs to be different for macOS? |
In db.cxx when you say malloc the compiler tries to call PgfDB::malloc
instead of the standard malloc. Try using "::malloc". You may also have to
add #include <stdlib.h>.
…On Fri, 15 Oct 2021 at 15:28, John J. Camilleri ***@***.***> wrote:
I realized what is probably happening if indeed you actually go to the
munmap/mmap part of the code.
When we have a file (i.e. fd > 0), then munmap/mmap works since the data
is stored in the file. On the other hand when you have fid < 0 then munmap
is just a more efficient version of free, and mmap becomes equivalent to
malloc. In that case, of course, after free+malloc we will lose all the
data.
On Mac the case when fd < 0 should be treated differently. In PgfDB::PgfDB
the initial block should be allocated with malloc. In
PgfDB::malloc_internal, instead of munmap+mmap we should use realloc().
I understand what you're suggesting and tried to make the changes in the
majestic-macos branch
<majestic...majestic-macos>,
however there's a compilation error I can't understand:
pgf/db.cxx:331:28: error: no matching function for call to 'malloc'
ms = (malloc_state*) malloc(file_size); // doesn't compile
^~~~~~
More generally, what is the reason that this needs to be different for
macOS?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#130 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEYFSZEIQNHY42LK5D6BIBLUHAT7BANCNFSM5BZSYMKQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Right, thanks! This seems to have worked. I'm now getting a lot further and pass all the Haskell "basic" tests. Now I'm getting a new error:
but I will need to debug this further. Could it be related to the call to |
ipc.cxx is not used yet. The problem should be something else.
…On Fri, Oct 15, 2021, 17:48 John J. Camilleri ***@***.***> wrote:
Right, thanks! This seems to have worked. I'm now getting a lot further
and pass all the Haskell "basic" tests. Now I'm getting a new error:
transactions: branchPGF: invalid argument (Invalid argument)
but I will need to debug this further. Could it be related to the call to
mmap in ipc.cxx?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#130 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEYFSZFISFCGEAKISGCXZY3UHBELRANCNFSM5BZSYMKQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
If I want to use the runtime from C, surely I don't need to implement my own un/marshaller? I see there are implementations of all the marshalling functions in |
The cause behind the 'Invalid argument' error mentioned above seems to be this line in int res = msync((void *) ms, size, MS_SYNC | MS_INVALIDATE); Which returns |
For reference, macOS man page for |
I tested not calling |
If fd < 0 then skipping msync is safe on all platforms. On Linux it will
just do nothing in that case.
…On Mon, Oct 18, 2021, 13:59 John J. Camilleri ***@***.***> wrote:
Any idea how this should be changed for macOS (when ms is malloc'ed)?
I tested not calling mysnc at all in this case, and seems to work on all
platforms (see CI here
<https://github.com/GrammaticalFramework/gf-core/actions/runs/1354485057>).
But I'm not sure if it's the right solution.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#130 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEYFSZFGG6PZTPAAFQM3CADUHQD2VANCNFSM5BZSYMKQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
The (un)marshaller in expr.cxx only works with the internal database
representations of the expressions. If someone wants to use the library
from C then he/she should define own data structures and marshallers. It is
also possible to define marshallers who start from an application specific
data structure and then do NLG without explicitly generating the abstract
syntax tree.
I haven't anyone yet who would like to use the runtime from C :-)
…On Mon, Oct 18, 2021, 13:11 John J. Camilleri ***@***.***> wrote:
If I want to use the runtime from C, surely I don't need to implement my
own un/marshaller? I see there are implementations of all the marshalling
functions in expr.cxx, but these are not exposed in any way.
Maybe if one passes NULL when an unmarshaller is needed, it can/should
use these internal implementations?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#130 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEYFSZG2G2RGREGZY4M3VNDUHP6GDANCNFSM5BZSYMKQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Ok, thanks for the clarifications!
Haha fair enough. I did this myself for testing purposes, in order to exclude the bindings themselves as a source of problems, but actually I managed to avoid using any functions that required un/marshalling. |
@krangelov has mentioned at the summer school his ideas on completely reimagining the PGF format as a database. @anka-213 has expressed his interest in contributing, and I (@johnjcamilleri) also think I could be of use here. I'm creating this issue to be the home of that discussion.
The text was updated successfully, but these errors were encountered: