Skip to content

Refactor lookupPath to avoid recursion. NFC#23017

Merged
sbc100 merged 9 commits into
emscripten-core:mainfrom
hoodmane:lookup-path-nonrecursive
Dec 3, 2024
Merged

Refactor lookupPath to avoid recursion. NFC#23017
sbc100 merged 9 commits into
emscripten-core:mainfrom
hoodmane:lookup-path-nonrecursive

Conversation

@hoodmane

@hoodmane hoodmane commented Nov 26, 2024

Copy link
Copy Markdown
Collaborator

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

@sbc100 sbc100 left a comment

Copy link
Copy Markdown
Collaborator

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!

Comment thread src/library_fs.js Outdated
// 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
Copy Markdown
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!

Comment thread src/library_fs.js Outdated
Comment thread src/library_fs.js Outdated

@sbc100 sbc100 left a comment

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
Collaborator Author

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

@sbc100

sbc100 commented Nov 26, 2024

Copy link
Copy Markdown
Collaborator

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

hoodmane commented Nov 26, 2024

Copy link
Copy Markdown
Collaborator Author

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

@sbc100

sbc100 commented Nov 26, 2024

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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

sbc100 commented Nov 26, 2024

Copy link
Copy Markdown
Collaborator

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

sbc100 commented Nov 26, 2024

Copy link
Copy Markdown
Collaborator

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

@hoodmane

Copy link
Copy Markdown
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.

Comment thread ChangeLog.md Outdated
@hoodmane

hoodmane commented Dec 2, 2024

Copy link
Copy Markdown
Collaborator Author

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

hoodmane commented Dec 3, 2024

Copy link
Copy Markdown
Collaborator Author

@sbc100 can this be merged?

@sbc100 sbc100 merged commit acf75ee into emscripten-core:main Dec 3, 2024
@hoodmane hoodmane deleted the lookup-path-nonrecursive branch December 4, 2024 09:25
@hoodmane

hoodmane commented Dec 4, 2024

Copy link
Copy Markdown
Collaborator Author

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