-
Notifications
You must be signed in to change notification settings - Fork 469
AST: store the attributes directly on function arguments. #7660
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
Conversation
Functions of several arguments are stored as nested `Ptyp_arrow` ast nodes, with attributes at toplevel in the node. This change adds an attribute field to type arguments, makin it impossible to distinguish attributes on arguments from attributes on the entire function.
efc80bd
to
df4c0ab
Compare
rescript
@rescript/darwin-arm64
@rescript/darwin-x64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/win32-x64
commit: |
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.
This is a very nice improvement! Great work!
@@ -15,7 +15,7 @@ module C4A1 = { | |||
@res.jsxComponentProps @live | |||
type props<'T_open, 'T_type> = {@as("open") _open: 'T_open, @as("type") _type: 'T_type} | |||
|
|||
external make: @as("open") React.componentLike<props<string, string>, React.element> = "default" | |||
external make: React.componentLike<props<string, string>, React.element> = "default" |
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.
Is this removed by design?
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.
This was captured by chance I think, as the open
is on the prop, not on the make
function:
module C4A1 = {
@react.component
external make: (@as("open") ~_open: string, @as("type") ~_type: string) => React.element =
"default"
}
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.
@zth looks like the editor tooling does not use attributes on functions anywhere -- does this sound right? Just double checking.
The new attributes are not passed to the typed ast yet (will be a simple change later on).
@@ -22,13 +22,13 @@ type nonrec t = f:(int -> string (a:1)) -> float (a:1) | |||
type nonrec t = f:(int -> string (a:1)) -> float | |||
type nonrec t = f:int -> string -> float (a:1) | |||
type nonrec t = | |||
((a:int -> ((b:int -> ((float)[@attr ]) -> unit)[@attrBeforeLblB ]) (a:3)) | |||
[@attrBeforeLblA ]) | |||
a:int[@attrBeforeLblA ] -> |
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.
This is ocaml's Pprintast
-- it's now clear that attributes go on type arguments.
@@ -15,7 +15,7 @@ module C4A1 = { | |||
@res.jsxComponentProps @live | |||
type props<'T_open, 'T_type> = {@as("open") _open: 'T_open, @as("type") _type: 'T_type} | |||
|
|||
external make: @as("open") React.componentLike<props<string, string>, React.element> = "default" | |||
external make: React.componentLike<props<string, string>, React.element> = "default" |
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.
This was captured by chance I think, as the open
is on the prop, not on the make
function:
module C4A1 = {
@react.component
external make: (@as("open") ~_open: string, @as("type") ~_type: string) => React.element =
"default"
}
@@ -132,7 +132,7 @@ type t = @attr (foo, @attr2 ~f: bar, @attr3 ~f: baz) => unit | |||
type t = @attr (string => @attr (int => unit)) | |||
type t = @attr (string, int) => @attr (int, float) => unit | |||
type t = @attr (int => @attr (int, float) => @attr (unit => unit => unit)) | |||
type t = (@attr @attr2 ~f: int, @attr3 ~g: float) => unit | |||
type t = @attr (@attr2 ~f: int, @attr3 ~g: float) => unit |
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.
This now correctly represents this type, distinguishing the attribute on the whole function from those on the function arguments:
type t = @attr ((@attr2 ~f: int, @attr3 ~g: float) => unit)
Introduces an 'attrs' field to the 'arg' record in typedtree.ml and typedtree.mli to support attributes on function arguments. Updates related code in typetexp.ml and printtyped.ml to handle the new field, enabling attribute preservation and printing for function argument types.
Sounds correct! |
Functions of several arguments are stored as nested
Ptyp_arrow
ast nodes, with attributes at toplevel in the node. This change adds an attribute field to type arguments, makin it impossible to distinguish attributes on arguments from attributes on the entire function.