Skip to content
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

feat: Add bb and bb_runtime output options #3700

Merged
29 changes: 25 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,16 +280,35 @@ def ir_compiler(ir, *args, **kwargs):
return ir_compiler


def _get_output_formats(experimental_codegen):
"""
Returns a list of output formats supported. If not running the experimental
codegen path, the bb and bb_runtime formats are removed.
"""
output_formats = list(compiler.OUTPUT_FORMATS.keys())
if experimental_codegen is False:
harkal marked this conversation as resolved.
Show resolved Hide resolved
output_formats.remove("bb")
output_formats.remove("bb_runtime")
return output_formats


def _get_contract(
w3, source_code, optimize, *args, override_opt_level=None, input_bundle=None, **kwargs
w3,
source_code,
optimize,
*args,
override_opt_level=None,
input_bundle=None,
experimental_codegen=False,
**kwargs,
):
settings = Settings()
settings.evm_version = kwargs.pop("evm_version", None)
settings.optimize = override_opt_level or optimize
out = compiler.compile_code(
source_code,
# test that all output formats can get generated
output_formats=list(compiler.OUTPUT_FORMATS.keys()),
output_formats=_get_output_formats(experimental_codegen),
settings=settings,
input_bundle=input_bundle,
show_gas_estimates=True, # Enable gas estimates for testing
Expand Down Expand Up @@ -355,13 +374,15 @@ def get_contract_module(source_code, *args, **kwargs):
return get_contract_module


def _deploy_blueprint_for(w3, source_code, optimize, initcode_prefix=b"", **kwargs):
def _deploy_blueprint_for(
w3, source_code, optimize, initcode_prefix=b"", experimental_codegen=False, **kwargs
):
settings = Settings()
settings.evm_version = kwargs.pop("evm_version", None)
settings.optimize = optimize
out = compiler.compile_code(
source_code,
output_formats=list(compiler.OUTPUT_FORMATS.keys()),
output_formats=_get_output_formats(experimental_codegen),
settings=settings,
show_gas_estimates=True, # Enable gas estimates for testing
)
Expand Down
20 changes: 17 additions & 3 deletions tests/unit/cli/vyper_json/test_compile_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,32 @@ def test_keyerror_becomes_jsonerror(input_json):

def test_compile_json(input_json, input_bundle):
foo_input = input_bundle.load_file("contracts/foo.vy")
# remove bb and bb_runtime from output formats
# because they require venom (experimental)
output_formats = OUTPUT_FORMATS.copy()
del output_formats["bb"]
del output_formats["bb_runtime"]
foo = compile_from_file_input(
foo_input, output_formats=OUTPUT_FORMATS, input_bundle=input_bundle
foo_input,
output_formats=output_formats,
input_bundle=input_bundle,
experimental_codegen=False,
)

library_input = input_bundle.load_file("contracts/library.vy")
library = compile_from_file_input(
library_input, output_formats=OUTPUT_FORMATS, input_bundle=input_bundle
library_input,
output_formats=output_formats,
input_bundle=input_bundle,
experimental_codegen=False,
)

bar_input = input_bundle.load_file("contracts/bar.vy")
bar = compile_from_file_input(
bar_input, output_formats=OUTPUT_FORMATS, input_bundle=input_bundle
bar_input,
output_formats=output_formats,
input_bundle=input_bundle,
experimental_codegen=False,
)

compile_code_results = {
Expand Down
6 changes: 6 additions & 0 deletions vyper/compiler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
# requires ir_node
"external_interface": output.build_external_interface_output,
"interface": output.build_interface_output,
"bb": output.build_bb_output,
"bb_runtime": output.build_bb_runtime_output,
"ir": output.build_ir_output,
"ir_runtime": output.build_ir_runtime_output,
"ir_dict": output.build_ir_dict_output,
Expand Down Expand Up @@ -55,6 +57,7 @@ def compile_from_file_input(
no_bytecode_metadata: bool = False,
show_gas_estimates: bool = False,
exc_handler: Optional[Callable] = None,
experimental_codegen: bool = False,
) -> dict:
"""
Main entry point into the compiler.
Expand Down Expand Up @@ -84,6 +87,8 @@ def compile_from_file_input(
two arguments - the name of the contract, and the exception that was raised
no_bytecode_metadata: bool, optional
Do not add metadata to bytecode. Defaults to False
experimental_codegen: bool
Use experimental codegen. Defaults to False

Returns
-------
Expand All @@ -108,6 +113,7 @@ def compile_from_file_input(
storage_layout_override,
show_gas_estimates,
no_bytecode_metadata,
experimental_codegen,
)

ret = {}
Expand Down
10 changes: 10 additions & 0 deletions vyper/compiler/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ def build_interface_output(compiler_data: CompilerData) -> str:
return out


def build_bb_output(compiler_data: CompilerData) -> IRnode:
compiler_data.experimental_codegen = True
harkal marked this conversation as resolved.
Show resolved Hide resolved
return compiler_data.venom_functions[0]


def build_bb_runtime_output(compiler_data: CompilerData) -> IRnode:
compiler_data.experimental_codegen = True
return compiler_data.venom_functions[1]


def build_ir_output(compiler_data: CompilerData) -> IRnode:
if compiler_data.show_gas_estimates:
IRnode.repr_show_gas = True
Expand Down
2 changes: 2 additions & 0 deletions vyper/compiler/phases.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def __init__(
storage_layout: StorageLayout = None,
show_gas_estimates: bool = False,
no_bytecode_metadata: bool = False,
experimental_codegen: bool = False,
harkal marked this conversation as resolved.
Show resolved Hide resolved
) -> None:
"""
Initialization method.
Expand Down Expand Up @@ -112,6 +113,7 @@ def __init__(
self.no_bytecode_metadata = no_bytecode_metadata
self.settings = settings or Settings()
self.input_bundle = input_bundle or FilesystemInputBundle([Path(".")])
self.experimental_codegen = experimental_codegen

_ = self._generate_ast # force settings to be calculated

Expand Down
Loading