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

Specialization vs Indirections #7907

Closed
vicuna opened this issue Feb 2, 2019 · 4 comments
Closed

Specialization vs Indirections #7907

vicuna opened this issue Feb 2, 2019 · 4 comments

Comments

@vicuna
Copy link

vicuna commented Feb 2, 2019

Original bug ID: 7907
Reporter: @Drup
Status: new
Resolution: open
Priority: normal
Severity: minor
Category: middle end (typedtree to clambda)
Monitored by: @hcarty

Bug description

Several people proposed to have functors that would easily introduce infix operators based on given primitives. That scheme is also used in the monomorphic library (https://github.com/kit-ty-kate/ocaml-monomorphic) and a few others.

We already know that specialization of primitives and abstraction don't play particularly well together (#7440), but apparently, basic indirections are really bad too:

module Make (A : sig type t end) : sig
val (=) : A.t -> A.t -> bool
(* external ( = ) : A.t -> A.t -> bool = "%equal" (* SPECIALIZE IF UNCOMENTED *) *)
end = struct
external ( = ) : A.t -> A.t -> bool = "%equal"
end

module F = Make(Float)
let equal1 (a : float) b = F.(=) a b (* NOT SPECIALIZED *)
let equal2 (a : float) b = (=) a b (* SPECIALIZED *)

inlining often doesn't help at all with functors, but sometime does in less complex examples. The result is the same with clambda and flambda.

@vicuna
Copy link
Author

vicuna commented Feb 5, 2019

Comment author: @stedolan

Internally, this issue is the same as #7440. When an external is exposed by a signature using "val" rather than "external", it is eta-expanded. In other words, the module:

module Make (A : sig type t end) : sig
  val (=) : A.t -> A.t -> bool
end = struct
  external ( = ) : A.t -> A.t -> bool = "%equal"
end

is internally converted to:

module Make (A : sig type t end) : sig
  val (=) : A.t -> A.t -> bool
end = struct
  external ( eq ) : A.t -> A.t -> bool = "%equal" 
  let (=) a b = eq a b
end

This turns it into the same pattern as #7440.

@github-actions
Copy link

github-actions bot commented May 6, 2020

This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc.

@github-actions github-actions bot added the Stale label May 6, 2020
@github-actions github-actions bot removed the Stale label Jun 10, 2020
@github-actions
Copy link

This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc.

@github-actions github-actions bot added the Stale label Jun 11, 2021
@gasche gasche removed the Stale label Jun 11, 2021
@github-actions
Copy link

github-actions bot commented Jul 1, 2022

This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc.

@github-actions github-actions bot added the Stale label Jul 1, 2022
@github-actions github-actions bot closed this as completed Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants