From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Authentication-Results: plum.tunbury.org; dkim=pass (1024-bit key; unprotected) header.d=inria.fr header.i=@inria.fr header.a=rsa-sha256 header.s=dc header.b=v2+Ms6eW; dkim=pass (1024-bit key; secure) header.d=mail.quaesituri.org header.i=@mail.quaesituri.org header.a=rsa-sha256 header.s=mail header.b=CpZIv7f2; dkim-atps=neutral Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=192.134.164.83; helo=mail2-relais-roc.national.inria.fr; envelope-from=caml-list-owner@inria.fr; receiver=tunbury.org Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by plum.tunbury.org (Postfix) with ESMTPS id 3D56C400A3 for ; Tue, 3 Jun 2025 09:23:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inria.fr; s=dc; h=message-id:date:mime-version:to:references:from: in-reply-to:subject:reply-to:sender:list-id:list-help: list-subscribe:list-unsubscribe:list-post:list-owner: list-archive; bh=i8HAiV3RypL6m644aK7y2wwi+ypVoeQjgs3WavWkilo=; b=v2+Ms6eWj9bb+kbLlIxo/zsnxoM0WE7k96I1gRa6RuqEAdDz8v8g98fq d3TrTeyWauTgeA/0SwTZ3I0npzDnL0SqGbqKLMADyhNot1HxkMX9pGbaX ++DErWiTBczvS3YSr84gxtQ3ObKG+NZaF4ldR/NQ6TH6ZwSYkRYjdHQDs c=; Received-SPF: Pass (mail2-relais-roc.national.inria.fr: domain of caml-list-owner@inria.fr designates 128.93.162.160 as permitted sender) identity=mailfrom; client-ip=128.93.162.160; receiver=mail2-relais-roc.national.inria.fr; envelope-from="caml-list-owner@inria.fr"; x-sender="caml-list-owner@inria.fr"; x-conformance=spf_only; x-record-type="v=spf1"; x-record-text="v=spf1 include:mailout.safebrands.com a:basic-mail.safebrands.com a:basic-mail01.safebrands.com a:basic-mail02.safebrands.com ip4:128.93.142.0/24 ip4:192.134.164.0/24 ip4:128.93.162.160 ip4:128.93.162.3 ip4:128.93.162.88 ip4:89.107.174.7 mx ~all" Received-SPF: None (mail2-relais-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@sympa.inria.fr) identity=helo; client-ip=128.93.162.160; receiver=mail2-relais-roc.national.inria.fr; envelope-from="caml-list-owner@inria.fr"; x-sender="postmaster@sympa.inria.fr"; x-conformance=spf_only Authentication-Results: mail2-relais-roc.national.inria.fr; spf=Pass smtp.mailfrom=caml-list-owner@inria.fr; spf=None smtp.helo=postmaster@sympa.inria.fr; dkim=pass (signature verified) header.i=@mail.quaesituri.org X-IronPort-AV: E=Sophos;i="6.16,205,1744063200"; d="scan'208,217";a="225026962" Received: from prod-listesu18.inria.fr (HELO sympa.inria.fr) ([128.93.162.160]) by mail2-relais-roc.national.inria.fr with ESMTP; 03 Jun 2025 11:23:15 +0200 Received: by sympa.inria.fr (Postfix, from userid 20132) id E2759E0AF1; Tue, 3 Jun 2025 11:23:14 +0200 (CEST) Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id ABE5AE0131 for ; Tue, 3 Jun 2025 11:23:11 +0200 (CEST) IronPort-SDR: 683ebefe_+EEUlTob2QSR5/Y38MMgNIzYzULsksFNqSgKJCMr+UiiSEB aP76lWLP4UU7N4N3buZNQPtYc6Lnuas1qA9GsCQ== X-IPAS-Result: =?us-ascii?q?A0GNBACtvT5o/5qjd6hQCh0CAgkUBQWCFIJEgQBaMwQLS?= =?us-ascii?q?YRViHuHMQEGgT4DhDuHOZQhDwEDAQ0xIAQBAQSFAwKLXx8HAQQ0EwECBAEBA?= =?us-ascii?q?QEDAgMBAQEBAQEQAQEFAQEBAgEBAgQGAQKBChOFew2CW4JRLIELAQEBAgEjB?= =?us-ascii?q?BkBATgPC0ICAlYbAQGCfgGCIQInJAOvYH8zgQG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g52ApBVH7bPS8SnfgjcwYtNMyMwSF KLYRwigIEex20RGujbqgpFfG2yaZdIkWlXN7Nqt+r9UK6NZ4fBeT04i95CV4VOXCVJD1DCJt lrhY6T28bRT+b50ldGxLpQZVhSGEvKtZuGm6wvpjs9va+nIOsLwtw84jFnrEgBVHLkJUeRMi rW/n4/r7XzBoYoJfTjVq7uZG4lNwPeCbu5dH8b0DXtdxA+pesvn5Tkd8GGZd71Ntv5g5fece gjpU/voKOYpWOpcykMMOmIaW1wYBr/sZ6jtmTKlor7eQlIB2AjAN5W8+WWvcWhfcTQSNobjD hPv/cyj/c1csJ8GESps6yuK2HOkCASLtWoam9zNWf2wC2CphhWbp7Lvjhs89CvKTH6eH64WJ H4DqgfWLHyPVGPglbm1cLCeejUPC3Jsiuk3ZEUbvdBs49x/JHBTNvwTaP3qFbkN+hEfF/jEi PXldGwmGC79Wi5Dd1Py+rwPm+tZ6vMmYr/EG9Diw69Yh+paym9N7HuNOxqMO0tLRwY= IronPort-HdrOrdr: A9a23:VOcqJKCQaUfEO0DlHemm55DYdb4zR+YMi2TDsHoddfU1SKClfq +V/cjzuSWE7Qr5O0tOpTn/Asm9qBrnnPYfi7X5W43SODUPIQCTXeZfBODZsl/d8kPFh41gPN 9bHZRDNA== X-Talos-CUID: 9a23:pQMWRm6d0a3r5UgBwdsst3NMAO4FaSfmk0zQKFXpCH1gdby+YArF X-Talos-MUID: 9a23:dR+/nQRZ5N28ejIjRXTPoQ46Oedv45iWGUwPiIkFotGpDDZ/bmI= X-IronPort-Anti-Spam-Filtered: true X-IronPort-AV: E=Sophos;i="6.16,205,1744063200"; d="scan'208,217";a="118079845" X-MGA-submission: =?us-ascii?q?MDHhRci4MnHjKYT5HZuPWk0mL0kr+lCIm4wLKa?= =?us-ascii?q?562yz7yh9pjnrcftHYMs2KUV83wcbdg5NbHrFZWpXBc5VadabhfhiJ24?= =?us-ascii?q?NprPow9bTRk+hjNn75fajGweP3PcZ1CJ79fYBHV/2ORyQhoysZprKjJ1?= =?us-ascii?q?c9SXcbKmhg7uRsaqzJ5rsWpQ=3D=3D?= Received: from quaesituri.org (HELO mail.quaesituri.org) ([168.119.163.154]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jun 2025 11:23:09 +0200 Received: from [128.93.64.106] (cadillac.paris.inria.fr [128.93.64.106]) by mail.quaesituri.org (Postfix) with ESMTPSA id A8B7C9F938 for ; Tue, 03 Jun 2025 11:23:08 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.quaesituri.org A8B7C9F938 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mail.quaesituri.org; s=mail; t=1748942588; bh=i8HAiV3RypL6m644aK7y2wwi+ypVoeQjgs3WavWkilo=; h=Date:Subject:To:References:From:In-Reply-To:From; b=CpZIv7f2QtwotPIkAu0RmEMk8GdfUikBkwf5ABKGUmHLuMhXTgCo5CU5pr8xAjqYu 4dOBVDuN0LZVwrVILBaI9B4f3ZEYL9efzunIbm2anrz3nkGfX0ueQebIjThLNiDS0d WILiP9YkBsHAYADB53ORSIqt2QKz7m167SnJUs3Y= Content-Type: multipart/alternative; boundary="------------rea6kTVuL0Q0J2bT0j10jr9n" Message-ID: <62c6640c-d06c-4103-b479-5dace4b5cfaf@polychoron.fr> Date: Tue, 3 Jun 2025 11:23:08 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: caml-list@inria.fr References: <26E93D7A-BAF3-46FB-8CAF-8DA7F7DEAF6B@mpi-sws.org> Content-Language: en-US From: Florian Angeletti In-Reply-To: <26E93D7A-BAF3-46FB-8CAF-8DA7F7DEAF6B@mpi-sws.org> Subject: Re: [Caml-list] Warning 69 (unused record fields) and polymorphic reads Reply-To: Florian Angeletti X-Loop: caml-list@inria.fr X-Sequence: 19334 Errors-To: caml-list-owner@inria.fr Precedence: list Precedence: bulk Sender: caml-list-request@inria.fr X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: This is a multi-part message in MIME format. --------------rea6kTVuL0Q0J2bT0j10jr9n Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Those warnings can be suppressed on the type definition by adding a `@@warning` attribute module M: sig type t end = struct   type t = { x:int; y:int } [@@warning "-unused-field"] end With this attribute, the compiler will not register those fields for the usage checker and thus no unused warning fields will be emitted for the fields `x` and `y` For this specific warning, the compiler even supports disabling the usage checker field-by-field. For instance, this code will only disable the warning for the `M.x` field, and thus warns module M: sig type t end = struct   type t = { x:int[@warning "-unused-field"] ; y:int } end  that the field `y` is being unused while omitting the check for the  field `x`. — Florian. Le 03/06/2025 à 11:11, Andreas Rossberg a écrit : > Today, I ran into a slight annoyance with warning 69 (unused record fields). Obviously, the warning does not consider uses of polymorphic operators like `=` or `compare`, which technically are reads of the fields. Unfortunately, it turns out that there are reasonable use cases where these are the _only_ reads, resulting in bogus warnings. > > There probably isn't much that can be done about it(?), since such access could hide in any polymorphic function invocation. Hence I didn’t file a bug. But for the record, I thought I'll show the counter example anyway. > > Consider code that implements some processing akin to SQL `group by`, as in: > ``` > SELECT artist, album, COUNT(*), SUM(time), ... FROM Tracks GROUP BY artist, album; > ``` > Intuitively, this extracts all known albums from a list of track (song) meta data, and computes their total running time, among other values. > > Here is a sketch of how to achieve something similar in OCaml: > ``` > module GroupKey = > struct > type t = {artist : string; title : string} > let compare = compare > end > module GroupMap = Map.Make(GroupKey) > > type track = ... > type acc = ... (* result type *) > val empty_acc : acc > val accumulate : entry -> acc -> acc (* combine result *) > > let albums = > tracks > |> List.fold_left (fun map (entry : track) -> > let group = {artist = entry.artist; title = entry.title} in > let acc = Option.value (GroupMap.find_opt group map) ~default: empty_acc in > GroupMap.add group (accumulate acc entry) map > ) GroupMap.empty > |> GroupMap.bindings |> List.map snd > ``` > The only purpose of the `GroupKey.t` type in this code is to identify entries belonging to the same group. Its fields are read implicitly by `GroupMap.find/add`, which invokes `compare` on them. Yet, this code produces warnings that `artist` and `title` are never read, which technically isn’t quite correct. > > In my actual code, the key record has more fields, which is why I didn’t want to replace it with a tuple. > > Perhaps there is some annotation magic I’m missing that could be applied to the type definition to suppress the warning? > > /Andreas > --------------rea6kTVuL0Q0J2bT0j10jr9n Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit Those warnings can be suppressed on the type definition by adding a `@@warning` attribute
module M: sig type t end = struct
  type t = { x:int; y:int } [@@warning "-unused-field"]
end
With this attribute, the compiler will not register those fields for the usage checker and thus no unused
warning fields will be emitted for the fields `x` and `y`

For this specific warning, the compiler even supports disabling the usage checker field-by-field.
For instance, this code will only disable the warning for the `M.x` field, and thus warns
module M: sig type t end = struct
  type t = { x:int[@warning "-unused-field"] ; y:int }
end
 that the field `y` is being unused while omitting the check for the  field `x`.

— Florian.

Le 03/06/2025 à 11:11, Andreas Rossberg a écrit :
Today, I ran into a slight annoyance with warning 69 (unused record fields). Obviously, the warning does not consider uses of polymorphic operators like `=` or `compare`, which technically are reads of the fields. Unfortunately, it turns out that there are reasonable use cases where these are the _only_ reads, resulting in bogus warnings.

There probably isn't much that can be done about it(?), since such access could hide in any polymorphic function invocation. Hence I didn’t file a bug. But for the record, I thought I'll show the counter example anyway.

Consider code that implements some processing akin to SQL `group by`, as in:
```
SELECT artist, album, COUNT(*), SUM(time), ... FROM Tracks GROUP BY artist, album;
```
Intuitively, this extracts all known albums from a list of track (song) meta data, and computes their total running time, among other values.

Here is a sketch of how to achieve something similar in OCaml:
```
module GroupKey =
   struct
      type t = {artist : string; title : string}
      let compare = compare
   end
module GroupMap = Map.Make(GroupKey)

type track = ...
type acc = ...  (* result type *)
val empty_acc : acc
val accumulate : entry -> acc -> acc  (* combine result *)

let albums =
   tracks
   |> List.fold_left (fun map (entry : track) ->
         let group = {artist = entry.artist; title = entry.title} in
         let acc = Option.value (GroupMap.find_opt group map) ~default: empty_acc in
         GroupMap.add group (accumulate acc entry) map
      ) GroupMap.empty
   |> GroupMap.bindings |> List.map snd
```
The only purpose of the `GroupKey.t` type in this code is to identify entries belonging to the same group. Its fields are read implicitly by `GroupMap.find/add`, which invokes `compare` on them. Yet, this code produces warnings that `artist` and `title` are never read, which technically isn’t quite correct.

In my actual code, the key record has more fields, which is why I didn’t want to replace it with a tuple.

Perhaps there is some annotation magic I’m missing that could be applied to the type definition to suppress the warning?

/Andreas


--------------rea6kTVuL0Q0J2bT0j10jr9n--