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

Tag AST nodes for pattern recognition #789

Open
sgtz opened this issue Sep 26, 2019 · 5 comments

Comments

@sgtz
Copy link

commented Sep 26, 2019

tag AST nodes for pattern recognition

Why

Code translates to an AST, before compiling down to ILASM. One way of putting code aside for special treatment is to place it in a quotation. Another technique is through tagging regular code in a more granular way, so that after scanning the resulting AST, you can opt to do something different.

Description

OCaml allows "tagging" of language constructs. Tagging doesn't do anything except help make more informed pattern recognition of the AST tree possible.

An existing way of approaching this problem in F# is to maybe have disguised identity functions ie. the name of the function could_be_a_special_tag. There may be places that syntactically this will not work though.

Often the .NET pattern is to tag classes and structure with attributes, but this approach is often too cumbersome if you seek to be more language-oriented.

Pros and Cons

The advantages of making this adjustment to F# are more flexible pre-compilation choices, for special cases.

It's a relatively low-risk suggestion. The tag itself doesn't have any extra functionality. It's just an identifier for custom Compiler Services.

The disadvantages of making this adjustment to F# are ...

The typical arguments about hurting language adoption through increasing the language surface area, I suppose. There's the can we trust people to use this feature responsively discussion, too.

Extra information

Estimated cost (XS, S, M, L, XL, XXL): S

Related suggestions:

Safe At Any Speed
Discriminate Unions As An API
fsharp/fslang-design#48
https://github.com/fsharp/fslang-design/blob/master/preview/FS-1003-nameof-operator.md#alternative-formalize-the-notion-of-a-named-entity
Rust Compiler Plugins

Affidavit (please submit!)

Please tick this by placing a cross in the box:

  • [ X ] This is not a question (e.g. like one you might ask on stackoverflow) and I have searched stackoverflow for discussions of this issue
  • [ X ] I have searched both open and closed suggestions on this site and believe this is not a duplicate
  • [ X ] This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it.

Please tick all that apply:

  • [ X ] This is not a breaking change to the F# language design
  • [ X ] I or my company would be willing to help implement and/or test this
@sgtz sgtz changed the title tag AST nodes for pattern recognition tag AST nodes for pre-compile pattern recognition Sep 26, 2019
@sgtz sgtz changed the title tag AST nodes for pre-compile pattern recognition Tag AST nodes for pre-compile pattern recognition Sep 26, 2019
@sgtz sgtz changed the title Tag AST nodes for pre-compile pattern recognition Tag AST nodes for pattern recognition Sep 26, 2019
@Tarmil

This comment has been minimized.

Copy link

commented Oct 1, 2019

I don't really follow what it is you're requesting here. Do you have a concrete example of something that would be made possible or easier? When you talk about OCaml, I assume you mean the [@foo] syntax? But that is used by a compile-time AST transformation plugin system, so if that's what you're requesting, then this is XXL, not S.

@7sharp9

This comment has been minimized.

Copy link
Member

commented Oct 1, 2019

Maybe look at myraid as this aims to fill this space, attribute on a type and precompile phase code gen via AST

@Tarmil

This comment has been minimized.

Copy link

commented Oct 1, 2019

I didn't mean that I'm skeptical about the usefulness :) I just mean that the design space for this kind of code metadata is extremely vast, and I'm unsure if what is being suggested is indeed something like Myriad or something completely different.

@cartermp

This comment has been minimized.

Copy link
Member

commented Oct 1, 2019

Yeah, I'm not sure what is being suggested here.

@7sharp9

This comment has been minimized.

Copy link
Member

commented Oct 1, 2019

@Tarmil Myriad is similar to the attribute tagging that you suggested that OCaml does. Im all for creating new stuff that doesn't impinge on adding to the compiler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.