Replies: 6 comments 3 replies
-
by |
Beta Was this translation helpful? Give feedback.
-
Are there any non-contrived programs or data structures that we need to write in Clarity that cannot be built with the extension contract method? I can't think of any new types we need to introduce. The only "specially-typed function" I can think of that we would really like to have is a These could all be implemented as an extension contract. Callers would just use the smallest The reason I bring this up is because I suspect the pragma approach is going to have lots of tiny gotchas in it. You'll basically be peppering the whole VM with a bunch of By contrast, the code I've written that replaces function bodies with native code was surprisingly simple, once I was familiarized enough with the codebase. The only gating logic that has to occur at all is the instantiation of the extension contracts; once they exist, the function |
Beta Was this translation helpful? Give feedback.
-
Two things:
|
Beta Was this translation helpful? Give feedback.
-
Relevant at-block example
|
Beta Was this translation helpful? Give feedback.
-
If we go the route of using Clarity versioning instead of extension contracts, then what does it mean for extensions to |
Beta Was this translation helpful? Give feedback.
-
Just an update on this: the decision we've landed on is to implement new Clarity keywords natively, and implement a Clarity contract versioning scheme and pragma keyword whereby new keywords will only be available to versions of Clarity in which they are supported. Moreover, the Clarity VM version will be fixed in the global context and unchangeable throughout the contract or contract-call execution -- calls to Extension contracts will not be used, since they are not needed. |
Beta Was this translation helpful? Give feedback.
-
In Stacks 2.1, we want to implement new native functionality for Clarity. However, implementing this new functionality requires new reserved words. This is problematic, because adding reserved words is not a backwards-compatible change. There’s potentially two ways to deal with this:
Advantages / Disadvantages
The pragma approach is more simple for developers and provides greater extensibility: it could be used in the future to add new types, etc. The disadvantage of the pragma approach is that it will require the interpreter and analysis passes to operate “context-aware”, which is a greater maintenance burden long term.
Contract-call interposition and “extension contracts” are more limited: they cannot introduce new types or new “specialy-typed functions”, rather they must have the same semantics as contract-calls, but they can be implemented without the VM or the analysis passes being context-aware.
To me, it seems like the "pragma approach" would be better: it provides a better experience for developers and is more extensible for the future. The downside is it is probably harder to implement and maybe harder to test, though both approaches require the same kind of testing described below. I'd be hard pressed to estimate how difficult the pragma approach would be to implement.
Implementing via Contract-Call Interposition
In order to implement Clarity extensions via a contract-call, a few things must happen.
contract-call
that checks whether or not the called contract is an extension contract. If it is, is checks whether the function name is an extension function, and then executes the corresponding “native” implementation, rather than the normal contract-call implementation.Desugaring Pass
One nice-to-have feature would make this less hostile of an interface for developers: extension desugaring: essentially, a contract author could write
In their contracts, and a desugaring pass would rewrite the contract to
Implementing via Context-Aware VM
In order to implement these extensions via a context-aware VM and analysis passes (i.e., option 1 above), the ContractContext struct in the VM would need to track the current Clarity version. When a contract-call occurs to a contract, the Clarity version would switch to the called contract’s version.
The analysis passes would also need to be context-aware, however, this is slightly easier than the runtime contexts: the analysis passes do not “cross” contract boundaries: they simply fetch the already computed analysis for a given contract (which would never change).
Testing Clarity Extensions
All new Clarity extensions must be tested across the 2.0/2.1 epoch boundary.
This means that for a new function:
(at-block …)
expressions that cross the 2.0/2.1 boundary should work(at-block ..)
expression that tries to use one of the new functions in the past should yield an error.(at-block …)
expression should still be able to use one of the new functionsBeta Was this translation helpful? Give feedback.
All reactions