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

[RFC] Toward Static Analysis #192

Open
faultyserver opened this issue May 20, 2018 · 0 comments
Open

[RFC] Toward Static Analysis #192

faultyserver opened this issue May 20, 2018 · 0 comments
Labels
rfc A request for comments from the community semantics Generic label for semantics issues. All semantics issues should have this tag.

Comments

@faultyserver
Copy link
Member

The primary goal of Myst is and always has been to support users as best as possible. For the most part, this has meant defining an expressive, globally-consistent syntax, and implementing powerful features like pattern matching.

But, if you ask anyone who uses a modern compiled or transpiled language what they think the most helpful feature of the language is, they'll likely tell you about the compiler catching errors before the code runs. Not just things like missing parentheses or mispelled keywords, but things like type checking, reachability, and more.

That kind of support is generally known as Static Analysis, and is something that modern dynamic languages have recently been growing into more and more. Some take the approach of creating a new "superset" language (e.g., TypeScript over JavaScript, Hack over PHP) while others like Python are adding Gradual Typing directly into the original language.

Now, I'd like to bring this into Myst directly. Similar to Python, I think the gradual typing approach is best, and being such a young language there's no concern for legacy compatibility, which makes this the simplest option as well.

That said, there are two changes that need to happen to enable static analysis in Myst:

  • Disallow dynamic type modification (e.g., opening a type within a method). Types can still be statically re-opened, and defining new "anonymous" types within a method could be allowed, but using defmodule or deftype to re-open an existing type from within a normal method would be explicitly disallowed.

  • Enforce that all necessary components of a program are loaded with static require expressions. In other words, require would almost always need to be given a string literal instead of a variable. It can still be allowed within methods, as require operates as a copy-paste.

I don't see these as being particularly restrictive. In fact, I would almost argue that these are desirable traits in the language to improve clarity and traceability in larger codebases.

Once those two changes are in place, we can start work on a proper semantic phase (a simple implementation already exists in /src/myst/semantic). I'm imagining a two-phase approach. First, Type Resolution to get the final state of all types defined in the program. Then, some implementation of Hindly-Milner type inference for type checking, along with method checking.

I'm not sure how strict things like type checking should be for Myst. I absolutely want to avoid any chance of the type system getting in the way of the user. Elixir seems like a solid reference point to use for strictness.

@faultyserver faultyserver added rfc A request for comments from the community semantics Generic label for semantics issues. All semantics issues should have this tag. labels May 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rfc A request for comments from the community semantics Generic label for semantics issues. All semantics issues should have this tag.
Projects
None yet
Development

No branches or pull requests

1 participant