ethereum / fe

Emerging smart contract language for the Ethereum blockchain.
https://fe-lang.org
Other
1.6k stars 178 forks source link

`unsafe` expr parsing #991

Open g-r-a-n-t opened 6 months ago

g-r-a-n-t commented 6 months ago

Implemented parsing for unsafe expressions.

e.g.

unsafe { 
  let a = 42
  foo(42)
}

unsafe bar()
g-r-a-n-t commented 4 months ago

I will add unsafe expr checking to this as well.

Y-Nak commented 4 months ago

It's still unclear to me what the unsafe actually means in Fe. Do you have any concrete thoughts on this?

g-r-a-n-t commented 4 months ago

It's still unclear to me what the unsafe actually means in Fe. Do you have any concrete thoughts on this?

In general, code should be labeled as unsafe if it has the potential to introduce undefined behavior during runtime. For instance, an invocation of evm::mstore(..) could alter the value of data that is exclusively used in safe code, thus necessitating the unsafe label.

Y-Nak commented 4 months ago

Ok. So, in the v1 implementation, there are functions that don't cause undefined behavior (UB) but are still marked as unsafe, like RawCallBuffer::offset, which merely returns an offset. Am I correct in understanding that these should not be marked as unsafe? I felt that unsafe was being somewhat abused in v1, so I want to eliminate any ambiguity in my understanding.

g-r-a-n-t commented 4 months ago

That is correct. I agree that unsafe was overused in v1 and think that it should be used more sparingly in the v2 implementation.

Y-Nak commented 4 months ago

Ok, thanks!