Git Product home page Git Product logo

coq-module-extraction-bugs's Introduction

Introduction

This repository contains a fairly minimal example of a problem I’m encountering with the Coq module system with ocaml extraction.

The code I have works in Coq, but upon extraction I get compilation errors with ocaml like the following:

File "ml/extracted/MyModules.mli", lines 243-244, characters 8-41:
243 | ........type value_byte = MEM'.Byte.value_byte =
244 |         | ExtractByte of LP.V.value * nat
Error: This variant or record definition does not match that of type
         MEM'.Byte.value_byte
       Constructors do not match:
         ExtractByte of LP'.V.value * Datatypes.nat
       is not the same as:
         ExtractByte of LP.V.value * Datatypes.nat
       The type LP'.V.value is not equal to the type LP.V.value

Building

Should be able to just:

cd src
make extracted

To see the error. There are no dependencies beyond Coq and coq_makefile.

If you use nix, this project has a flake that you can use to get the same versions of Coq as me (8.16). Running nix build -L . should try to build the project and give you a build log.

Some more background

The issue seems to arise because of the Module Language := Make_Lang LP MEM line in InterpreterStack_common. It seems like the mixture of having a module like Byte in the Module Type Memory and the Declare Module MEM : Memory LP results in an incorrect module interface getting extracted. The ocaml .mli file has this:

module Make_InterpreterStack :
 functor (LP':LanguageParams) ->
 functor (MEM':sig
  module Byte :
   sig
    type value_byte =
    | ExtractByte of LP'.V.value * nat

    val value_byte_rect : (LP'.V.value -> nat -> 'a1) -> value_byte -> 'a1

    val value_byte_rec : (LP'.V.value -> nat -> 'a1) -> value_byte -> 'a1
   end
 end) ->
 sig
  module LP :
   LanguageParams

  module MEM :
   sig
    module Byte :
     sig
      type value_byte = MEM'.Byte.value_byte =
      | ExtractByte of LP'.V.value * nat

      val value_byte_rect : (LP'.V.value -> nat -> 'a1) -> value_byte -> 'a1

      val value_byte_rec : (LP'.V.value -> nat -> 'a1) -> value_byte -> 'a1
     end
   end

  module Language :
   sig
    module MEM :
     sig
      module Byte :
       sig
        type value_byte = MEM'.Byte.value_byte =
        | ExtractByte of LP.V.value * nat

        val value_byte_rect : (LP.V.value -> nat -> 'a1) -> value_byte -> 'a1

        val value_byte_rec : (LP.V.value -> nat -> 'a1) -> value_byte -> 'a1
       end
     end
   end
 end

And the problem seems to be that the Language module ends up using LP.V.value from the LP module declared here:

Module Type InterpreterStack.
  Declare Module LP : LanguageParams.
  Declare Module MEM : Memory LP.
  Include InterpreterStack_common LP MEM.
End InterpreterStack.

But it doesn’t know that this LP = LP'. Coq itself seems to be okay with this arrangement of modules, but it doesn’t work when extracted.

Interestingly the MEM module seems to use LP'.V.value directly… I guess that might be because it gets defined using with Module MEM := MEM'. Thus must act differently behind the scenes?

coq-module-extraction-bugs's People

Contributors

chobbes avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.