-
-
Notifications
You must be signed in to change notification settings - Fork 812
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
VIP - define top level namespace and relegate everything else to "standard library" #1347
Comments
I like this proposal, would need a deeper investigation of what keywords we would cover under this. |
In case it isn't clear to anyone, the names I used in my example |
Would it be more explicit to force namespace importing? i.e.
I think this might be even better. |
I see I missed this VIP for this weeks' call, added to agenda for the next one ;) |
I'll try to make the meeting on the 8th so I can explain some of my thinking on this topic. |
Approved, but decisions have to be made still once implemented:
|
Suggested namespacing (note: still illegal names for variables/functions): # Environment variables
from ethereum.environment import block, chain, msg, tx
# Ethereum utility functions
from ethereum.utils import (
as_wei_value,
blockhash,
create_forwarder_to,
method_id,
raw_call,
raw_log,
selfdestruct,
)
# Built-in Constants
from vyper.constants import ZERO_ADDRESS, EMPTY_BYTES32, ... # And all the rest
# Cryptography functions
from vyper.cryptography import keccak256, sha256, ecrecover, ecadd, ecmul
# Math functions
from vyper.math import ceil, floor, sqrt, uint256_addmod, uint256_mulmod Note that the following are not namespaced: assert
concat
convert
empty
extract32
raise
send
slice |
Generally the layout you propose for |
I put them under Everything under the |
Punting on v0.2.0 milestone because the bikeshed should be purple |
as of 0.4.0 on a technical level we can do this fairly easily (see for instance that c6f457a moves builtin interfaces to pure vyper |
Simple Summary
As vyper adds new built-in functions and reserved words there will be an increased likelihood of name collision in user code. Support for namespacing new built-ins will remedy this issue by reducing the number of names in the top level namespace.
Abstract
Vyper needs some version of what python calls, the "standard library". A set of modules that are available by default for any Vyper contract to import and use, but which are not available in the global namespace by default.
Motivation
The motivation for this comes from seeing multiple VIPs that introduce new top-level namespace variables.
sqrt
funds
,credit
,debit
bigadd
,bigmul
,bigdiv
,bigmod
All of these are names that a user could have already created in their contracts. By adding these to the top level namespace, we will 1) reduce the number of available names a user may use in their contract code and 2) cause breakage in existing code that already uses one of these names.
Specification
I propose introducing an importable standard library to vyper.
Similar to python, I propose we define a
builtins
module that contains all of the functions which are available by default in the global namespace. The vyper compiler would treat every vyper file as-if it had imported all of the top-level names from thebuiltins
module.Any functions that are currently in the top level namespace which are deemed not to belong in the
builtins
should 1) be moved to an importable module and 2) be replaced by a version that behaves the same but raises deprecations warnings for some period before being removed from the global namespace.Bonus points if we could combine this with EthPM packages in some way as it would lay the foundation for installing 3rd party modules which provide fancy functions and functionality not available in the standard library.
Extra bonus points if this API allows us to leverage
DELEGATECALL
style libraries to reduce deployment costs when appropriate.Backwards Compatibility
This would be backwards incompatible with respect to any function that currently exists in the top level namespace that is deemed to not belong there, but there is a clear and simple deprecation path for these.
Dependencies
None that I know of.
Copyright
Copyright and related rights waived via CC0
The text was updated successfully, but these errors were encountered: