Skip to content

Customize the limit of MaxDataSegments #7285

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

Merged
merged 4 commits into from
Feb 20, 2025
Merged

Conversation

lorsanta
Copy link
Contributor

@lorsanta lorsanta commented Feb 8, 2025

Related to #7229.

The custom limit can be passed by doing --pass-arg=limit-segments@1024 .

I didn't commit a unit test because I don't think it's necessary to add one, but I wrote one to test everything works:

index e2468e689..42e696421 100644
--- a/test/unit/test_memory_packing.py
+++ b/test/unit/test_memory_packing.py
@@ -40,3 +40,19 @@ class MemoryPackingTest(utils.BinaryenTestCase):
         self.assertEqual(p.returncode, 0)
         self.assertIn('Some VMs may not accept this binary', p.stderr)
         self.assertIn('Run the limit-segments pass to merge segments.', p.stderr)
+
+    def test_limit_segments_arg(self):
+        max_data_segments = 1024
+        data = '\n'.join('(data (i32.const %i) "A")' % i for i in range(100001))
+        module = '(module (memory 256 256) %s)' % data
+        opts = ['--limit-segments', f'--pass-arg=limit-segments@{max_data_segments}', '--print',
+                '-o', os.devnull]
+        output = [
+            f'(data ${max_data_segments-3} (i32.const {max_data_segments-3}) "A")',
+            f'(data $ (i32.const {max_data_segments-2}) "{"A"*(100001-(max_data_segments-2))}")'
+        ]
+        p = shared.run_process(shared.WASM_OPT + opts, input=module,
+                               check=False, capture_output=True)
+        self.assertEqual(p.returncode, 0)
+        for line in output:
+            self.assertIn(line, p.stdout)

Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

I agree a python unit test is not needed, but let's add a simple lit test. We are in the process of moving more testing to lit.

See e.g. test/lit/passes/strip-eh.wast for an example lit test to base off of. That directory is the right place for it.

Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

lgtm otherwise

@kripken kripken merged commit 613ea88 into WebAssembly:main Feb 20, 2025
14 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.

2 participants