From b3c75936a4912ca794cdcecfeb92044552336c63 Mon Sep 17 00:00:00 2001 From: Pierre Letouzey Date: Wed, 4 Apr 2018 10:43:38 +0200 Subject: prim notations backtrackable, their declarations now in two parts (API change) The first part (e.g. register_bignumeral_interpretation) deals only with the interp/uninterp closures. It should typically be done as a side effect during a syntax plugin loading. No prim notation are active yet after this phase. The second part (enable_prim_token_interpretation) activates the prim notation. It is now correctly talking to Summary and to the LibStack. To avoid "phantom" objects in libstack after a mere Require, this second part should be done inside a Mltop.declare_cache_obj The link between the two parts is a prim_token_uid (a string), which should be unique for each primitive notation. When this primitive notation is specific to a scope, the scope_name could be used as uid. Btw, the list of "patterns" for detecting when an uninterpreter should be considered is now restricted to a list of global_reference (inductive constructors, or injection functions such as IZR). The earlier API was accepting a glob_constr list, but was actually only working well for global_reference. A minimal compatibility is provided (declare_numeral_interpreter), but is discouraged, since it is known to store uncessary objects in the libstack. --- test-suite/interactive/PrimNotation.v | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test-suite/interactive/PrimNotation.v (limited to 'test-suite/interactive') diff --git a/test-suite/interactive/PrimNotation.v b/test-suite/interactive/PrimNotation.v new file mode 100644 index 0000000000..ca8cba67d5 --- /dev/null +++ b/test-suite/interactive/PrimNotation.v @@ -0,0 +1,18 @@ +(* Until recently, the Notation.declare_numeral_notation wasn't synchronized + w.r.t. backtracking. This should be ok now. + This test is pretty artificial (we must declare Z_scope for this to work). +*) + +Delimit Scope Z_scope with Z. +Open Scope Z_scope. +Check 0. +(* 0 : nat *) +Require BinNums. +Check 0. +(* 0 : BinNums.Z *) +Back 2. +Check 0. +(* Expected answer: 0 : nat *) +(* Used to fail with: +Error: Cannot interpret in Z_scope without requiring first module BinNums. +*) -- cgit v1.2.3 From 3c7c0bb08d406d4addfc0ac68dce45bf7c5cb7e9 Mon Sep 17 00:00:00 2001 From: Pierre Letouzey Date: Wed, 11 Apr 2018 09:58:56 +0200 Subject: WIP: adapt Numeral Notation to synchronized prim notations --- test-suite/interactive/PrimNotation.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test-suite/interactive') diff --git a/test-suite/interactive/PrimNotation.v b/test-suite/interactive/PrimNotation.v index ca8cba67d5..4c81095c68 100644 --- a/test-suite/interactive/PrimNotation.v +++ b/test-suite/interactive/PrimNotation.v @@ -7,7 +7,7 @@ Delimit Scope Z_scope with Z. Open Scope Z_scope. Check 0. (* 0 : nat *) -Require BinNums. +Require BinInt. Check 0. (* 0 : BinNums.Z *) Back 2. -- cgit v1.2.3 From ebf453d4ae4e4f0312f3fd696da26c03671bc906 Mon Sep 17 00:00:00 2001 From: Jason Gross Date: Tue, 24 Jul 2018 13:06:03 -0400 Subject: Update doc and test-suite after supporting univ poly Also make `Check S` no longer anomaly Add a couple more test cases for numeral notations Also add another possibly-confusing error message to the doc. Respond to Hugo's doc request with Zimmi48's suggestion From https://github.com/coq/coq/pull/8064/files#r204191608 --- test-suite/interactive/PrimNotation.v | 58 +++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 6 deletions(-) (limited to 'test-suite/interactive') diff --git a/test-suite/interactive/PrimNotation.v b/test-suite/interactive/PrimNotation.v index 4c81095c68..07986b0df3 100644 --- a/test-suite/interactive/PrimNotation.v +++ b/test-suite/interactive/PrimNotation.v @@ -5,14 +5,60 @@ Delimit Scope Z_scope with Z. Open Scope Z_scope. -Check 0. -(* 0 : nat *) +Check let v := 0 in v : nat. +(* let v := 0 in v : nat : nat *) Require BinInt. -Check 0. -(* 0 : BinNums.Z *) +Check let v := 0 in v : BinNums.Z. +(* let v := 0 in v : BinNums.Z : BinNums.Z *) Back 2. -Check 0. -(* Expected answer: 0 : nat *) +Check let v := 0 in v : nat. +(* Expected answer: let v := 0 in v : nat : nat *) (* Used to fail with: Error: Cannot interpret in Z_scope without requiring first module BinNums. *) + +Local Set Universe Polymorphism. +Delimit Scope punit_scope with punit. +Delimit Scope pcunit_scope with pcunit. +Delimit Scope int_scope with int. +Numeral Notation Decimal.int Decimal.int_of_int Decimal.int_of_int : int_scope. +Module A. + NonCumulative Inductive punit@{u} : Type@{u} := ptt. + Cumulative Inductive pcunit@{u} : Type@{u} := pctt. + Definition to_punit : Decimal.int -> option punit + := fun v => match v with 0%int => Some ptt | _ => None end. + Definition to_pcunit : Decimal.int -> option pcunit + := fun v => match v with 0%int => Some pctt | _ => None end. + Definition of_punit : punit -> Decimal.uint := fun _ => Nat.to_uint 0. + Definition of_pcunit : pcunit -> Decimal.uint := fun _ => Nat.to_uint 0. + Numeral Notation punit to_punit of_punit : punit_scope. + Check let v := 0%punit in v : punit. + Back 2. + Numeral Notation pcunit to_pcunit of_pcunit : punit_scope. + Check let v := 0%punit in v : pcunit. +End A. +Reset A. +Local Unset Universe Polymorphism. +Module A. + Inductive punit : Set := ptt. + Definition to_punit : Decimal.int -> option punit + := fun v => match v with 0%int => Some ptt | _ => None end. + Definition of_punit : punit -> Decimal.uint := fun _ => Nat.to_uint 0. + Numeral Notation punit to_punit of_punit : punit_scope. + Check let v := 0%punit in v : punit. +End A. +Local Set Universe Polymorphism. +Inductive punit@{u} : Type@{u} := ptt. +Definition to_punit : Decimal.int -> option punit + := fun v => match v with 0%int => Some ptt | _ => None end. +Definition of_punit : punit -> Decimal.uint := fun _ => Nat.to_uint 0. +Numeral Notation punit to_punit of_punit : punit_scope. +Check let v := 0%punit in v : punit. +Back 6. (* check backtracking of registering universe polymorphic constants *) +Local Unset Universe Polymorphism. +Inductive punit : Set := ptt. +Definition to_punit : Decimal.int -> option punit + := fun v => match v with 0%int => Some ptt | _ => None end. +Definition of_punit : punit -> Decimal.uint := fun _ => Nat.to_uint 0. +Numeral Notation punit to_punit of_punit : punit_scope. +Check let v := 0%punit in v : punit. -- cgit v1.2.3