diff --git a/docs/elpi-dependencies.dot b/docs/elpi-dependencies.dot index c224242..f840e04 100644 --- a/docs/elpi-dependencies.dot +++ b/docs/elpi-dependencies.dot @@ -10,6 +10,7 @@ digraph { "util-rocq" [URL="https://github.com/rocq-community/trocq/blob/master/elpi/util-rocq.elpi"]; "database" [shape=box, URL="https://github.com/rocq-community/trocq/blob/master/elpi/database.elpi"]; "aterm" [URL="https://github.com/rocq-community/trocq/blob/master/elpi/aterm.elpi"]; + "fake-aterm" [URL="https://github.com/rocq-community/trocq/blob/master/elpi/fake-aterm.elpi"]; "aterm-type" [shape=box, URL="https://github.com/rocq-community/trocq/blob/master/elpi/aterm-type.elpi"]; "c/constraints" [URL="https://github.com/rocq-community/trocq/blob/master/elpi/constraints/constraints.elpi"]; "constraints" [URL="https://github.com/rocq-community/trocq/blob/master/elpi/constraints.elpi"]; @@ -25,13 +26,14 @@ digraph { "vernac" [URL="https://github.com/rocq-community/trocq/blob/master/elpi/vernac.elpi"]; ## DEPENDENCIES - "util" -> {"database" "util-rocq"}; - "logging" -> {"aterm"}; + "util" -> {"database"}; + "logging" -> {"util-rocq"}; "util-rocq" -> {"param-class-util"}; "class" -> {"aterm-type"}; "database" -> {"logging" "param-class-util"}; - "aterm" -> {"c/constraints"}; - "aterm-type" -> {"database" "util-rocq"}; + "aterm" -> {"c/constraints" "fake-aterm"}; + "aterm-type" -> {"database"}; + "fake-aterm" -> {"vernac"} "constraints" -> "annot"; "c/constraints" -> "c/simple-graph"; "c/simple-graph" -> "c/constraint-graph"; diff --git a/docs/elpi-dependencies.svg b/docs/elpi-dependencies.svg index 84422ed..d69e0f9 100644 --- a/docs/elpi-dependencies.svg +++ b/docs/elpi-dependencies.svg @@ -4,20 +4,20 @@ - - - - + + + + cluster_trocqdb - -trocq.db header + +trocq.db header - + cluster_constraints - - -constraints + + +constraints @@ -25,298 +25,307 @@ class - -class + +class - + aterm-type - - -aterm-type + + +aterm-type - + class->aterm-type - - + + util - -util + +util - - -util-rocq - - -util-rocq - - - - - -util->util-rocq - - - database - -database + +database - + util->database - - + + logging - -logging + +logging - - -aterm - - -aterm + + +util-rocq + + +util-rocq - - -logging->aterm - - + + +logging->util-rocq + + - + param-class-util - - -param-class-util + + +param-class-util - + util-rocq->param-class-util - - + + - + database->logging - - + + - + database->param-class-util - - + + + + + +aterm + + +aterm + + + + + +fake-aterm + + +fake-aterm + + + + + +aterm->fake-aterm + + - + c/constraints - - -c/constraints + + +c/constraints aterm->c/constraints - - + + - - -aterm-type->util-rocq - - + + +vernac + + +vernac + - + + +fake-aterm->vernac + + + + + aterm-type->database - - + + - + c/simple-graph - - -c/simple-graph + + +c/simple-graph c/constraints->c/simple-graph - - + + - + constraints - - -constraints + + +constraints - + annot - - -annot + + +annot constraints->annot - - + + - + coercion - - -coercion + + +coercion - + c/constraint-graph - - -c/constraint-graph + + +c/constraint-graph c/simple-graph->c/constraint-graph - - + + - + c/constraints-impl - - -c/constraints-impl + + +c/constraints-impl c/constraint-graph->c/constraints-impl - - + + c/constraints-impl->constraints - - + + - + param - - -param + + +param annot->param - - - - - -vernac - - -vernac - - + + annot->vernac - - + + - + data - - -data + + +data data->aterm - - + + param-class-util->data - - + + param->coercion - - + + - + tactic - - -tactic + + +tactic param->tactic - - + + diff --git a/elpi/aterm.elpi b/elpi/aterm.elpi index 87b92ee..267f010 100644 --- a/elpi/aterm.elpi +++ b/elpi/aterm.elpi @@ -15,7 +15,6 @@ % ----------------------------------------------------------------------------- accumulate "Trocq.Elpi/data". -accumulate "Trocq.Elpi/logging". % `@pi-adecl N AT (ax\ x\ x'\ xr\ F x x' xr)` declares elpi pi-variables x x' xr with adecl % x has annotated type AT @@ -296,54 +295,6 @@ namespace aterm.util { annotate-legacy (pglobal G U) [] none (apglobal G U TG TG) :- coq.env.global G TG. - - func fake-term->aterm term -> aterm. - fake-term->aterm (app [PType|L]) (asort (typ U) Cl) :- - trocq.data.ptype PType, !, - L = [TM, TN], - trocq.data.term->map-class TM M, - trocq.data.term->map-class TN N, - if (var M, var N) - (Cl = _) - (Cl = pc M N), - coq.univ.new U. - fake-term->aterm (app [PTriple|L]) Out :- - trocq.data.ptriple PTriple, - L = [_,_,_,X,X',RX|L'], !, - std.map L' fake-term->aterm AL', - % XXX Reactivate this, but think about it first - %coq.elaborate-skeleton RX (prod `_` X _\ prod `_` X' _\ sort _) RXR Diag, - %(Diag = ok, ! ; trocq.error {coq.term->string RX} "is not a relation between" {coq.term->string X} "and" {coq.term->string X'} Diag), !, - RXR = RX, - if (X = global G) - (OutT = aglobal G X' RXR) - (if (X = pglobal G U) - (OutT = apglobal G U X' RXR) - (OutT = atriple X X' RXR)), - std.map L' fake-term->aterm AL', - aterm.util.mk-app OutT AL' Out. - fake-term->aterm (sort S) (asort S Cl) :- !, - prune Cl []. %XXX Check wether those prunes will cause any trouble. - fake-term->aterm (global G) (aglobal G G' RG) :- !, - prune G' [], - prune RG []. - fake-term->aterm (pglobal G U) (apglobal G U G' RG) :- !, - prune G' [], - prune RG []. - fake-term->aterm (fun Name T F) (afun Name AT AF) :- !, - fake-term->aterm T AT, - @pi-adecl Name AT (ay\ y\ _\ _\ - fake-term->aterm (F y) (AF ay) - ). - fake-term->aterm (prod Name T F) (aprod Name AT AF) :- !, - fake-term->aterm T AT, - @pi-adecl Name AT (ay\ y\ _\ _\ - fake-term->aterm (F y) (AF ay) - ). - fake-term->aterm (app L) (aapp AL) :- !, - std.map L fake-term->aterm AL. - fake-term->aterm X AX :- adecl AX _ X _ _ _, !. - % From a full aterm in the database, instantiates a aterm with holes func equals-ignore aterm -> aterm. equals-ignore X X' :- @@ -441,21 +392,4 @@ namespace aterm.util { topOf X X'. bottomOf X X :- !. topOf X X :- !. - - % {infer-aterm TR AT T T'} infers AT, T, and T' such that - % TR = [[AT]] T T' - func infer-aterm term -> aterm, term, term. - infer-aterm T _ _ _ :- - coq.say "Inferring on" T, fail, !. - infer-aterm (prod N T x\ prod N' T' x'\ prod _ (RTxx x x') rx\ RU x x' rx) - (aprod N AT ax\ AU ax) - (prod N T x\ U x) - (prod N' T' x'\ U' x') :- - @pi-decl N T x\ @pi-decl N' T' x'\ infer-aterm (RTxx x x') AT x x', - @pi-adecl N AT ax\ x\ x'\ rx\ ( - infer-aterm (RU x x' rx) (AU ax) (U x) (U' x') - ). - infer-aterm (app [ParamRelCl,T,T']) (asort S Cl) T T' :- - trocq.data.param.rel->param-class ParamRelCl Cl, !, - coq.typecheck T (sort S) ok. -} \ No newline at end of file +} diff --git a/elpi/data.elpi b/elpi/data.elpi index df37eed..8ccb366 100644 --- a/elpi/data.elpi +++ b/elpi/data.elpi @@ -154,18 +154,6 @@ namespace trocq.data { ptriple T :- coq.env.global G T, !, trocq.db.fake-aterm-ptype _ G, !. - - func term->map-class term -> map-class. - term->map-class T N :- - coq.env.global G T, - trocq.db.map-class->indc-class N G, !. - - func param.rel->param-class term -> param-class. - param.rel->param-class T Cl :- - coq.env.global G T, - trocq.db.rel Cl G _ _ _ _, - !. - } % trocq.data namespace trocq { diff --git a/elpi/fake-aterm.elpi b/elpi/fake-aterm.elpi new file mode 100644 index 0000000..acc3e5f --- /dev/null +++ b/elpi/fake-aterm.elpi @@ -0,0 +1,161 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % Trocq % +% _______ % Copyright (C) 2023 Inria & MERCE % +% |__ __| % (Mitsubishi Electric R&D Centre Europe) % +% | |_ __ ___ ___ __ _ % Cyril Cohen % +% | | '__/ _ \ / __/ _` | % Enzo Crance % +% | | | | (_) | (_| (_| | % Assia Mahboubi % +% |_|_| \___/ \___\__, | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% | | % This file is distributed under the terms of % +% |_| % GNU Lesser General Public License Version 3 % +% % (see LICENSE file for the text of the license) % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% ----------------------------------------------------------------------------- +% Convertion from/into fake aterms. +% ----------------------------------------------------------------------------- + +accumulate "Trocq.Elpi/aterm". + +% `@pi-adecl N AT (ax\ x\ x'\ xr\ F x x' xr)` declares elpi pi-variables x x' xr with adecl +% x has annotated type AT +macro @pi-adecl N PAD_AT PAD_F :- + aterm.raw-triple PAD_AT PAD_T PAD_T' PAD_RT, + util.name-suffix N "'" N', + util.name-suffix N "R" NR, + @pi-decl N PAD_T x\ ( + @pi-decl N' PAD_T' x'\ ( + util.mk-app PAD_RT [x, x'] (PAD_RTx x x'), + @pi-decl NR (PAD_RTx x x') xR\ ( + pi ax\ [ + adecl ax N x x' xR PAD_AT + ] => ( + logging.trace (coq.say "[adecl]" ax "==" x "@" PAD_AT "~" x' "∵" xR), + (PAD_F ax x x' xR) + )))). + +typeabbrev fake-map-class term. +typeabbrev fake-aterm term. + +% Converts a fake-map-class into a map-class. +func fake-map-class->map-class fake-map-class -> map-class. +fake-map-class->map-class (uvar as E) _ :- !, + trocq.error "[fake-map-class->map-class] called on the evar" {coq.term->string E}. +fake-map-class->map-class T N :- + coq.env.global G T, + trocq.db.map-class->indc-class N G, !. + +% Converts a map-class into a fake-map-class. +% +% Unification variables as input are supported, returning a Rocq evar. +% If the unification variable is assigned, the Rocq evar will be resolved too. +func map-class->fake-map-class map-class -> fake-map-class. +map-class->fake-map-class (uvar as E) T :- !, std.do![ + util.uvar-to-evar E T, + declare_constraint (map-class->fake-map-class E T) [E] +]. +map-class->fake-map-class N T :- + trocq.db.map-class->indc-class N G, + coq.env.global G T, !. + +% Converts a fake-aterm into an aterm. +func fake-aterm->aterm fake-aterm -> aterm. +fake-aterm->aterm (app [PType|L]) (asort (typ U) Cl) :- + trocq.data.ptype PType, !, + L = [TM, TN], + fake-map-class->map-class TM M, + fake-map-class->map-class TN N, + if (var M, var N) + (Cl = _) + (Cl = pc M N), + coq.univ.new U. +fake-aterm->aterm (app [PTriple|L]) Out :- + trocq.data.ptriple PTriple, + L = [_,_,_,X,X',RX|L'], !, + std.map L' fake-aterm->aterm AL', + % XXX Reactivate this, but think about it first + %coq.elaborate-skeleton RX (prod `_` X _\ prod `_` X' _\ sort _) RXR Diag, + %(Diag = ok, ! ; trocq.error {coq.term->string RX} "is not a relation between" {coq.term->string X} "and" {coq.term->string X'} Diag), !, + RXR = RX, + if (X = global G) + (OutT = aglobal G X' RXR) + (if (X = pglobal G U) + (OutT = apglobal G U X' RXR) + (OutT = atriple X X' RXR)), + std.map L' fake-aterm->aterm AL', + aterm.util.mk-app OutT AL' Out. +fake-aterm->aterm (sort S) (asort S Cl) :- !, + prune Cl []. %XXX Check whether those prunes will cause any trouble. +fake-aterm->aterm (global G) (aglobal G G' RG) :- !, + prune G' [], + prune RG []. +fake-aterm->aterm (pglobal G U) (apglobal G U G' RG) :- !, + prune G' [], + prune RG []. +fake-aterm->aterm (fun Name T F) (afun Name AT AF) :- !, + fake-aterm->aterm T AT, + @pi-adecl Name AT (ay\ y\ _\ _\ + fake-aterm->aterm (F y) (AF ay) + ). +fake-aterm->aterm (prod Name T F) (aprod Name AT AF) :- !, + fake-aterm->aterm T AT, + @pi-adecl Name AT (ay\ y\ _\ _\ + fake-aterm->aterm (F y) (AF ay) + ). +fake-aterm->aterm (app L) (aapp AL) :- !, + std.map L fake-aterm->aterm AL. +fake-aterm->aterm X AX :- adecl AX _ X _ _ _, !. +fake-aterm->aterm (uvar as E) _ :- !, + trocq.error "[fake-aterm->aterm] cannot create an annotated term out of an evar:" {coq.term->string E}. +fake-aterm->aterm T _ :- + trocq.error "[fake-aterm->aterm] not implemented for the subterm:" {coq.term->string T}. + +func normalize-apps term -> term. +normalize-apps (app [app [A|L]|L']) T :- !, + std.append L L' L'', + normalize-apps (app [A|L'']) T. +normalize-apps T T. + +% Converts a fake-aterm into an aterm. +func aterm->fake-aterm aterm -> fake-aterm. +aterm->fake-aterm (asort (typ _U) PC) (app [PType, NT, MT]) :- !, + % TODO: the universe level U cannot be represented in the fake-aterm because PType is not universe-polymorphic. + trocq.data.ptype PType, + PC = pc N M, + map-class->fake-map-class N NT, + map-class->fake-map-class M MT. +aterm->fake-aterm (asort S _) _ :- !, + trocq.error "[aterm->fake-aterm] sort" S "cannot be represented via a fake-aterm.". +aterm->fake-aterm (atriple N N' NR) (app [PTriple, _, _, _, N, N', NR]) :- !, + trocq.data.ptriple PTriple. +aterm->fake-aterm (aglobal G G' RG) (app [PTriple, _, _, _, global G, G', RG]) :- !, + trocq.data.ptriple PTriple. +aterm->fake-aterm (apglobal G UI G' RG) (app [PTriple, _, _, _, pglobal G UI, G', RG]) :- !, + trocq.data.ptriple PTriple. +aterm->fake-aterm (afun N A B) (fun N A' B') :- !, std.do! [ + aterm->fake-aterm A A', + @pi-adecl N A (ax\ x\ _\ _\ + aterm->fake-aterm (B ax) (B' x) + ) +]. +aterm->fake-aterm (aprod N A B) (prod N A' B') :- !, std.do! [ + aterm->fake-aterm A A', + @pi-adecl N A (ax\ x\ _\ _\ + aterm->fake-aterm (B ax) (B' x) + ) +]. +aterm->fake-aterm (alet _ _ _ _) _ :- !, + trocq.error "[aterm->fake-aterm] unsupported construct match". +aterm->fake-aterm (aapp AL) T :- !, + std.map AL aterm->fake-aterm L, + % L could be `[app ..|..]`, so `app T` could be not normalized. + normalize-apps (app L) T. +aterm->fake-aterm (amatch _ _ _) _ :- !, + trocq.error "[aterm->fake-aterm] unsupported construct match". +aterm->fake-aterm (afix _ _ _ _) _ :- !, + trocq.error "[aterm->fake-aterm] unsupported construct afix". +aterm->fake-aterm (aprimitive _) _ :- !, + trocq.error "[aterm->fake-aterm] unsupported construct aprimitive". +aterm->fake-aterm (uvar as E) T :- !, + util.uvar-to-evar E T, !, + declare_constraint (aterm->fake-aterm E T) [E]. +aterm->fake-aterm AX X :- adecl AX _ X _ _ _, !. diff --git a/elpi/util-rocq.elpi b/elpi/util-rocq.elpi index 08a6dbd..6ccd5e0 100644 --- a/elpi/util-rocq.elpi +++ b/elpi/util-rocq.elpi @@ -14,8 +14,7 @@ % utility predicates related to Rocq % ----------------------------------------------------------------------------- -accumulate "Trocq.Elpi/util". -accumulate "Trocq.Elpi/aterm-type". +accumulate "Trocq.Elpi/logging". % Some of the Coq native predicates raise errors in Elpi, stopping all % ongoing computations. Adding a custom flag like do-not-fail gives us an @@ -197,6 +196,32 @@ func name-suffix name, any -> name. name-suffix uvar _ _ :- !. name-suffix X S O :- coq.name-suffix X S O. +func uvar-evar-mapping? any, term ->. +uvar-evar-mapping? (uvar as U) E :- !, + declare_constraint (uvar-evar-mapping? U E) [_]. +uvar-evar-mapping? _ _ :- !, + trocq.error "[uvar-evar-mapping] not called on a uvar!". + +func uvar-evar-mapping! any, term ->. +uvar-evar-mapping! (uvar as U) E :- !, + declare_constraint (uvar-evar-mapping! U E) [_]. +uvar-evar-mapping! _ _ :- !, + trocq.error "[uvar-evar-mapping] not called on a uvar!". + +constraint uvar-evar-mapping? uvar-evar-mapping! { + rule (uvar-evar-mapping! U T1) \ (uvar-evar-mapping? U T2) <=> (T2 = T1). + rule \ (uvar-evar-mapping? U _) <=> false. +} + +% `uvar-to-evar U E` provides a way to associated an Elpi uvar `E` to a Rocq evar `U`. +% The mapping is unique: if `uvar-to-evar` is called once again on the same uvar `U`, the same Rocq evar will be returned. +% The uvar resolving will not cause an assignment to the evar. +pred uvar-to-evar any -> term. +uvar-to-evar U E :- + uvar-evar-mapping? U E. +uvar-to-evar U E :- + logging.trace (coq.say "[uvar-evar-mapping]" U "↔" {coq.term->string E}), + uvar-evar-mapping! U E. % Elpi does not allow replacing a named clause with a named clause. This is not allowed: % coq.elpi.accumulate Scope Database (clause ClauseName (replace ClauseName) Content) diff --git a/elpi/vernac.elpi b/elpi/vernac.elpi index b1d9b2d..85fb0a9 100644 --- a/elpi/vernac.elpi +++ b/elpi/vernac.elpi @@ -12,6 +12,7 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% accumulate "Trocq.Elpi/annot". +accumulate "Trocq.Elpi/fake-aterm". % API @@ -75,7 +76,7 @@ func vernac.infer-aterm term -> aterm. vernac.infer-aterm uvar _AT :- !. vernac.infer-aterm T AT :- (coq.elaborate-skeleton T _ ET ok, - aterm.util.fake-term->aterm ET AT + fake-aterm->aterm ET AT ; trocq.error "Could not make an annotated term out of term" {coq.term->string T}), !, logging.trace (coq.say "[infer-aterm] Inferred annotated term" AT). diff --git a/tests/_CoqProject.hott b/tests/_CoqProject.hott index c7f56f2..3169114 100644 --- a/tests/_CoqProject.hott +++ b/tests/_CoqProject.hott @@ -5,6 +5,9 @@ -R ../hott/ Trocq -R ../elpi/ Trocq.Elpi +elpi/fake_aterm.v +elpi/uvar_to_evar.v + unit_arrow_contravariant.v unit_coercion_deptype.v unit_coercion_onoff.v diff --git a/tests/_CoqProject.std b/tests/_CoqProject.std index 6a2bba8..ace6f76 100644 --- a/tests/_CoqProject.std +++ b/tests/_CoqProject.std @@ -4,6 +4,9 @@ -R ../std/ Trocq -R ../elpi/ Trocq.Elpi +elpi/fake_aterm.v +elpi/uvar_to_evar.v + unit_arrow_contravariant.v unit_coercion_deptype.v unit_coercion_onoff.v diff --git a/tests/elpi/fake_aterm.v b/tests/elpi/fake_aterm.v new file mode 100644 index 0000000..0a667fc --- /dev/null +++ b/tests/elpi/fake_aterm.v @@ -0,0 +1,120 @@ +(*****************************************************************************) +(* * Trocq *) +(* _______ * Copyright (C) 2023 Inria & MERCE *) +(* |__ __| * (Mitsubishi Electric R&D Centre Europe) *) +(* | |_ __ ___ ___ __ _ * Cyril Cohen *) +(* | | '__/ _ \ / __/ _` | * Enzo Crance *) +(* | | | | (_) | (_| (_| | * Assia Mahboubi *) +(* |_|_| \___/ \___\__, | ************************************************) +(* | | * This file is distributed under the terms of *) +(* |_| * GNU Lesser General Public License Version 3 *) +(* * see LICENSE file for the text of the license *) +(*****************************************************************************) + +From elpi Require Import elpi. +From Trocq Require Import Trocq. +From Trocq.Elpi Extra Dependency "fake-aterm.elpi" as fake_aterm. + +Axiom P : nat -> Type. + +Elpi Command Test. +Elpi Accumulate File fake_aterm. +Elpi Accumulate Db trocq.db. +Elpi Accumulate lp:{{ + +pred test-fake-map-class->map-class. +test-fake-map-class->map-class :- std.do! [ + fake-map-class->map-class {{ map0 }} map0, + fake-map-class->map-class {{ map1 }} map1, + fake-map-class->map-class {{ map2a }} map2a, + fake-map-class->map-class {{ map2b }} map2b, + fake-map-class->map-class {{ map3 }} map3, + fake-map-class->map-class {{ map4 }} map4, + % it does not support evars. + do-not-fail => not(fake-map-class->map-class {{ _ }} _) +]. + +pred test-map-class->fake-map-class. +test-map-class->fake-map-class :- std.do! [ + map-class->fake-map-class map0 {{ map0 }}, + map-class->fake-map-class map1 {{ map1 }}, + map-class->fake-map-class map2a {{ map2a }}, + map-class->fake-map-class map2b {{ map2b }}, + map-class->fake-map-class map3 {{ map3 }}, + map-class->fake-map-class map4 {{ map4 }}, + + % it supports uvars! + map-class->fake-map-class Uvar Evar, + var Evar, + % but if the uvar is assigned, the evar should be resolved. + Uvar = map0, not (var Evar), Evar = {{ map0 }} +]. + +pred test-fake-aterm->aterm. +test-fake-aterm->aterm :- std.do! [ + coq.locate "nat" Nat, + + % Sorts. Either the param-class of the sort is exactly specified via `PType`, or not if `Type` is used. In this case, the param-class is a unification variable. + fake-aterm->aterm {{ PType map3 map1 }} (asort (typ _) (pc map3 map1)), + fake-aterm->aterm {{ Type }} (asort (typ _) PC), var PC, + + % Triples (N, N', NR). + % Such a triple can be given exactly using `PTriple N N' NR`. + % In fake aterms, a global constant G is translated to a triple (G, G', GR) where G' and GR are unification variable. However, currently, triples of grefs are represented via aglobal instead of atriple. + fake-aterm->aterm {{ nat }} (aglobal Nat Nat' Rnat), var Nat', var Rnat, + fake-aterm->aterm {{ PTriple nat bool (fun _ _ => True) }} (aglobal Nat {{ bool }} {{ fun _ _ => True }}), + fake-aterm->aterm {{ PTriple (fun x: nat => x) (fun x: nat => x) (fun _ _ => True) }} ( + atriple {{ fun x: nat => x }} {{ fun x: nat => x }} {{ fun _ _ => True }} + ), + + % Lambda abstractions, foralls and applications. + fake-aterm->aterm {{ fun (n: nat) => P n }} (afun _ {fake-aterm->aterm {{ nat }}} (n\ + aapp [{fake-aterm->aterm {{ P }}}, n] + )), + fake-aterm->aterm {{ forall (n: nat), P n }} (aprod _ {fake-aterm->aterm {{ nat }}} (n\ + aapp [{fake-aterm->aterm {{ P }}}, n] + )), + + % Constructions not supported cause an error + do-not-fail => not (fake-aterm->aterm {{ _ }} _) +]. + +pred test-aterm->fake-aterm. +test-aterm->fake-aterm :- std.do! [ + coq.locate "nat" Nat, + Id = {{ fun x: nat => x }}, + FullRel = {{ fun _ _ => True }}, + + % Triples + aterm->fake-aterm (atriple Id Id FullRel) {{ PTriple lp:Id lp:Id lp:FullRel }}, + aterm->fake-aterm (aglobal Nat {{ nat }} FullRel) {{ PTriple nat nat lp:FullRel }}, + + % Sorts + aterm->fake-aterm (asort (typ _) (pc map4 map3)) {{ PType map4 map3 }}, + + % Lambda abstractions, foralls and applications. + aterm->fake-aterm (afun `n` {fake-aterm->aterm {{ nat }}} (n\ + aapp [{fake-aterm->aterm {{ P }}}, n] + )) {{ fun (n: PTriple nat _ _) => (PTriple P _ _) n }}, + aterm->fake-aterm (aprod `n` {fake-aterm->aterm {{ nat }}} (n\ + aapp [{fake-aterm->aterm {{ P }}}, n] + )) {{ forall (n: PTriple nat _ _), (PTriple P _ _) n }}, + + % Uvars are supported too. + aterm->fake-aterm Uvar T, + var T, + % and if the uvar is assigned, the evar should be assigned too. + Uvar = (asort (typ _) (pc map4 map3)), + not (var T), + T = {{ PType map4 map3 }} +]. + +main _ :- + test-fake-map-class->map-class, + test-map-class->fake-map-class, + test-fake-aterm->aterm, + test-aterm->fake-aterm. + +}}. + +Elpi Test. \ No newline at end of file diff --git a/tests/elpi/uvar_to_evar.v b/tests/elpi/uvar_to_evar.v new file mode 100644 index 0000000..3875e95 --- /dev/null +++ b/tests/elpi/uvar_to_evar.v @@ -0,0 +1,45 @@ +(*****************************************************************************) +(* * Trocq *) +(* _______ * Copyright (C) 2023 Inria & MERCE *) +(* |__ __| * (Mitsubishi Electric R&D Centre Europe) *) +(* | |_ __ ___ ___ __ _ * Cyril Cohen *) +(* | | '__/ _ \ / __/ _` | * Enzo Crance *) +(* | | | | (_) | (_| (_| | * Assia Mahboubi *) +(* |_|_| \___/ \___\__, | ************************************************) +(* | | * This file is distributed under the terms of *) +(* |_| * GNU Lesser General Public License Version 3 *) +(* * see LICENSE file for the text of the license *) +(*****************************************************************************) + +From elpi Require Import elpi. +From Trocq Require Import Trocq. +From Trocq.Elpi Extra Dependency "util-rocq.elpi" as util_rocq. + +Elpi Command Test. +Elpi Accumulate File util_rocq. +Elpi Accumulate lp:{{ + +main _ :- std.spy-do! [ + util.uvar-to-evar UVar1 EVar1_, + var EVar1_, + util.uvar-to-evar UVar1 EVar1', + var EVar1', + % When called on the same uvar, the same Rocq evar is returned + same_term EVar1_ EVar1', + + util.uvar-to-evar UVar2_ EVar2_, + var EVar2_, + % But when called on a different uvar, a different Rocq evar is returned + not (same_term EVar1_ EVar2_), + + % Assigning to a uvar should not assign the evar + UVar1 = 2, + var Evar1_, + + % Calling uvar-to-evar on something else than a uvar raises an error + do-not-fail => not (util.uvar-to-evar 2 Evar3_), +]. + +}}. + +Elpi Test. \ No newline at end of file