Replies: 1 comment 1 reply
|
This is a much better proposal for exposing ledger vars assuming it's technically feasible. Opt-in > auto export. Another interesting thing to consider is should explicit visibility be enforced by the compiler to avoid surprises? Or should it default to private like it does now? I assume from this proposal you think it should be enforced |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I want to clarify my position on the compiler exporting ledger state and circuit visibility.
I agree with Andrew’s concern about automatically exporting. However, the current system is still not ergonomic: when building a top-level Compact contract, you must manually re-export every
export ledger STATE(sometimes also re-export circuits) from all imported modules. In a large project this becomes error-prone, and the only negative effect is on the generated TypeScript representation of the top-level contract — not on the actual contract logic.Three Visibility Cases (Ledger + Circuits)
Compact today conceptually mirrors Solidity, but the semantics end up being blurred because
exportis overloaded. Here are the three real visibility cases:1. Private Visibility (Solidity →
private)These members live only inside the module that defines them. They cannot be imported by other modules, and the compiler does not include them in TS artifacts.
2. Internal / Public Visibility (Solidity →
internal,public)These members can be imported into other modules. But here’s the confusing part:
Even if module
Mdeclares them withexport, the compiler does not emit them into the final TS representation unless the top-level module re-exports them manually.Example
Now in the top-level:
Compiler behavior:
Only exported items from the top-level are represented in TS.
So even though M exported two items, they are invisible unless re-exported manually:
This mixing of visibility ("internal" vs "public") with explicit re-exporting is what makes things verbose and confusing in large project structures.
Suggestion: Replace
exportWith Explicit Visibility KeywordsInstead of overloading
export, we could adopt explicit visibility modifiers similar to Solidity:privateinternalpublicRewriting the examples using these keywords:
And the top-level contract:
Expected Compiler Behavior
Now the compiler can automatically generate the correct TS representation for top-level contract on example
7without requiring manual re-exports:This provides:
export { M_something }patternsOverall, explicit visibility modifiers would significantly simplify large-scale Compact projects.
All reactions