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

Customize the limit of MaxDataSegments #7285

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

lorsanta
Copy link

@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.

src/ir/memory-utils.h Outdated Show resolved Hide resolved
src/passes/LimitSegments.cpp Outdated Show resolved Hide resolved
src/passes/LimitSegments.cpp Outdated Show resolved Hide resolved
src/passes/LimitSegments.cpp Outdated Show resolved Hide resolved
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

@@ -22,7 +22,13 @@ namespace wasm {

struct LimitSegments : public Pass {
Copy link
Member

Choose a reason for hiding this comment

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

Please add a comment documenting this flag, similar to

// --pass-arg=asyncify-asserts
//
// This enables extra asserts in the output, like checking if we put in
// an unwind/rewind in an invalid place (this can be helpful for manual
// tweaking of the only-list / remove-list, see later).

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