Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 3 commits into from
Jul 18, 2025

Conversation

cristianoc
Copy link
Collaborator

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.

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.
@cristianoc cristianoc force-pushed the ast-attributes-on-fun-args branch from efc80bd to df4c0ab Compare July 17, 2025 08:27
Copy link

pkg-pr-new bot commented Jul 17, 2025

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@7660

@rescript/darwin-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-arm64@7660

@rescript/darwin-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@7660

@rescript/linux-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-arm64@7660

@rescript/linux-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-x64@7660

@rescript/win32-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/win32-x64@7660

commit: 99827ba

Copy link
Collaborator

@nojaf nojaf left a 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"
Copy link
Collaborator

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?

Copy link
Collaborator Author

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"
}

Copy link
Collaborator Author

@cristianoc cristianoc left a 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 ] ->
Copy link
Collaborator Author

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"
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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.
@cristianoc cristianoc requested a review from zth July 17, 2025 09:06
@zth
Copy link
Collaborator

zth commented Jul 17, 2025

@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).

Sounds correct!

@cristianoc cristianoc merged commit cea6328 into master Jul 18, 2025
27 checks passed
@cristianoc cristianoc deleted the ast-attributes-on-fun-args branch July 18, 2025 06:46
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.

3 participants