Skip to content

Conversation

zth
Copy link
Member

@zth zth commented Sep 11, 2025

This migrates fn arguments to use the AST nodes with locations in the typed tree as well. It was previously just used for the parsetree.

Lays the foundations for some other refactors as well.

innerFunctionDefinition.kind
|> List.map (fun (entry : Kind.entry) ->
( Asttypes.Noloc.Labelled entry.label,
( Asttypes.Labelled {txt = entry.label; loc = Location.none},
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've assumed that tracking the loc is unimportant here since reanalyze worked well before this refactor, and didn't have locs then.

Comment on lines -176 to +178
if labelDecl.ld_optional then Asttypes.Noloc.Optional lblName
else Labelled lblName
if labelDecl.ld_optional then
Asttypes.Optional {txt = lblName; loc = Location.none}
else Asttypes.Labelled {txt = lblName; loc = Location.none}
Copy link
Member Author

Choose a reason for hiding this comment

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

Same here, I've assumed tracking the loc is not important here. We could however trivially add labelDecl.ld_loc here if we wanted to.

Copy link

pkg-pr-new bot commented Sep 11, 2025

Open in StackBlitz

rescript

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

@rescript/darwin-arm64

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

@rescript/darwin-x64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: c427212

@zth zth marked this pull request as ready for review September 11, 2025 09:12
@zth zth requested review from cristianoc and Copilot September 11, 2025 09:12
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR migrates the function argument handling in the typed tree representation from using location-stripped argument labels (Noloc.arg_label) to using AST nodes with locations (arg_label). This change aligns the typed tree with the parse tree representation and lays groundwork for future refactors.

Key changes:

  • Replace Noloc.arg_label with arg_label throughout the typed tree
  • Update pattern matching from string-based to record-based field access
  • Remove the to_noloc conversion function calls

Reviewed Changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
compiler/ml/typetexp.ml Remove conversion to noloc for function argument labels
compiler/ml/types.mli Update type definition to use located arg_label
compiler/ml/types.ml Update type definition to use located arg_label
compiler/ml/typedtree.mli Update function and argument type definitions
compiler/ml/typedtree.ml Update function and argument type definitions
compiler/ml/typecore.mli Update error type definitions
compiler/ml/typecore.ml Update error handling and pattern matching
compiler/ml/printtyped.ml Update argument label printing
compiler/ml/printtyp.mli Update function signature
compiler/ml/printtyp.ml Update label string conversion
compiler/ml/ctype.mli Update filter_arrow signature
compiler/ml/ctype.ml Update type comparison functions
compiler/ml/btype.mli Consolidate utility functions
compiler/ml/btype.ml Remove duplicate utility functions
compiler/ml/asttypes.ml Remove Noloc-specific comparison function
compiler/gentype/*.ml Update gentype translation functions
analysis/src/*.ml Update analysis functions for new label format

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@nojaf
Copy link
Member

nojaf commented Sep 11, 2025

I guess module Noloc is only used in parsetree0.ml.
Perhaps add a note there, that is only exists for legacy reasons.

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.

2 participants