-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
feat(compiler)!: foreign
module syntax
#1873
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks mostly good, I did have a few small questions though.
Great job on this 👏 , insane turn around time.
@@ -37,7 +37,8 @@ module Grain_parsing = struct end | |||
%token <string> PREFIX_150 | |||
%token <string> INFIX_ASSIGNMENT_10 | |||
|
|||
%token ENUM RECORD TYPE MODULE INCLUDE USE PROVIDE ABSTRACT FOREIGN WASM PRIMITIVE | |||
%token FOREIGN_VALUE FOREIGN_MODULE | |||
%token ENUM RECORD TYPE MODULE INCLUDE USE PROVIDE ABSTRACT FOREIGN PRIMITIVE BINDS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this pr get rid of the FOREIGN
token in the lever, so shouldn't we remove it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't read through the implementation yet, but at least what we discussed was keeping that token to help with error messages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't read through the implementation yet, but at least what we discussed was keeping that token to help with error messages.
well need to keep it in the lexar than as well right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ospencer How could we use it in error messages? Wouldn't that token need to show up in a parse rule?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. What we want to enable is a proper error message when someone writes, for example, foreign foo
. The compiler should tell you that after the foreign
keyword, there should be the keyword module
or value
.
foreign_binds: | ||
| lseparated_nonempty_list(eos, foreign_bind) eos? { $1 } | ||
|
||
foreign_module_stmt: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we change
FOREIGN_MODULE UIDENT BINDS str lbrace foreign_binds
to
foreign_module_header lbrace foreign_binds
so we ensure the pattern is the same for both?
If this makes sense we should probably do the same thing for normal modules in a separate pr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say that's reasonable. I'll also just go ahead and change normal modules in this PR since it's basically a one line change anyways
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, my thoughts are if we ever go back and change the syntax its now one change instead of two.
@@ -1,4 +1,6 @@ | |||
/* grainc-flags --compilation-mode=runtime */ | |||
module Debug | |||
|
|||
provide foreign wasm debug: a => Void from "console" | |||
provide foreign module Console binds "console" { | |||
foreign value debug binds "debug": a => Void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be allowing an a
type on foreigns?
I thought the only types we wanted to allow are WasmI32
, WasmI64
, WasmF32
, WasmF64
and Void
It looks like we did before with the old syntax but Im wondering if we should change that with the new syntax. I don't know where the best place to change that would be, maybe typed_well_formedness
, should enforce that you are only using the primitive unsafe types. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually not even sure why this file exists as it doesn't appear to be used anywhere; what you're suggesting sounds like an interesting idea, though I think this would require some nontrivial changes to the compiler to be able to recognize a function call to a foreign vs a normal function. What are your thoughts @ospencer @phated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old Grain js runner had a debug thing and this is how you'd use it. I don't remember if we merged that PR yet.
Should we be allowing an
a
type on foreigns?
No, and we discussed that (as a thing that we will do/warn against), but that work does not need to happen in this PR (and needs some more thought).
@@ -1,47 +1,36 @@ | |||
/* grainc-flags --no-gc */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need to have this set to --no-gc
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, but I figured I'd just keep this file (as well as the other wasi files) like this for now since it will have to be rectified with #1804 anyways
@@ -0,0 +1,36 @@ | |||
/* grainc-flags --no-gc */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this module just be marked as unsafe
, rather than --no-gc
@@ -0,0 +1,184 @@ | |||
/* grainc-flags --no-gc */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question as above.
Closes #1052 with modified syntax as discussed in Discord