core: refactor to use TypeVarId and TypeVar #414

Merged
sb10q merged 5 commits from type-var-id into master 2024-06-13 18:32:41 +08:00
Collaborator

Main changes are in nac3core/src/typecheck/typedef/mod.rs.

  1. Type variable IDs are now carried by struct TypeVarId(u32) instead of simply u32.
  2. Added struct TypeVar { id: TypeVarId, ty: Type }.
    1. unifier.add_ty and others now return TypeVar instead of (Type, u32).

Other notes:

  1. Some insta snapshots are updated. This is because type variable ID u32 values are now wrapped within TypeVarId. The output from Debug becomes different.
Main changes are in `nac3core/src/typecheck/typedef/mod.rs`. 1. Type variable IDs are now carried by `struct TypeVarId(u32)` instead of simply `u32`. 2. Added `struct TypeVar { id: TypeVarId, ty: Type }`. 1. `unifier.add_ty` and others now return `TypeVar` instead of `(Type, u32)`. Other notes: 1. Some `insta` snapshots are updated. This is because type variable ID `u32` values are now wrapped within `TypeVarId`. The output from `Debug` becomes different.
lyken added 1 commit 2024-06-13 13:35:21 +08:00
lyken requested review from derppening 2024-06-13 13:35:45 +08:00
derppening requested changes 2024-06-13 15:32:50 +08:00
derppening left a comment
Collaborator

The rest of the PR looks good. Do remove the *.bc and *.o file, or otherwise add those to the Gitignore.

The rest of the PR looks good. Do remove the `*.bc` and `*.o` file, or otherwise add those to the Gitignore.
@ -32,1 +31,3 @@
pub type VarMap = IndexMapping<u32>;
/// ID of a Python type variable. Specific to `nac3core`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct TypeVarId(pub u32);
Collaborator

I don't think it's necessary to pub the value of the TypeVarId. Maybe add a From<TypeVarId> for u32 if we want to be able to convert back to a u32 value.

I don't think it's necessary to `pub` the value of the `TypeVarId`. Maybe add a `From<TypeVarId> for u32` if we want to be able to convert back to a `u32` value.
@ -33,0 +33,4 @@
pub struct TypeVarId(pub u32);
impl fmt::Display for TypeVarId {
// NOTE: Must output the string fo the ID value. Certain unit tests rely on string comparisons.
Collaborator

Typo: fo -> of

Typo: fo -> of
@ -33,0 +55,4 @@
/// Build a [`VarMap`] from an iterator of [`TypeVar`]
///
/// The resulting [`VarMap`] wil have the same order as the input iterator.
pub fn to_var_map<I>(vars: I) -> VarMap
Collaborator

This might be better named as into_var_map.

This might be better named as `into_var_map`.
lyken force-pushed type-var-id from 1da1bdacab to 21c62f235b 2024-06-13 15:52:53 +08:00 Compare
Author
Collaborator

Revised. Force-pushed to remove non-source files from history.

Revised. Force-pushed to remove non-source files from history.
lyken added 2 commits 2024-06-13 16:03:55 +08:00
lyken force-pushed type-var-id from ddef23db15 to 344b959998 2024-06-13 16:23:32 +08:00 Compare
lyken force-pushed type-var-id from 344b959998 to 6979843431 2024-06-13 16:59:59 +08:00 Compare
sb10q merged commit 6979843431 into master 2024-06-13 18:32:41 +08:00
sb10q deleted branch type-var-id 2024-06-13 18:32:41 +08:00
Sign in to join this conversation.
No reviewers
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: M-Labs/nac3#414
No description provided.