Skip to content

Refactor lookupPath to avoid recursion. NFC #23017

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 9 commits into from
Dec 3, 2024

Conversation

hoodmane
Copy link
Collaborator

@hoodmane hoodmane commented Nov 26, 2024

This removes the recursion from lookupPath and in my opinion makes the control flow much more explicit and comprehensible.

@hoodmane hoodmane force-pushed the lookup-path-nonrecursive branch from b959b5b to 1611617 Compare November 26, 2024 10:52
Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

Thanks for working on this!

// split the absolute path
var parts = path.split('/').filter((p) => !!p);
// limit max consecutive symlinks to 40 (SYMLOOP_MAX).
linkloop: for (var nlinks = 0; nlinks < 40; nlinks ++) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wow, labeled continue targets!

Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

Can you rebase the codesize tests?

@hoodmane
Copy link
Collaborator Author

Well it's going to conflict with #22998, I suppose you can pick which one to merge first.

@sbc100
Copy link
Collaborator

sbc100 commented Nov 26, 2024

Can you confirm those codesize changes are all due to this change? i.e. can you run the rebase on main and confirm you don't see any changes?

@hoodmane
Copy link
Collaborator Author

hoodmane commented Nov 26, 2024

There are a lot of similar changes when I run it on main too.

@sbc100
Copy link
Collaborator

sbc100 commented Nov 26, 2024

There are a lot of similar changes when I run it on main too.

Maybe try with emsdk install tot (or otherwise make sure you have the latest llvm and binaryen). (Also try ./emcc --clear-cache)

@hoodmane
Copy link
Collaborator Author

Even after ./emsdk install tot, and clearing cache and getting the most up to date main branch I get a bunch of changes from the rebaseline.

@sbc100
Copy link
Collaborator

sbc100 commented Nov 26, 2024

Even after ./emsdk install tot, and clearing cache and getting the most up to date main branch I get a bunch of changes from the rebaseline.

Hmm.. that is strange/annoying. Maybe just revert those files then, and I can do a rebaseline after this lands.

@sbc100 sbc100 changed the title NFC Refactor lookupPath to avoid recursion Refactor lookupPath to avoid recursion. NFC Nov 26, 2024
@sbc100
Copy link
Collaborator

sbc100 commented Nov 26, 2024

OK, I just pushed another rebaseline commit, perhaps this one will match what you are generated on main now?

@hoodmane
Copy link
Collaborator Author

Nope, even if I check out your rebaseline commit and do a clean install of tot from emsdk I get a bunch of changes in code size by one to ten bytes.

@hoodmane
Copy link
Collaborator Author

hoodmane commented Dec 2, 2024

I think this PR fixes the case when you symlink a directory to itself symlink(".", "dir") and then try to glob("**") it. The previous lookupPath doesn't seem to detect this loop.

@hoodmane
Copy link
Collaborator Author

hoodmane commented Dec 3, 2024

@sbc100 can this be merged?

@sbc100 sbc100 merged commit acf75ee into emscripten-core:main Dec 3, 2024
26 of 28 checks passed
@hoodmane hoodmane deleted the lookup-path-nonrecursive branch December 4, 2024 09:25
@hoodmane
Copy link
Collaborator Author

hoodmane commented Dec 4, 2024

Thanks!

kleisauke added a commit to kleisauke/emscripten that referenced this pull request Dec 4, 2024
hedwigz pushed a commit to hedwigz/emscripten that referenced this pull request Dec 18, 2024
This removes the recursion from `lookupPath` and in my opinion makes the
control flow much more explicit and comprehensible.
hedwigz pushed a commit to hedwigz/emscripten that referenced this pull request Dec 18, 2024
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