Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This reverts commit 7cbaa7c.
sidepelican
commented
Dec 17, 2024
Comment on lines
+90
to
+92
| guard generatedSources.insert(source).inserted else { | ||
| continue | ||
| } |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
課題
PackageGeneratorにおいて、特定の状況において同じソースファイルが複数回生成されるという問題がありました。
以下の状況で再現します。
同じソースファイルが複数回処理された場合、
didConvertSourceがその回数分呼び出されてしまうため、外部から別途TSコードをPackageEntryに注入していた場合、そのコードが重複してしまいます。(PackageEntryのもつ
sourceが参照型であることと、シンボルテーブル生成時の結果を使い回す実装が組み合わさって起こる)原因
現在のPackageGeneratorの処理は以下のようになっています。
)し、importされているシンボルを調べる。その中に未生成のものがあればそれを生成対象スタックに追加
この際、3で未生成のものかどうかを
generatedSourcesという集合で管理していましたが、generatedSourcesに含まれていないけど生成対象スタックに含まている、というケースを見逃していました。そのケースの場合、生成対象スタックには同じソースファイルが複数積まれることが生じえます。
例えば上のA,Bのファイルのケースの場合の生成対象スタックの変化は以下の形になります。
generatedSourcesにAは含まれないので、Aを追加A.swiftが2回処理されることになりました。
修正方針
スタックから値を取り出した際、それが
generatedSourcesに含まれている場合はスキップできるようにします。