-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Synchronize standard library sources with Scala 2.13.18 #24788
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
Open
WojciechMazur
wants to merge
8
commits into
scala:main
Choose a base branch
from
WojciechMazur:stdlib-sync/2.13.18
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+231
−27
Open
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7b16dd7
Re-introduce null checks to ScalaRunTime.wrapXArray
lrytz bea3196
IterableOnce: Documentation update in IterableOnce `cmp` -> `ord`
ev-ev 51aa5b9
fix Buffer.filterInPlace scaladoc
xuwei-k ffbe998
Add `@uncheckedOverride` annotation for definitions that may override
lrytz 4a16c59
Add script to sychronize stdlib sources
WojciechMazur 29eb965
Use `mapNull` to implement ScalaRunTime array wrap functions
WojciechMazur 675e656
Add regression test for #24204 fixed by changes to ScalaRunTime
WojciechMazur 9b37e89
Adjust MiMa filters
WojciechMazur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
library/src/scala/annotation/unchecked/uncheckedOverride.scala
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| * Scala (https://www.scala-lang.org) | ||
| * | ||
| * Copyright EPFL and Lightbend, Inc. dba Akka | ||
| * | ||
| * Licensed under Apache License 2.0 | ||
| * (http://www.apache.org/licenses/LICENSE-2.0). | ||
| * | ||
| * See the NOTICE file distributed with this work for | ||
| * additional information regarding copyright ownership. | ||
| */ | ||
|
|
||
| package scala.annotation.unchecked | ||
|
|
||
| import scala.annotation.StaticAnnotation | ||
|
|
||
| /** | ||
| * Marking a definition `@uncheckedOverride` is equivalent to the `override` keyword, except that overriding is not | ||
| * enforced. A definition marked `@uncheckedOverride` is allowed to override nothing. | ||
| */ | ||
| final class uncheckedOverride extends StaticAnnotation |
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| //> using scala 3.7 | ||
| //> using toolkit default | ||
|
|
||
| import scala.util.matching.Regex | ||
|
|
||
| import scala.util.CommandLineParser.FromString | ||
|
|
||
| given FromString[os.Path] with | ||
| def fromString(s: String) = os.Path(s, os.pwd) | ||
|
|
||
| /** Sync standard library changes from scala/scala to scala/scala3. | ||
| * | ||
| * Usage: scala run syncStdLib.scala -- <scala2-repo-path> <from-tag> <to-tag> | ||
| * | ||
| * Example: scala syncStdLib.scala -- ../scala2 v2.13.17 v2.13.18 | ||
| */ | ||
| @main def syncStdLib( | ||
| scala2RepoPath: os.Path, | ||
| fromTag: String, | ||
| toTag: String | ||
| ): Unit = | ||
| val scala2Path = os.Path(scala2RepoPath, os.pwd) | ||
| val scala3Path = os.pwd | ||
|
|
||
| val workDir = scala3Path / "stdlib-sync-work" | ||
| val patchDir = workDir / "patches" | ||
|
|
||
| println(s"Scala 2 repo: $scala2Path") | ||
| println(s"Scala 3 repo: $scala3Path") | ||
| println(s"Syncing: $fromTag..$toTag") | ||
| println() | ||
|
|
||
| // Clean up and create directories | ||
| os.remove.all(workDir) | ||
| os.makeDir.all(patchDir) | ||
|
|
||
| // ------------------------- | ||
| // 1) Fetch latest changes in scala2 repo | ||
| // ------------------------- | ||
| println(s"Fetching tags $fromTag and $toTag from scala2...") | ||
| os.proc("git", "fetch", "--tags", "origin", fromTag, toTag) | ||
| .call(cwd = scala2Path, stdout = os.Inherit, stderr = os.Inherit) | ||
|
|
||
| // Show what will be synced | ||
| println(s"\nCommits to sync ($fromTag..$toTag):") | ||
| val logResult = os | ||
| .proc("git", "log", "--oneline", s"$fromTag..$toTag", "--", "src/library") | ||
| .call(cwd = scala2Path) | ||
| logResult.out.lines().foreach(println) | ||
| println() | ||
|
|
||
| // ------------------------- | ||
| // 2) Create patch series for src/library only, paths relative to src/library/ | ||
| // ------------------------- | ||
| println("Creating patches...") | ||
| os.proc( | ||
| "git", | ||
| "format-patch", | ||
| "--output-directory", | ||
| patchDir.toString, | ||
| "--relative=src/library", | ||
| "--no-signature", | ||
| s"$fromTag..$toTag", | ||
| "--", | ||
| "src/library" | ||
| ).call(cwd = scala2Path, stdout = os.Inherit, stderr = os.Inherit) | ||
|
|
||
| val patchFiles = os.list(patchDir).filter(_.ext == "patch").sorted | ||
| println(s"Created ${patchFiles.size} patches") | ||
|
|
||
| // ------------------------- | ||
| // 3) Rewrite patches: | ||
| // - qualify #NNNN -> scala/scala#NNNN | ||
| // - add footer: "Upstream: scala/scala@<sha>" | ||
| // ------------------------- | ||
| println("\nRewriting patches...") | ||
| rewritePatches(patchDir) | ||
|
|
||
| // ------------------------- | ||
| // 4) Apply onto scala3 | ||
| // ------------------------- | ||
| val branchName = s"stdlib-sync/${toTag.stripPrefix("v")}" | ||
| println(s"\nCreating branch $branchName...") | ||
|
|
||
| os.proc("git", "checkout", "-b", branchName, "origin/main") | ||
| .call(cwd = scala3Path, stdout = os.Inherit, stderr = os.Inherit) | ||
|
|
||
| println(s"Applying ${patchFiles.size} patches...") | ||
|
|
||
| val patches = os.list(patchDir).filter(_.ext == "patch").sorted | ||
| val amResult = os | ||
| .proc("git", "am", "--3way", "--directory=library/src", patches) | ||
| .call( | ||
| cwd = scala3Path, | ||
| check = false, | ||
| stdout = os.Inherit, | ||
| stderr = os.Inherit | ||
| ) | ||
|
|
||
| if amResult.exitCode != 0 then | ||
| println() | ||
| println("Conflicts occurred.") | ||
| println("Resolve, then run: git am --continue") | ||
| println("Abort with: git am --abort") | ||
| sys.exit(1) | ||
|
|
||
| println("\nPatches applied successfully!") | ||
| os.remove.all(workDir) | ||
|
|
||
| println(s"\nTo push the branch, run:") | ||
| println(s" git push -u origin $branchName") | ||
| end syncStdLib | ||
|
|
||
| /** Rewrite patches to: | ||
| * - Qualify GitHub issue refs: #NNNN -> scala/scala#NNNN | ||
| * - Add footer: "Upstream: scala/scala@<sha>" | ||
| */ | ||
| def rewritePatches(patchDir: os.Path): Unit = | ||
| val patchFiles = os.list(patchDir).filter(_.ext == "patch").sorted | ||
| val issueRefPattern = """(?<!\w)#(\d+)""".r | ||
| val fromLinePattern = """^From ([0-9a-f]{40}) """.r | ||
|
|
||
| var rewrittenCount = 0 | ||
|
|
||
| for patch <- patchFiles do | ||
| val raw = os.read(patch) | ||
|
|
||
| // Extract upstream commit SHA from the "From <sha> ..." line | ||
| val upstream = fromLinePattern.findFirstMatchIn(raw).map(_.group(1)) | ||
|
|
||
| // Qualify github refs in the patch (commit message is inside) | ||
| var rewritten = issueRefPattern.replaceAllIn(raw, "scala/scala#$1") | ||
|
|
||
| // Insert "Upstream: ..." footer into the commit message. | ||
| // In format-patch output, commit message ends just before "\n---\n" | ||
| upstream.foreach { sha => | ||
| val footer = s"Upstream: scala/scala@$sha" | ||
| if !rewritten.contains(footer) then | ||
| rewritten.split("\n---\n", 2) match | ||
| case Array(msg, rest) => | ||
| var newMsg = msg | ||
| if !newMsg.endsWith("\n") then newMsg += "\n" | ||
| if !newMsg.endsWith("\n\n") then newMsg += "\n" | ||
| newMsg += s"$footer\n" | ||
| rewritten = newMsg + "\n---\n" + rest | ||
| case _ => // No split point found, leave as is | ||
| } | ||
|
|
||
| if rewritten != raw then | ||
| os.write.over(patch, rewritten) | ||
| rewrittenCount += 1 | ||
|
|
||
| println(s"Rewrote $rewrittenCount patches") | ||
| end rewritePatches |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@noti0na1 is it ok? Should we adjust the signature as well? I'm not sure what's the best approach here, should we kept it as it is for backward compatibility, make output nullable, or both input and output
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The signatures look good to me. We can use
ScalaRunTime.mapNullfor rhs to deal with situations like this.