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

fix: guard against mutating code in non-mutable functions #3555

Closed
wants to merge 8 commits into from

Conversation

tserg
Copy link
Collaborator

@tserg tserg commented Aug 7, 2023

What I did

Fix #3554.

How I did it

Move the checks from visit_Expr to visit_Call. This causes semantic analysis to leak into annotation.py, but it should be fixed later on by #3456 when annotation and validation are combined into a single pass.

How to verify it

See tests.

Commit message

fix: guard against mutating code in non-mutable functions

Description for the changelog

Guard against mutating code in non-mutable functions

Cute Animal Picture

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

@@ -76,16 +76,111 @@ def foo():
for i in range(x):
pass""",
"""
f:int128
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This test now throws for its other issue of call violation, which is checked first in visit_Expr. Hence, I removed it as there are already tests for call violation in this file.

get_possible_types_from_node,
)
from vyper.semantics.types import TYPE_T, BoolT, EnumT, EventT, SArrayT, StructT, is_type_t
from vyper.semantics.types.function import ContractFunctionT, MemberFunctionT
from vyper.semantics.types.function import ContractFunctionT, MemberFunctionT, StateMutability

Check notice

Code scanning / CodeQL

Cyclic import Note

Import of module
vyper.semantics.types.function
begins an import cycle.
@codecov-commenter
Copy link

codecov-commenter commented Aug 7, 2023

Codecov Report

Merging #3555 (65b5384) into master (cc2a5cd) will decrease coverage by 0.02%.
Report is 2 commits behind head on master.
The diff coverage is 95.83%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##           master    #3555      +/-   ##
==========================================
- Coverage   89.14%   89.13%   -0.02%     
==========================================
  Files          85       85              
  Lines       11362    11378      +16     
  Branches     2584     2587       +3     
==========================================
+ Hits        10129    10142      +13     
- Misses        812      815       +3     
  Partials      421      421              
Files Changed Coverage Δ
vyper/semantics/analysis/local.py 92.06% <ø> (+0.44%) ⬆️
vyper/semantics/analysis/annotation.py 90.64% <92.30%> (+0.01%) ⬆️
vyper/builtins/_signatures.py 97.70% <100.00%> (+0.05%) ⬆️
vyper/builtins/functions.py 90.60% <100.00%> (+0.05%) ⬆️

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@tserg tserg marked this pull request as draft August 7, 2023 09:15
Comment on lines 188 to 192
mutable_builtins = (
"create_minimal_proxy_to",
"create_copy_of",
"create_from_blueprint",
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is an overlap here with #3546 (comment).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Another option here could be to check constancy of the context in _CreateBase.build_IR(), similar to how it is being checked for raw_call. However, this would not resolve #3546.

@@ -6,6 +6,7 @@
from vyper.codegen.expr import Expr
from vyper.codegen.ir_node import IRnode
from vyper.exceptions import CompilerPanic, TypeMismatch
from vyper.semantics.analysis.base import StateMutability

Check notice

Code scanning / CodeQL

Cyclic import Note

Import of module
vyper.semantics.analysis.base
begins an import cycle.
@@ -51,7 +51,7 @@
UnfoldableNode,
ZeroDivisionException,
)
from vyper.semantics.analysis.base import VarInfo
from vyper.semantics.analysis.base import StateMutability, VarInfo

Check notice

Code scanning / CodeQL

Cyclic import Note

Import of module
vyper.semantics.analysis.base
begins an import cycle.
Copy link

@Haitham103 Haitham103 left a comment

Choose a reason for hiding this comment

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

viwed

@charles-cooper
Copy link
Member

superseded by #3729

@tserg tserg deleted the fix/mutate branch February 14, 2024 02:50
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.

compiler panic with mutating code inside non-mutable function
4 participants