- Notifications
You must be signed in to change notification settings - Fork79
Imports and exports#949
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
As we have discussed, in the recent implementation of |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 9 comments 16 replies
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Use case 1. module A{ var x: intaction aInit= x'=0action aStep= x'= x+1}module B{importA.*action bInit= aInit// x is visible in bStepaction bStep= all{ x>=0, aStep}}// C can be the internal module constructed by REPLmodule C{importB.*action cInit= bInitaction cStep= bStep// aInit, aStep, and x are not visible in C} The expectation. The module The VSCode is OK ✅ REPL ✅: $ quint repl-r t.qnt::C Quint REPL0.11.1Type".exit" to exit,or".help"for more information>>> cInittrue>>> cSteptrue>>> The simulator ✅: $ quint run --main=C --init=cInit --step=cStep t.qnt The transpiler ✅: $ quint verify --main=C --init=cInit --step=cStep t.qnt |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Use case 2. module A{ var x: intaction aInit= x'=0action aStep= x'= x+1}module B{importA as A2exportA2.*action bInit= A2::aInit// x is visible in bStepaction bStep= all{ A2::x>=0, A2::aStep}}// C can be the internal module constructed by REPLmodule C{importB.*action cInit= bInitaction cStep= bStep// aInit, aStep, and x are visible in Caction cInit2= aInitaction cStep2= all{ x>=0, aStep}} The expectation. This does not work in VSCode ❌ This does not work in REPL ❌ $ quint repl-r t.qnt::C Quint REPL0.11.2Type".exit" to exit,or".help"for more informationsyntax error: error: Failed to resolve name aInit in definitionfor cInit2, inmodule Caction cInit2= aInit^^^^^ This does not work in the simulator ❌ $ quint run--main=C--init=cInit--step=cStep t.qnt .../quint/t.qnt:24:19- error: Failed to resolve name aInit in definitionfor cInit2, inmodule C24:action cInit2= aInit^^^^^ This does not work in the transpiler ❌ $ quint verify--main=C--init=cInit--step=cStep t.qnt.../quint/t.qnt:24:19- error: Failed to resolve name aInit in definitionfor cInit2, inmodule C24:action cInit2= aInit^^^^^ |
BetaWas this translation helpful?Give feedback.
All reactions
-
@bugarela, do we expect this spec to work? |
BetaWas this translation helpful?Give feedback.
All reactions
-
Yes. I couldn't find any obvious issue, I'd have to debug it to understand why it is not working. |
BetaWas this translation helpful?Give feedback.
All reactions
-
This was a small bug in the name collector, where I was not saving the table for A2 (only with instances, not for imports). I fixed it locally and this example works on all commands. |
BetaWas this translation helpful?Give feedback.
All reactions
🚀 1
-
Here it is#1030 |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Use case 3. The third use case using a single instance. module A{ const N: int var x: intaction aInit= x'=0action aStep= x'= x+ N}module B{importA(N=2) as A2exportA2.*action bInit= A2::aInit// x is visible in bStepaction bStep= all{ A2::x>=0, A2::aStep}}// C can be the internal module constructed by REPLmodule C{importB.*action cInit= bInitaction cStep= bStep// aInit, aStep, and x are visible in Caction cInit2= aInitaction cStep2= all{ x>=0, aStep}} The expectation. This does work in VSCode ✅ REPL is quite confused here ❌ $ quint repl-r t.qnt::C Quint REPL0.11.2Type".exit" to exit,or".help"for more information>>> cInittrue[warning] some variables are undefined: x>>> cSteptrue[warning] some variables are undefined: x>>> A::xsyntax error: error: Failed to resolve name A::x in definitionfor q::input, inmodule __repl__A::x^^^^>>> xruntime error: error: Variable x isnot set var x: int^^^^^^^^^^<undefined value> This works in the simulator, though it uses the variable
The Apalache transpiler is confused ❌ $ quint verify --main=C --init=cInit --step=cStep t.qnterror: Assignment error: No assignments found for: x |
BetaWas this translation helpful?Give feedback.
All reactions
-
The REPL is confused because it doesn't know that both It works in the simulator since |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Use case 4. For some reason it works, though it works somewhat unexpected. module A{ const N: int var x: intaction aInit= x'=0action aStep= x'= x+ N}module B{importA(N=2).*action bInit= aInit// x is visible in bStepaction bStep= all{ x>=0, aStep}} The expectation. This works in VSCode ✅ This works in REPL but it may be confusing 🪲 $ quint repl-r t.qnt::BQuint REPL0.11.2Type".exit" to exit,or".help"for more information>>> bInittrue>>> bSteptrue>>> x2 Although it works in REPL, I did not expect it. Apparently, when we instantiate a module, it is exported automatically. I think this is where we have got confused: Normal imports do not export names, whereas instances export names. What makes it worse, when I import the module $ quint replQuint REPL0.11.2Type".exit" to exit,or".help"for more information>>>import B.* from"./t"syntax error: error:[QNT404]Module Bnot foundimportB.* from"./t"^^^^^^^^^^^^^^^^^^^^^>>> It works in the simulator as expected ✅ $ quint run--main=B--init=bInit--step=bStep t.qntAn example execution:[State0] {x:0}... It works in the transpiler as expected ✅ $ quint verify--main=B--init=bInit--step=bStep t.qnt |
BetaWas this translation helpful?Give feedback.
All reactions
-
I'm pretty sure that's an unrelated bug |
BetaWas this translation helpful?Give feedback.
All reactions
-
As for why I fixed it by keeping the original unflattened modules in the compilation state, and then using that to resolve names. This way, an error is flagged when we type
|
BetaWas this translation helpful?Give feedback.
All reactions
-
Fix is here:#1031 |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Use case 5. module A{ const N: int var x: intaction aInit= x'=0action aStep= x'= x+ N}module B{importA(N=2) as A2importA(N=3) as A3action bInit= all{ A2::aInit, A3::bInit}action bStep= all{ A2::aStep, A3::bStep}} The expectation. The VSCode is not working ❌ REPL is not working ❌ $ quint repl-r t.qnt::B Quint REPL0.11.2Type".exit" to exit,or".help"for more informationsyntax error: error: Failed to resolve name A3::bInit in definitionfor bInit, inmodule Baction bInit= all{ A2::aInit, A3::bInit}^^^^^^^^^ The simulator is not working ❌ $ quint run--main=B--init=bInit--step=bStep t.qnt.../quint/t.qnt:13:35- error: Failed to resolve name A3::bInit in definitionfor bInit, inmodule B13:action bInit= all{ A2::aInit, A3::bInit} The transpiler is not working ❌ $ quint verify--main=B--init=bInit--step=bStep t.qnt.../quint/t.qnt:13:35- error: Failed to resolve name A3::bInit in definitionfor bInit, inmodule B13:action bInit= all{ A2::aInit, A3::bInit} |
BetaWas this translation helpful?Give feedback.
All reactions
-
I think you meant |
BetaWas this translation helpful?Give feedback.
All reactions
-
Indeed, there was a typo. Here is the revised version, which is failing in the effect checker. module A{ const N: int var x: intaction aInit= x'=0action aStep= x'= x+ N}module B{importA(N=2) as A2importA(N=3) as A3action bInit= all{ A2::aInit, A3::aInit}action bStep= all{ A2::aStep, A3::aStep}} |
BetaWas this translation helpful?Give feedback.
All reactions
-
#1290 fixes this |
BetaWas this translation helpful?Give feedback.
All reactions
-
Use case 6. Exporting all the names from the namespace. Consider the following example: module A{ const N: int var x: intaction aInit= x'=0action aStep= x'= x+ N}module B{importA.* export*action bInit= A2::aInit// x is visible in bStepaction bStep= all{ A2::x>=0, A2::aStep}}// C can be the internal module constructed by REPLmodule C{importB(N=2).* export*action cInit= bInitaction cStep= bStep// aInit, aStep, and x are visible in Caction cInit2= aInitaction cStep2= all{ x>=0, aStep}} Expected behavior.All names of Currently, we do not have syntax for that. However, it should be really easy to introduce |
BetaWas this translation helpful?Give feedback.
All reactions
-
@bugarela wdyt? It looks like |
BetaWas this translation helpful?Give feedback.
All reactions
-
Seems like a good idea! Easy to use and easy to implement :) |
BetaWas this translation helpful?Give feedback.
All reactions
-
Use case 7. Importing and exporting names across files. Consider the following three module definitions scattered across three files: File module A{ const N: int var x: intaction aInit= x'=0action aStep= x'= x+ N} File module B{importA as A2 from"./A"exportA2.*action bInit= A2::aInit// x is visible in bStepaction bStep= all{ A2::x>=0, A2::aStep}} File module C{importB(N=2) as B2 from"./B"exportB2.*action cInit= bInitaction cStep= bStep// aInit, aStep, and x are visible in Caction cInit2= aInitaction cStep2= all{ x>=0, aStep}} Expected behavior. Module Current behavior. The parser does not accept $ quint parse B.qnt.../B.qnt:3:3 - error: [QNT405] Module'A2' not found3:export A2.* ^^^^^^^^^^^error: parsing failed $ quint parse C.qnt.../B.qnt:3:3 - error: [QNT405] Module'A2' not found3:export B2.* ^^^^^^^^^^^.../C.qnt:2:3 - error: [QNT406] Instantiation error:'N' not foundin'B'2: import B(N = 2) as B2 from"./B" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^.../C.qnt:2:12 - error: [QNT404] Name'B2::N' not found2: import B(N = 2) as B2 from"./B" ^.../C.qnt:8:19 - error: [QNT404] Name'aInit' not found8: action cInit2 = aInit ^^^^^.../C.qnt:9:25 - error: [QNT404] Name'x' not found9: action cStep2 = all { x>= 0, aStep } ^.../C.qnt:9:33 - error: [QNT404] Name'aStep' not found9: action cStep2 = all { x>= 0, aStep } ^^^^^error: parsing failed |
BetaWas this translation helpful?Give feedback.
All reactions
-
This is the same problem of#949 (reply in thread). My fix for that also fixes this. |
BetaWas this translation helpful?Give feedback.
All reactions
-
After meeting about this subject twice this week, here's what we believe we should do:
With this, we should end up with the following semantics: Imports: |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
Thanks for the writeup! A few notes:
All the rest sounds great to me! 🎉 |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
But replacing |
BetaWas this translation helpful?Give feedback.
All reactions
-
Given moduleA { constX: intvalf=X}moduleB {importA.fvalg= f}moduleC {importBvalh=B::g}moduleD {importC.hvali= h}
However, loading the modules in the repl, we find that modules B, C, and D are
However, if we use the
As I understand things, modules that declare constants are parametric. We should
In short: our modules have types. They are either non-parametric modules of type
|
BetaWas this translation helpful?Give feedback.