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

Internal iterator ref #41

Merged
merged 3 commits into from
Jan 13, 2025
Merged

Internal iterator ref #41

merged 3 commits into from
Jan 13, 2025

Conversation

Lokathor
Copy link
Owner

@Lokathor Lokathor commented Jan 6, 2025

No description provided.

@danielhenrymantilla
Copy link

danielhenrymantilla commented Jan 13, 2025

The following lets cargo c --tests pass (I admit the problem of this pattern seems to be with the horrendous diagnostics when InternalIteratorThing<Item = …> is used instead of the proper InternalIteratorThing<ItemThing = …>):

  • (I had to add the rev = specification to the .toml file since the project does not track its .lock file, and since the remote repo has, since, removed its label feature.)
diff --git a/Cargo.toml b/Cargo.toml
index 80e7807..c37db04 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -21,7 +21,7 @@ logos = "0.14.0"
 chumsky = { git = "https://github.com/zesterer/chumsky", features = [
   "label",
   "pratt",
-] }
+], rev = "9d1ee8c" }
 ariadne = { git = "https://github.com/zesterer/ariadne" }
 internal-iterator = "0.2.3"
 #rayon = "1.7.0"
diff --git a/src/ast/data/if_else.rs b/src/ast/data/if_else.rs
index e50c9b2..9d74fe3 100644
--- a/src/ast/data/if_else.rs
+++ b/src/ast/data/if_else.rs
@@ -58,7 +58,7 @@ impl IfElse {
 
   pub fn calls_ref(
     &self,
-  ) -> impl '_ + InternalIterator<Item = &'_ FileSpanned<Call>> {
+  ) -> impl '_ + InternalIteratorRef<ItemRef = &'_ FileSpanned<Call>> {
     return CallsRef(self);
     // where:
     struct CallsRef<'r>(&'r IfElse);
@@ -76,7 +76,7 @@ impl IfElse {
         for stmt in self.0.if_body.iter() {
           stmt.calls_ref().try_for_each_ref(&mut *f)?;
         }
-        for stmt in self.0.else_body.iter_mut() {
+        for stmt in self.0.else_body.iter() {
           stmt.calls_ref().try_for_each_ref(&mut *f)?;
         }
         ControlFlow::Continue(())
diff --git a/src/ast/data/loop_.rs b/src/ast/data/loop_.rs
index 4178e36..4e8acee 100644
--- a/src/ast/data/loop_.rs
+++ b/src/ast/data/loop_.rs
@@ -66,7 +66,7 @@ impl Loop {
 
   pub fn calls_ref(
     &self,
-  ) -> impl '_ + InternalIterator<Item = &'_ FileSpanned<Call>> {
+  ) -> impl '_ + InternalIteratorRef<ItemRef = &'_ FileSpanned<Call>> {
     return CallsRef(self);
     // where:
     struct CallsRef<'r>(&'r Loop);
diff --git a/src/ast/data/statement.rs b/src/ast/data/statement.rs
index 14882ce..44755b1 100644
--- a/src/ast/data/statement.rs
+++ b/src/ast/data/statement.rs
@@ -51,7 +51,7 @@ impl Statement {
 
   pub fn calls_ref(
     &self,
-  ) -> impl '_ + InternalIteratorRef<Item = &'_ FileSpanned<Call>> {
+  ) -> impl '_ + InternalIteratorRef<ItemRef = &'_ FileSpanned<Call>> {
     return CallsRef(self);
     // where:
     struct CallsRef<'r>(&'r Statement);

That being said, I believe the Mut of InternalIteratorMut is w.r.t. the &mut impl Fn… arg it gets, not w.r.t. the items the iteration yields. In other words, it could be renamed as InternalIteratorExt (for clarity), and be used here. That way you won't have to duplicate the trait def and the guts! helper macro 🙂

@danielhenrymantilla
Copy link

PR submitted:

* I was being `.lock`ed out of testing the code 🙃

* Fix typo in trait/assoc type usage for `.calls_ref()`

* WIP: `git mv src/internal_iterator_re{f,c}.rs`

* WIP: finish renaming `InternalIterator{Ref,Mut}` as `InternalIteratorRec`

* Rename the call-sites (including `Mut`) accordingly

* WIP: Rename `ItemRec` as `Item` to prevent future such mistakes / bad diagnostics

* Adjust the call-sites accordingly

* WIP: Expose new internal `adhoc_internal_iterator_rec!` helper macro

* Profit™

* rustfmt

🥲
@Lokathor Lokathor merged commit 36bcd80 into main Jan 13, 2025
1 check passed
@Lokathor Lokathor deleted the internal_iterator_ref branch January 13, 2025 20:00
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