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

LFVM: Refactor interpreter Configuration, test registration of experimental and default features. #868

Closed
wants to merge 2 commits into from

Conversation

LuisPH3
Copy link
Contributor

@LuisPH3 LuisPH3 commented Oct 14, 2024

part of #684

This PR refactors lfvm.go to clean up the public interface of the lfvm package

There were three different configuration structs found, in the package, in the interpreter and in the step function. The three objects have been merged into 2 objects:

  • configuration is an opaque object that allows configuring the interpreter. Because the default value may not suffice, a function DefaultConfiguration is created with the features planned for the release.
  • configurationOverrides is a key-value map that can set a subset of configuration flags, final set of configs is TBD.

The public interface of LFVM is:

  • type Configuration
    • Constructor DefaultConfiguration is the sanctioned features for the release.
    • type ConfigurationOverrides is created because the unused any type passed to the factory, this type can be rewritten in any way.
  • Interpreter is the old lfvm instance. It is public to allow tests to query configuration parameters from outside the package.
    • NewInterpreter is the only constructor
  • additionally. The default configured lfvm instance is pushed into the global registry.
  • RegisterExperimentalInterpreterConfigurations can be called to register more configurations

To prevent polluting the registry during testing, registry tests use the lfvm_test package.

@LuisPH3 LuisPH3 force-pushed the luis/lfvm_test_register_experimental branch 2 times, most recently from 08844a2 to 7743183 Compare October 14, 2024 15:20
@LuisPH3 LuisPH3 marked this pull request as ready for review October 14, 2024 15:20
Copy link
Contributor

@facuMH facuMH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice refactor, I have some questions though

// Converter converts EVM code to LFVM code.
type Converter struct {
// converter converts EVM code to LFVM code.
type converter struct {
config ConversionConfig
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does ConversionConfig needs to be public ?

// configuration for production purposes.
func NewInterpreter(Config) (*lfvm, error) {
return newVm(config{
// DefaultConfiguration ist the set of configuration values sanctioned for
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// DefaultConfiguration ist the set of configuration values sanctioned for
// DefaultConfiguration is the set of configuration values sanctioned for

Comment on lines 35 to 39
return Configuration{
ConversionConfig: ConversionConfig{
WithSuperInstructions: false,
SuperInstructionsEnabled: false,
},
WithShaCache: true,
})
ShaCache: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if these values are supposed to be changed by the functions below, should they not be private ?

// This test is slightly different from other tests because of dealing with the
// global registry:
// - It is declared in it's own package to avoid leaking the registration to other tests.
// - It tests different properties, in one single function. The reason is that the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// - It tests different properties, in one single function. The reason is that the
// - It tests different properties in one single function. The reason is that the

// WithSuperInstructions enables the use of super instructions.
WithSuperInstructions bool
// SuperInstructionsEnabled mark the use of super instructions.
SuperInstructionsEnabled bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what I do not like about these fields being public is that anyone can change them. Maybe they should only be changed during construction and to read them a getter should be provided ? wdyt ?

@LuisPH3 LuisPH3 force-pushed the luis/lfvm_test_register_experimental branch from 7743183 to 1065d2f Compare October 15, 2024 09:01
@LuisPH3
Copy link
Contributor Author

LuisPH3 commented Oct 15, 2024

refactor will not be done, instead the file will be tested as it is now.

@LuisPH3 LuisPH3 closed this Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants