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

refactor: internal handling of imports #3655

Merged
merged 63 commits into from
Nov 6, 2023

Conversation

charles-cooper
Copy link
Member

@charles-cooper charles-cooper commented Oct 20, 2023

What I did

How I did it

How to verify it

Commit message

this commit refactors how imports are handled internally.

historically, vyper handled imports by using a preprocessing step
(`extract_file_interface_imports`) which resolved imports to files and
provided them to the compiler pipeline as pure inputs. however, this
causes problems once the module system gets more complicated:
- it mixes passes. resolving imports and loading the files should
  essentially be resolved during analysis, but instead they are being
  resolved before the compiler is even entered into(!)
- it produces slightly different code paths into the main compiler entry
  point which introduces subtle bugs over time from scaffolding
  differences
- relatedly, each entry point into the compiler has to maintain its own
  mechanism for resolving different kinds of inputs to the compiler
  (JSON interfaces vs .vy files at the moment).

this commit replaces the external scaffolding with an "InputBundle"
abstraction which essentially models how the compiler interacts with its
inputs (depending on whether it is using the filesystem or JSON inputs).
this makes the entry points to the compiler overall simpler, and have
more consistent behavior.

this commit also:
- changes builtin interfaces so they are represented in the codebase as
  `.vy` files which are imported similarly to how regular (non-builtin)
  files are imported
- simplifies the `compile_files` and `compile_json` pipelines
- removes the `compile_codes` API, which was not actually more useful
  than the `compile_code` API (which is kept).
- cleans up tests by introducing a `make_file` and `make_input_bundle`
  abstraction
- simplifies and merges several files in the tests/cli/ directories
- adds a test for multiple output selections in the standard json pipeline

Description for the changelog

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

vyper/compiler/input_bundle.py Fixed Show fixed Hide fixed
vyper/compiler/input_bundle.py Fixed Show fixed Hide fixed
vyper/semantics/analysis/module.py Fixed Show fixed Hide fixed
vyper/compiler/phases.py Fixed Show fixed Hide fixed
vyper/semantics/analysis/module.py Fixed Show fixed Hide fixed
vyper/semantics/analysis/module.py Fixed Show fixed Hide fixed
vyper/semantics/analysis/module.py Fixed Show fixed Hide fixed
vyper/semantics/analysis/module.py Fixed Show fixed Hide fixed
vyper/compiler/input_bundle.py Outdated Show resolved Hide resolved
vyper/compiler/input_bundle.py Show resolved Hide resolved
vyper/compiler/input_bundle.py Outdated Show resolved Hide resolved
vyper/compiler/input_bundle.py Fixed Show fixed Hide fixed
vyper/compiler/input_bundle.py Fixed Show resolved Hide resolved
vyper/cli/vyper_json.py Fixed Show fixed Hide fixed
@charles-cooper charles-cooper marked this pull request as ready for review November 5, 2023 21:44
@charles-cooper charles-cooper changed the title [wip] refactor import system feat: refactor import system Nov 5, 2023
@codecov-commenter
Copy link

codecov-commenter commented Nov 6, 2023

Codecov Report

Merging #3655 (42ea90f) into master (ed0b1e0) will increase coverage by 0.35%.
Report is 3 commits behind head on master.
The diff coverage is 87.93%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

@@            Coverage Diff             @@
##           master    #3655      +/-   ##
==========================================
+ Coverage   89.14%   89.50%   +0.35%     
==========================================
  Files          85       80       -5     
  Lines       11364    11342      -22     
  Branches     2585     2553      -32     
==========================================
+ Hits        10131    10152      +21     
+ Misses        822      797      -25     
+ Partials      411      393      -18     
Files Coverage Δ
vyper/__init__.py 58.82% <100.00%> (ø)
vyper/compiler/output.py 91.62% <100.00%> (-0.05%) ⬇️
vyper/semantics/analysis/__init__.py 100.00% <100.00%> (ø)
vyper/typing.py 100.00% <ø> (ø)
vyper/cli/vyper_serve.py 0.00% <0.00%> (ø)
vyper/compiler/phases.py 92.64% <76.92%> (-0.43%) ⬇️
vyper/compiler/__init__.py 87.50% <80.95%> (-1.39%) ⬇️
vyper/compiler/input_bundle.py 95.78% <95.78%> (ø)
vyper/cli/vyper_compile.py 60.97% <66.66%> (-2.61%) ⬇️
vyper/semantics/analysis/module.py 92.37% <89.23%> (+2.42%) ⬆️
... and 1 more

📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today!

@charles-cooper charles-cooper changed the title feat: refactor import system refactor: internal handling of imports Nov 6, 2023
@charles-cooper charles-cooper enabled auto-merge (squash) November 6, 2023 20:32
@charles-cooper charles-cooper merged commit 5d10ea0 into vyperlang:master Nov 6, 2023
82 of 83 checks passed
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.

None yet

3 participants