-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
flambda-backend: Change [%call_pos] to the function's start position,…
… not the application's (#2765) This feature adjusts the position that [%call_pos] uses. The motivation is |>: ```ocaml (* f : here:[%call_pos] -> unit -> unit *) () |> f |> f ``` Previously, both calls to f received the same position for `~here`! Both positions were the start of `()`. This is because the AST of the expression is roughly `((() |> f) |> f)` and since call_pos uses the location of the entire function application, both calls to f had the same starting location (despite having different ending locations.) This is change in this commit by making [%call_pos] use the start position of the function instead of the start position of the entire application.
- Loading branch information
Showing
4 changed files
with
51 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
testsuite/tests/typing-implicit-source-positions/rev_apply_correct_location.ml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
(* TEST | ||
expect; | ||
*) | ||
|
||
let f ~(here : [%call_pos]) x = here, x | ||
|
||
[%%expect | ||
{| | ||
val f : here:[%call_pos] -> 'a -> lexing_position * 'a = <fun> | ||
|}] | ||
|
||
let result = () |> f |> f | ||
|
||
(* Importantly, these locations are different. *) | ||
[%%expect | ||
{| | ||
val result : lexing_position * (lexing_position * unit) = | ||
({pos_fname = ""; pos_lnum = 1; pos_bol = 145; pos_cnum = 169}, | ||
({pos_fname = ""; pos_lnum = 1; pos_bol = 145; pos_cnum = 164}, ())) | ||
|}] | ||
|
||
class ['a] c : here:[%call_pos] -> 'a -> object | ||
method here : lexing_position * 'a | ||
end = fun ~(here : [%call_pos]) a -> object | ||
method here = here, a | ||
end | ||
|
||
[%%expect{| | ||
class ['a] c : | ||
here:[%call_pos] -> 'a -> object method here : lexing_position * 'a end | ||
|}] | ||
|
||
let obj = (() |> new c |> new c) | ||
|
||
let second_here = fst obj#here | ||
let first_here = fst (snd obj#here)#here | ||
|
||
|
||
[%%expect{| | ||
val obj : unit c c = <obj> | ||
val second_here : lexing_position = | ||
{pos_fname = ""; pos_lnum = 1; pos_bol = 710; pos_cnum = 736} | ||
val first_here : lexing_position = | ||
{pos_fname = ""; pos_lnum = 1; pos_bol = 710; pos_cnum = 727} | ||
|}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters