Sketch of a subtype judgment on contract specs #747
+372
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a sketch of a subtype relationship on soroban contract specs. The idea here is to support the host function that updates / overwrites contracts with a judgment it can make that a new contract is compatible with the spec (type signature) of an old contract, such that anyone using the old contract will continue to be able to use the new contract.
Of course it's just "spec-level" compatibility, not like "does the contract do the same thing" -- we can't judge that -- but I think it'll prevent a fairly wide class of upgrade mistakes if we can at least catch spec mismatches.
The subtyping relationship here is intended to be extremely textbook and hopefully corresponds to the same rules (covariant returns, contravariant arguments, record extensions, union restrictions) you'll find in any standard treatment of immutable structural types and functions.
We haven't 100% decided we're going to do this yet, I don't think, but I suspect something like this (possibly strengthened or weakened somewhat) will prevent a lot of errors, and I wanted to sketch it out as part of discussing the lifecycle, evolution and versioning of contracts in the field (eg. as part of stellar/rs-soroban-sdk#1095 though that bug somewhat mixes up issues of contract compatibility and SDK compatibility, I think the spec mechanism is likely to be at least part of how we express SDK versioning anyways)
cc @sisuresh, @MonsieurNicolas, @dmkozh and @leighmcculloch