Keep generated Ruby constants under the binding namespace - #1
Closed
pboling wants to merge 1 commit into
Closed
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a namespace-pollution bug in the Magnus-generated Ruby wrapper by stopping the generator from re-exporting generated type constants into Object, keeping all generated Ruby types under the binding module namespace to avoid collisions with unrelated gems.
Changes:
- Removed the
Object.const_setre-export loop from the Ruby wrapper template so generated constants stay under the binding module. - Added a generator regression test asserting the generated main Ruby wrapper does not contain the global export code.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/backends/magnus/templates/main_rb_wrapper.rb.jinja |
Removes global constant re-exporting; leaves generated types namespaced under the binding module. |
src/backends/magnus/gen_bindings/tests.rs |
Adds a regression test to prevent reintroducing global constant exports in generated Ruby wrappers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+162
to
+165
| assert!( | ||
| !main_file.content.contains("::Object.const_set"), | ||
| "the generated Ruby wrapper must not export constants globally" | ||
| ); |
Author
|
This PR was opened against the staging fork by mistake. The actual upstream PR is xberg-io#214. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Remove the Magnus Ruby wrapper's automatic export of generated constants into
Object.Generated Ruby types should remain under the public binding namespace. Publishing them globally is unsafe because generic names can collide with unrelated Ruby libraries. For example, TSLP's generated native
TreeSitterLanguagePack::Parserwas exported as::Parser; requiring theparsergem afterward raised:The
parsergem is not a dependency of TSLP. This is a generator namespace-pollution bug.Changes
Object.const_setre-export loop from the Magnus Ruby wrapper template.Issues are disabled for this repository, so this PR is also the bug report and design record.
Verification
Passes.