Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rearranging modules in the Tendermint spec #1023

Merged
merged 11 commits into from
Aug 28, 2023
Merged

Conversation

konnov
Copy link
Contributor

@konnov konnov commented Jul 7, 2023

Refactoring the Tendermint spec a bit. Imports and exports do not seem to work as expected.

Update: imports and exports work with the new flattening, so we're finally opening this PR

@konnov konnov changed the title Igor/tendermint imports Rearranging modules in the Tendermint spec Jul 7, 2023
@konnov
Copy link
Contributor Author

konnov commented Jul 7, 2023

Not sure why export does not work in TendermintTest. @bugarela, could you have a look?

@bugarela
Copy link
Collaborator

bugarela commented Jul 7, 2023

Not sure why export does not work in TendermintTest. @bugarela, could you have a look?

Probably because of this: #949 (reply in thread)

I'll try it with my local change and see if it fixes the problem

@bugarela
Copy link
Collaborator

bugarela commented Jul 7, 2023

Unrelated: I'm not getting syntax hightlightning in the added files. Seems like our global config mapping .qnt -> Bluspec is not working 😢

@bugarela
Copy link
Collaborator

bugarela commented Jul 7, 2023

My fix makes it so typecheck succeeds, but I still couldn't run the tests. Running quint run TendermintModels.qnt --init=n4_f1::Init --step=n4_f1::Next gives me some weird errors about constants not being found. Looking into that!

@bugarela
Copy link
Collaborator

bugarela commented Jul 7, 2023

Ok, I found the problem but don't know the fix won't be super easy.

The problem here is with flattening and constants. In TendermintTest, each constant is present with two names, i.e. Corr exists as both Corr and TM::Corr. Since flattening doesn't care about visibility (as any visibility issues should be flagged before hand by the name resolver), it copies all of definitions from TendermintTest to TendermintModels, under each namespace.

So it is copying n4_f1::Corr and n4_f1::TM::Corr. Overriding constants only overrides the first one (since we are not doing TendermintTest(Corr = 1, TM::Corr = 1), which of course we shouldn't have to), and therefore the constant n4_f1::TM::Corr is left without a value, which results in an error in the compiler since it expects all constants to be defined.

I'll probably need to implement some visibility sensitiveness in the flattener as well. The other option is implementing the new flattener I mentioned in the beginning of the week, which will only flatten actually used definitions - that should fix the problem because, if the name resolver passed, then no TM:: names are ever used. I'll explore these solutions.

@konnov
Copy link
Contributor Author

konnov commented Jul 7, 2023

The problem here is with flattening and constants. In TendermintTest, each constant is present with two names, i.e. Corr exists as both Corr and TM::Corr. Since flattening doesn't care about visibility (as any visibility issues should be flagged before hand by the name resolver), it copies all of definitions from TendermintTest to TendermintModels, under each namespace.

As far as I understand,Corr and TM::Corr are both pointing to the same constant definition with the same id. I would expect the flattener to copy the same definition once.

By the way, I had to do import as TM just because I wanted to do export TM.*, as there is no other way of exporting all definitions. Introducing export * would solve the actual issue in this example.

@bugarela
Copy link
Collaborator

bugarela commented Jul 7, 2023

I just noticed we don't support export ... from statements. That would also serve as a workaround here: export Tendermint.* from "./Tendermint", and you don't need TM.

@bugarela
Copy link
Collaborator

@konnov I hope you don't mind, I've taken this over a bit to test it with the new flattener - and it works 😄 I just had to add some type annotations for the stuff I tried to run.

One thing that is not working is unit tests. It's the same problem I just fixed for verify: since the tests are not used (as far as the flattener knows), they are not copied to the main module and then the test runner finds no tests. I'm looking for a solution.

Copy link
Contributor Author

@konnov konnov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's really cool!

@bugarela bugarela marked this pull request as ready for review August 28, 2023 16:22
@bugarela bugarela merged commit d3c5f47 into main Aug 28, 2023
15 checks passed
@bugarela bugarela deleted the igor/tendermint-imports branch August 28, 2023 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants