This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
adamiak
approved these changes
Mar 25, 2024
Consider three files: - file A - file B - file C The structure is the following: - file A does an import that looks like this `import { Decl, IDecl }` from file B. - file B declares the `Decl` object and does an import that looks like `import { IDecl }` from file C. - file C declares the `IDecl` object. Now the flow of what happened: - the code sees that there is an import in file A so it calls `resolveFileImport()`. - that function sees that it will import only two things from file B. - it processes the first object (`Decl`), it finds it in the declarations of file B. It adds it to the `alreadyImportedObjects` map. - it processes the second object (`IDecl`), it does not find it in the declarations of file B. It calls itself recursively to resove all the imports of file B. IMPORTANT: it passes the `alreadyImportedObjects` as an argument to that call. That call **will** modify that object, filling it up with all the imports that file B does. When it finds the `IDecl` object from the imports that are happening what we want to have happened is to only include that `IDecl` object in the `alreadyImportedObjects` map. But that map becomes tainted. The solution to that problem is to do a deep copy of that object so any tainting is contained to that copy that is later dropped. A note on performance. Copying is almost always not the thing we want to do if we want to achieve high performance. But in this case this solution is fine because this is a statistically rare case.
b549ffc
to
33674d9
Compare
adamiak
pushed a commit
to l2beat/l2beat
that referenced
this pull request
Apr 24, 2024
* Import more top level declarations * Compact stuff * Tests * Fix a very rare edge case in the PolygonZKEVM fix Consider three files: - file A - file B - file C The structure is the following: - file A does an import that looks like this `import { Decl, IDecl }` from file B. - file B declares the `Decl` object and does an import that looks like `import { IDecl }` from file C. - file C declares the `IDecl` object. Now the flow of what happened: - the code sees that there is an import in file A so it calls `resolveFileImport()`. - that function sees that it will import only two things from file B. - it processes the first object (`Decl`), it finds it in the declarations of file B. It adds it to the `alreadyImportedObjects` map. - it processes the second object (`IDecl`), it does not find it in the declarations of file B. It calls itself recursively to resove all the imports of file B. IMPORTANT: it passes the `alreadyImportedObjects` as an argument to that call. That call **will** modify that object, filling it up with all the imports that file B does. When it finds the `IDecl` object from the imports that are happening what we want to have happened is to only include that `IDecl` object in the `alreadyImportedObjects` map. But that map becomes tainted. The solution to that problem is to do a deep copy of that object so any tainting is contained to that copy that is later dropped. A note on performance. Copying is almost always not the thing we want to do if we want to achieve high performance. But in this case this solution is fine because this is a statistically rare case. * Changeset
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves L2B-4024 L2B-4023