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

add new function type syntax (second try, closes #4799) #6667

Closed

Conversation

nadako
Copy link
Member

@nadako nadako commented Oct 10, 2017

This also implements HaxeFoundation/haxe-evolution#23, but as discussed in #6645, this changes representation of arguments in CTFunction (and haxe.macro.Expr.TFunction).

@@ -573,6 +573,26 @@ enum ComplexType {
}

/**
Represents an argument of a function type (`ComplexType.TFunction`).
**/
typedef FunctionTypeArg = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we add a new type anyway we should consider adding the name position.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to ask about that, don't we want to have generic PlacedName instead of adding namePos fields?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure. I think a flat structure is easier to handle, less breaking and even more performant (no nested object allocation).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I also add typePos then?

TBH I wouldn't do that just now because adding positions to random types sounds really inconsistent. I would rather wait for some kind of parse tree integration to support precise positions and leave AST alone.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concern is that this will require people to update their macro code, and then if/when we add more positions, they have to update it again.

Also, we definitely have to make sure we don't lose the position in an encode/decode roundtrip. Check the other occurrences of encode_placed_name, they all come with a name_pos encoding as well. It's just not exposed on the Haxe side yet.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I added namePos (should be that instead of name_pos for Haxe, right?)

@nadako
Copy link
Member Author

nadako commented Oct 11, 2017

I'll just copy-paste the nice gif from #6645

@@ -128,6 +128,7 @@ class TypeTools {
[ for (a in args)
{
name: a.name,
namePos: {file: "", min: -1, max: -1}, // TODO, I guess?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Simn should we also use placed_name for TFun then?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure... it's kind of expected to lose some information when going typed -> untyped.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should make namePos optional for now, because for old syntax it doesn't even make sense...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the entire type is new, so why does it matter?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because there will be a lot of null_pos positions encoded for the old syntax. Maybe an optional field or a Null<Position> would be better for performance.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt that would even be measurable... but if it makes you feel better, I don't mind.

@ncannasse
Copy link
Member

We can have a single CTFunction in Haxe compiler but we need to accept both old TFunction and new TFunctionArgs (or another name) in macro code, so we don't have to do a lot of #if

BTW, is there #if haxe4 ? would be simplier than #if (haxe_ver >= 4)

@nadako
Copy link
Member Author

nadako commented Oct 11, 2017

Closing this in favor of #6645 again (see discussions there).

@nadako nadako closed this Oct 11, 2017
@nadako nadako deleted the new_function_type_syntax2 branch October 12, 2017 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants