Skip to content

Conversation

@kripken
Copy link
Member

@kripken kripken commented Dec 13, 2024

Other than simple defined functions function foo() {}, JS also has
arrow functions and object methods. We need to be aware of those
in metadce.

This fixes #22968 which was an issue with an object method that
enclosed a function of the same name as another toplevel function.
To fix this, this PR makes us aware of such scopes, and we do not
optimize functions in them. That is, we only ever optimize defined
functions at the toplevel scope, and anything enclosed is considered
fixed.

@kripken
Copy link
Member Author

kripken commented Dec 13, 2024

@sbc100 I'm not sure what to do with the prettier error here. On CI the error is without explanation, so I tried to run it locally, ./node_modules/prettier/bin/prettier.cjs tools/acorn-optimizer.mjs --fix. But that produces 334 lines of diff, on lots of other stuff than I touched?

@@ -0,0 +1,35 @@

Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if we can give this (and the other tests 1-5) better names? Can be followup maybe?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll rename the new one in this PR. I can look at the others later.

}

wasmImports = {};

Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove extra newline at start and end of this file.

@sbc100
Copy link
Collaborator

sbc100 commented Dec 13, 2024

@sbc100 I'm not sure what to do with the prettier error here. On CI the error is without explanation, so I tried to run it locally, ./node_modules/prettier/bin/prettier.cjs tools/acorn-optimizer.mjs --fix. But that produces 334 lines of diff, on lots of other stuff than I touched?

If you run that on main does it do anything? For me it doesn't.

}
}
}
} else if (node.type === 'Property' && node.method) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

assert(specialScopes > 0) ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

(Sorry just saw the one below.. probably don't need both)

Copy link
Member Author

Choose a reason for hiding this comment

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

Why, I think both make equal sense?

Copy link
Collaborator

Choose a reason for hiding this comment

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

lgtm either way.

@kripken
Copy link
Member Author

kripken commented Dec 13, 2024

Correct, it does nothing on the main branch, but does a 334-line diff on this one, though my changes are an order of magnitude smaller than that. I'm not familiar with prettier - is this a known issue?

@sbc100
Copy link
Collaborator

sbc100 commented Dec 13, 2024

Correct, it does nothing on the main branch, but does a 334-line diff on this one, though my changes are an order of magnitude smaller than that. I'm not familiar with prettier - is this a known issue?

No idea at all.. that seems very odd. It should always format the whole file.. regardless of which part you touch.

@kripken
Copy link
Member Author

kripken commented Dec 13, 2024

Ok, I pushed the prettier results (and the other feedback). The diff is now larger, but most of that is whitespace. I don't quite understand why it decided to change that whitespace, but it doesn't look bad...

@sbc100
Copy link
Collaborator

sbc100 commented Dec 13, 2024

Ok, I pushed the prettier results (and the other feedback). The diff is now larger, but most of that is whitespace. I don't quite understand why it decided to change that whitespace, but it doesn't look bad...

Its because it changed the indentation of argument to fullWalk on line 711. Viewing with ignore whitespace works.

@brendandahl
Copy link
Collaborator

Do you know offhand if methods in js classes work with metadce?

@kripken
Copy link
Member Author

kripken commented Dec 13, 2024

Does that use the same syntax as object methods? (type: "Property", and method: true) If so we should be handling them properly after this PR. But we just ignore them, we don't try to optimize away parts of classes or objects.

@kripken
Copy link
Member Author

kripken commented Dec 13, 2024

Landing to fix the user issue - if there is more to do here, we can look into that later.

@kripken kripken merged commit 0dfb071 into emscripten-core:main Dec 13, 2024
28 checks passed
@kripken kripken deleted the scope.horrible branch December 13, 2024 23:56
hedwigz pushed a commit to hedwigz/emscripten that referenced this pull request Dec 18, 2024
…en-core#23159)

Other than simple defined functions (function foo() {}), JS also has
arrow functions and object methods. We need to be aware of those
in metadce.

This fixes emscripten-core#22968 which was an issue with an object method that
enclosed a function of the same name as another toplevel function.
To fix this, this PR makes us aware of such scopes, and we do not
optimize functions in them. That is, we only ever optimize defined
functions at the toplevel scope, and anything enclosed is considered
fixed.
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.

__embind_initialize_bindings is stripped from export table in Release + pthreads build

3 participants