-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FFI: disallow interface specification on locals (#886)
## Summary Change the language specification and implementation to disallow using the `.nodecl`, `.header`, `.importc`, `.importjs`, `.exportc`, `.extern`, and `.dynlib` pragmas on local 'var'/'let' definitions -- locals exist only inside routines and thus cannot be foreign. ## Details Except for parameters, which can be detected through the `skParam` kind, locals cannot be distinguished from globals through just the symbol kind. Therefore, they need to be detected through dedicated logic that inspects the full symbol. This check is implemented by the new `isLocal` procedure added to the `pragmas` module. The `sfGlobal` flag cannot be used for detecting globals at this point, as the flag is only included on the symbols for declarations outside of routines *after* pragma processing is finished. Instead, `isLocal` checks for whether the owner of the symbol is a module -- nonetheless testing for the `sfGlobal` flag ensures that declarations with `.global` can also use the FFI. During application of the FFI pragmas, it is now first checked whether the applied-to symbol is that of a local, and if it is, an error is returned. The error uses the new `adSemExternalLocalNotAllowed` diagnostic plus associated report. Finally, the documentation for the pragmas is updated. ### Code-generator cleanup - the name mangling in the C code generator is updated to not inspect the `extname` for parameters and locals -- the string is now always empty for those - testing for the `sfImportc` and `extNoDecl` flag for locals is removed from the JS code generator -- the flags are never present on the symbol now ### Other adjustments The only place in the compiler where using the FFI with locals was relied on is with the `asyncjs` module. There, `.importjs` is used for getting access to JavaScript's `undefined` value. However, using a local is not necessary for achieving this -- a `proc` using `.importjs` works as well.
- Loading branch information
Showing
9 changed files
with
64 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters