ethereum / fe

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

Add `usize` and `isize` as a primitive type #995

Closed Y-Nak closed 2 months ago

Y-Nak commented 4 months ago

We don't have usize and isize to represent target-dependent pointer-size, which are useful, especially for

  1. Memory Indexing: usize is primarily used for indexing into collections and working with memory sizes.
  2. System Compatibility: Both isize and usize provide a means to write code that is portable across systems.

This issue can be split up into several phases.

lana-shanghai commented 3 months ago

Hey, could I work on this? @Y-Nak

Y-Nak commented 3 months ago

Yes, of course!

lana-shanghai commented 3 months ago

Yes, of course!

Sweet! So this task includes mentoring from you? :) if you have any guidance on how to start with the parser, please share, otherwise I am diving into the codebase for now!

Y-Nak commented 3 months ago

So this task includes mentoring from you?

yep!

if you have any guidance on how to start with the parser

Sorry, I made the wrong description for the issue; you don't need to modify the parser. So, the first step for this issue would be to make the name resolution handle the two types properly.

The concrete steps would be

  1. Add usize and isize tohir::hir_def::ident::kw.
  2. Modify hir::hir_def::prim_ty to accommodate those two types(IntTy and UintTy are the places where you would need to modify).
  3. Modify hir::hir_def::PrimTy::all_types so that it includes the newly added usize and isize in step 2.
Y-Nak commented 3 months ago

For the type checker module, the steps would be

  1. Modify hir_analysis::ty::ty_def::PrimTy.
  2. Modify impl From<HirPrimty> for TyBase in ty_def module.

In addition to that, you probably need to modify some auxiliary methods like ty_def::PrimTy::is_integral.

Basically, that'd be all necessary things(I might miss something, though). Please feel free to ask any questions.

Y-Nak commented 3 months ago

Oh, currently, the head of v2 is https://github.com/ethereum/fe/pull/1007, which will be merged soon. Please use that branch as a base.

Y-Nak commented 2 months ago

resolved in #1012