Skip to content

Fix duplicate deleters in manage function - #1572

Merged
eriksvedang merged 4 commits into
carp-lang:masterfrom
iwami4438:fix-repl-crashs-on-type-of-map
Jul 29, 2026
Merged

Fix duplicate deleters in manage function#1572
eriksvedang merged 4 commits into
carp-lang:masterfrom
iwami4438:fix-repl-crashs-on-type-of-map

Conversation

@iwami4438

Copy link
Copy Markdown
Contributor
  • Filter out existing deleters with the same name before insertion.
  • Added a comment suggesting exporting deleterVar in Info.hs later.
  • ormolu fixed the style.
  • Ref: Repl crashes on type of Map #1457

Filter out existing deleters with the same name before insertion.
Added a comment suggesting exporting deleterVar in Info.hs later.

@hellerve hellerve left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this!

I think this is an alright fix (I would remove the duplicated check here), but I think we could go for something more principled, and remove the root cause of the issue.

As far as I remember, the main issue was that the parser doesn’t assign identifiers (they are set in setNewIdentifiers in expansion). This is fine for all regular forms, but primitives never get there, so kind and type call qualification and annotation on uninitialized identifiers.

What I propose we do instead is to renumber before annotating in the two primitives that do this, mirroring what every other caller to annotate does. This is still brittle, because it also needs any future caller to do this, but I think it’s nicer than filtering it out later.

I’ll happily let others chime in, though.

Comment thread src/Memory.hs Outdated
Comment on lines +523 to +528
deleterV = \case
-- It's probably better to export deleterVar in Info.hs's.
ProperDeleter _ _ v -> v
RefDeleter v -> v
PrimDeleter v -> v
FakeDeleter v -> v

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d agree to instead export deleterVar and use that.

@iwami4438

Copy link
Copy Markdown
Contributor Author

Thank you for the suggestion. I agree that addressing the root cause is better.

​I will update the implementation to renumber before annotating in the primitives as you proposed.

- Renumber via `setNewIdentifiers` before `qualify`/`annotate` in
  `primitiveType` and `primitiveKind`.
- Remove the now-unneeded duplicated deleter check in Memory.hs.
- Export `setNewIdentifiers` from `Expand.hs`.

@hellerve hellerve left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me now! If we want to go the extra mile, we can add some regression tests, but other than that, this is clean!

@iwami4438

Copy link
Copy Markdown
Contributor Author

Okay, I'll add the test code.

@eriksvedang
eriksvedang merged commit bfa0802 into carp-lang:master Jul 29, 2026
4 checks passed
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