-
Notifications
You must be signed in to change notification settings - Fork 9
Implement interfaceId via new type(C).publicMethods builtin
#462
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
Draft
axic
wants to merge
14
commits into
argotorg:main
Choose a base branch
from
axic:interface-id
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1393bf0
Add `type(C).publicMethods` primitive and interface-id computation
claude 46544df
Fix interfaceid example: construct uint256(0) instead of bare literal
claude 46deaec
Use concrete SelectorArray instead of generic DynArray for publicMethods
claude 207c75d
Simplify test
axic 2f28215
Formatting
axic aa5e1b9
Align publicMethods feature with main's funIsPublic FunDef
claude 69e0a65
Redesign publicMethods as a PublicMethods type class over Proxy(Method)
claude 3ec0e10
PublicMethods: drop length, constrain head as Method(...) like compute
claude 061eb56
ContractDispatch: lift unwrapSigs/isTyped/getTy to top level
claude 1de8301
Formatting
axic 41f8b58
interfaceid: return bytes4 directly and use ^ for the selector fold
claude f2d37e6
std: add bytes4:Int and use bare integer literals for interface-id
claude 3cef997
deposit: implement supportsInterface via type(C).publicMethods
claude bc55f23
deposit: test supportsInterface against the contract's interface id
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| {-# LANGUAGE OverloadedStrings #-} | ||
|
|
||
| -- | | ||
| -- Module : Solcore.Desugarer.PublicMethods | ||
| -- Description : Implements the `type(C).publicMethods` primitive | ||
| -- | ||
| -- The parser/name-resolver turns `type(C).publicMethods` into a call to a | ||
| -- per-contract helper function (see 'publicMethodsTagName'). This pass | ||
| -- generates the body of that helper for every contract whose primitive is | ||
| -- actually used. | ||
| -- | ||
| -- The helper hands back a type-level token — @Proxy(methods)@ — describing the | ||
| -- contract's public methods as a right-nested tuple terminated by @()@: | ||
| -- | ||
| -- @Proxy((Method(...), (Method(...), ... ())))@ | ||
| -- | ||
| -- Each element carries the very same @Method(name,payability,args,rets,fn)@ | ||
| -- typing consumed by @Selector.compute@ (see @std/dispatch.solc@), so no | ||
| -- selector hashing leaks into the compiler. Walking that tuple — counting the | ||
| -- methods (@length@) and XOR-folding their selectors into an interface id — is | ||
| -- the @PublicMethods@ type class in @std/dispatch.solc@; the compiler only | ||
| -- exposes the method list, never the iteration or hashing. | ||
| -- | ||
| -- This must run BEFORE contract dispatch generation, which produces the | ||
| -- per-method @DispatchNameTy_*@ name types (and their @SigString@ instances) | ||
| -- that the method tuple refers to. | ||
| module Solcore.Desugarer.PublicMethods | ||
| ( publicMethodsDesugarer, | ||
| publicMethodsTopDecls, | ||
| ) | ||
| where | ||
|
|
||
| import Data.Generics (listify) | ||
| import Data.List (isPrefixOf) | ||
| import Solcore.Desugarer.ContractDispatch (publicMethodTypes) | ||
| import Solcore.Frontend.Syntax | ||
| import Solcore.Frontend.Syntax.NameResolution (publicMethodsTagName) | ||
| import Solcore.Primitives.Primitives (tupleTyFromList, unit) | ||
|
|
||
| publicMethodsDesugarer :: CompUnit Name -> CompUnit Name | ||
| publicMethodsDesugarer (CompUnit ims topdecls) = | ||
| CompUnit ims (publicMethodsTopDecls topdecls) | ||
|
|
||
| publicMethodsTopDecls :: [TopDecl Name] -> [TopDecl Name] | ||
| publicMethodsTopDecls topdecls = topdecls ++ helpers | ||
| where | ||
| -- every contract paired with the helper name its `publicMethods` primitive | ||
| -- would call | ||
| contractsByTag = | ||
| [(publicMethodsTagName cname, c) | TContr c@(Contract cname _ _) <- topdecls] | ||
|
|
||
| -- helper names actually referenced by a `type(C).publicMethods` call | ||
| referenced = | ||
| [fn | Call Nothing fn [] <- listify isTagCall topdecls] | ||
|
|
||
| helpers = | ||
| [ genPublicMethodsFn c | ||
| | (tag, c) <- contractsByTag, | ||
| tag `elem` referenced | ||
| ] | ||
|
|
||
| isTagCall :: Exp Name -> Bool | ||
| isTagCall (Call Nothing fn []) = isTagName fn | ||
| isTagCall _ = False | ||
|
|
||
| isTagName :: Name -> Bool | ||
| isTagName (Name s) = "$publicMethods$" `isPrefixOf` s | ||
| isTagName _ = False | ||
|
|
||
| -- | Generate the helper that yields a contract's public-method tuple as a | ||
| -- @Proxy@ type token. The tuple is right-nested and terminated by @()@ so the | ||
| -- @PublicMethods@ instances in @std/dispatch.solc@ only need a @()@ base case | ||
| -- and an @(n, m)@ recursive case (no special single-method case). | ||
| genPublicMethodsFn :: Contract Name -> TopDecl Name | ||
| genPublicMethodsFn c@(Contract cname _ _) = | ||
| TFunDef (FunDef False sig body) | ||
| where | ||
| -- the public methods, plus a `()` terminator for the tuple | ||
| methodsTuple = tupleTyFromList (publicMethodTypes c ++ [unit]) | ||
| proxyTy = TyCon "Proxy" [methodsTuple] | ||
|
|
||
| sig = | ||
| Signature | ||
| { sigVars = [], | ||
| sigContext = [], | ||
| sigName = publicMethodsTagName cname, | ||
| sigParams = [], | ||
| sigRetComptime = False, | ||
| sigReturn = Just proxyTy, | ||
| sigPayable = False | ||
| } | ||
|
|
||
| -- return Proxy : Proxy((Method(...), (Method(...), ... ()))); | ||
| body = [Return (TyExp (Con "Proxy" []) proxyTy)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this AI comment is not needed.
@mbenke did you mean this refactor?