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

Add usize and isize as a primitive type #995

Closed
1 of 3 tasks
Y-Nak opened this issue Apr 20, 2024 · 7 comments
Closed
1 of 3 tasks

Add usize and isize as a primitive type #995

Y-Nak opened this issue Apr 20, 2024 · 7 comments
Labels
mentor This issue is mentored v2 Issues in v2 implementation

Comments

@Y-Nak
Copy link
Member

Y-Nak commented Apr 20, 2024

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.

  • Modify the parser to accommodate these types
  • Make name resolution handle them properly as a builtin type
  • Make type check handle them. These types will affect other built-in types, e.g., array type definition.
@Y-Nak Y-Nak added mentor This issue is mentored v2 Issues in v2 implementation labels Apr 20, 2024
@lana-shanghai
Copy link

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

@Y-Nak
Copy link
Member Author

Y-Nak commented May 17, 2024

Yes, of course!

@lana-shanghai
Copy link

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
Copy link
Member Author

Y-Nak commented May 17, 2024

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
Copy link
Member Author

Y-Nak commented May 17, 2024

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
Copy link
Member Author

Y-Nak commented May 17, 2024

Oh, currently, the head of v2 is #1007, which will be merged soon.
Please use that branch as a base.

@Y-Nak
Copy link
Member Author

Y-Nak commented Jun 10, 2024

resolved in #1012

@Y-Nak Y-Nak closed this as completed Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mentor This issue is mentored v2 Issues in v2 implementation
Projects
None yet
Development

No branches or pull requests

2 participants