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

Basic unsafe support #569

Merged
merged 1 commit into from
Oct 13, 2021
Merged

Basic unsafe support #569

merged 1 commit into from
Oct 13, 2021

Conversation

sbillig
Copy link
Collaborator

@sbillig sbillig commented Oct 12, 2021

This adds basic support for unsafe functions and unsafe blocks. This doesn't add any built-in unsafe functions; someday soon there will be some fun unsafe fns in a std::evm module, but that'll come in a separate PR. So there's currently no point in using any of this.

I've decided to enforce the rule that contract functions can be either pub or unsafe, but not both. I don't have strong feelings about this, it just seemed reasonable.

To-Do

  • OPTIONAL: Update Spec if applicable

  • Add entry to the release notes (may forgo for trivial changes)

  • Clean up commit history

@sbillig sbillig marked this pull request as ready for review October 12, 2021 04:26
@codecov-commenter
Copy link

codecov-commenter commented Oct 12, 2021

Codecov Report

Merging #569 (f72b2bf) into master (a8c713e) will decrease coverage by 0.03%.
The diff coverage is 82.55%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #569      +/-   ##
==========================================
- Coverage   86.67%   86.63%   -0.04%     
==========================================
  Files          87       87              
  Lines        6362     6428      +66     
==========================================
+ Hits         5514     5569      +55     
- Misses        848      859      +11     
Impacted Files Coverage Δ
crates/analyzer/src/namespace/scopes.rs 77.34% <ø> (ø)
crates/lowering/src/mappers/module.rs 85.71% <ø> (ø)
crates/parser/src/grammar/contracts.rs 86.66% <ø> (ø)
crates/parser/src/lexer/token.rs 21.05% <0.00%> (-0.23%) ⬇️
crates/yulgen/src/mappers/functions.rs 92.53% <0.00%> (-4.34%) ⬇️
crates/parser/src/ast.rs 80.74% <37.50%> (-1.37%) ⬇️
crates/parser/src/grammar/module.rs 82.89% <44.44%> (+0.11%) ⬆️
crates/lowering/src/mappers/functions.rs 97.95% <80.00%> (-0.66%) ⬇️
crates/analyzer/src/db/queries/contracts.rs 94.32% <100.00%> (ø)
crates/analyzer/src/db/queries/functions.rs 97.89% <100.00%> (+0.19%) ⬆️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a8c713e...f72b2bf. Read the comment docs.

@@ -25,6 +26,17 @@ pub fn function_signature(
let mut scope = ItemScope::new(db, function.module(db));
let contract = function.contract(db);

if_chain! {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sweet helper :)

Copy link
Collaborator

@cburgdorf cburgdorf left a comment

Choose a reason for hiding this comment

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

Looks great! I think there's one incorrect error message though.

"`pub` visibility modifier must come before `unsafe`",
vec![Label::primary(
unsafe_span + pub_.span,
"use `pub unsafe` here",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I've decided to enforce the rule that contract functions can be either pub or unsafe, but not both

As I understand pub unsafe is a compile time error so the error message of "use pub unsafe here" seems to be misleading.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

pub unsafe is allowed on functions defined at the module level, and will be allowed for struct functions, but it is misleading for contracts. I guess I'm inclined to just leave this, rather than add special behavior here for fns inside contracts.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, understood 👍

@sbillig sbillig merged commit 9255c97 into ethereum:master Oct 13, 2021
@sbillig sbillig deleted the unsafe branch October 13, 2021 18:17
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.

3 participants