aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKazuhiko Sakaguchi2020-02-21 01:08:44 +0900
committerKazuhiko Sakaguchi2020-02-21 01:08:44 +0900
commit935101ee1375ed930e993d0e76f2325ade562506 (patch)
treef382650e4fd0f3127ca12d46a40b880317a86b7e
parent21551b37cfa25657cf51179ad60e9ead455390f0 (diff)
parente57b2e19bbd9e5ab13f16e06ec9fbcff89a5e80c (diff)
Merge PR #11329: Fixing #11114: anomaly with Extraction Implicit on records.
Reviewed-by: pi8027
-rw-r--r--doc/changelog/12-misc/11329-master+fix11114-extraction-anomaly-implicit-record.rst4
-rw-r--r--plugins/extraction/extraction.ml13
-rw-r--r--test-suite/bugs/closed/bug_11114.v17
3 files changed, 28 insertions, 6 deletions
diff --git a/doc/changelog/12-misc/11329-master+fix11114-extraction-anomaly-implicit-record.rst b/doc/changelog/12-misc/11329-master+fix11114-extraction-anomaly-implicit-record.rst
new file mode 100644
index 0000000000..0a686dd87d
--- /dev/null
+++ b/doc/changelog/12-misc/11329-master+fix11114-extraction-anomaly-implicit-record.rst
@@ -0,0 +1,4 @@
+- **Fixed:**
+ :cmd:`Extraction Implicit` on the constructor of a record was leading to an anomaly
+ (`#11329 <https://github.com/coq/coq/pull/11329>`_,
+ by Hugo Herbelin, fixes `#11114 <https://github.com/coq/coq/pull/11114>`_).
diff --git a/plugins/extraction/extraction.ml b/plugins/extraction/extraction.ml
index 9b30ddd958..71a3dcfef2 100644
--- a/plugins/extraction/extraction.ml
+++ b/plugins/extraction/extraction.ml
@@ -507,21 +507,22 @@ and extract_really_ind env kn mib =
assert (Int.equal (List.length field_names) (List.length typ));
let projs = ref Cset.empty in
let mp = MutInd.modpath kn in
- let rec select_fields l typs = match l,typs with
+ let implicits = implicits_of_global (GlobRef.ConstructRef (ip,1)) in
+ let rec select_fields i l typs = match l,typs with
| [],[] -> []
- | _::l, typ::typs when isTdummy (expand env typ) ->
- select_fields l typs
+ | _::l, typ::typs when isTdummy (expand env typ) || Int.Set.mem i implicits ->
+ select_fields (i+1) l typs
| {binder_name=Anonymous}::l, typ::typs ->
- None :: (select_fields l typs)
+ None :: (select_fields (i+1) l typs)
| {binder_name=Name id}::l, typ::typs ->
let knp = Constant.make2 mp (Label.of_id id) in
(* Is it safe to use [id] for projections [foo.id] ? *)
if List.for_all ((==) Keep) (type2signature env typ)
then projs := Cset.add knp !projs;
- Some (GlobRef.ConstRef knp) :: (select_fields l typs)
+ Some (GlobRef.ConstRef knp) :: (select_fields (i+1) l typs)
| _ -> assert false
in
- let field_glob = select_fields field_names typ
+ let field_glob = select_fields (1+npar) field_names typ
in
(* Is this record officially declared with its projections ? *)
(* If so, we use this information. *)
diff --git a/test-suite/bugs/closed/bug_11114.v b/test-suite/bugs/closed/bug_11114.v
new file mode 100644
index 0000000000..dd981279db
--- /dev/null
+++ b/test-suite/bugs/closed/bug_11114.v
@@ -0,0 +1,17 @@
+Require Extraction.
+
+Inductive t (sig: list nat) :=
+| T (k: nat).
+
+Record pkg :=
+ { _sig: list nat;
+ _t : t _sig }.
+
+Definition map (f: nat -> nat) (p: pkg) :=
+ {| _sig := p.(_sig);
+ _t := match p.(_t) with
+ | T _ k => T p.(_sig) (f k)
+ end |}.
+
+Extraction Implicit Build_pkg [_sig].
+Extraction TestCompile map.