Skip to content
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

Enable builds under GraalVM #1266

Merged
merged 3 commits into from
Sep 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scalafmt-cli/src/main/scala/org/scalafmt/cli/Cli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ object Cli {
}

def main(args: Array[String]): Unit = {
val exit = mainWithOptions(args, CliOptions.default)
val exit = mainWithOptions(args, CliOptions())
sys.exit(exit.code)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.scalafmt

package object internal {
type PriorityQueue[T] = scala.collection.mutable.PriorityQueue[T]
ssaavedra marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.scalafmt.internal

/**
* Minimal implementation of the PriorityQueue's functions needed.
*
* We use [[java.util.PriorityQueue]] to enable usage under GraalVM. The
* native-image compiler is unable to work with
* [[scala.collection.mutable.PriorityQueue]] currently.
*
* @tparam T the values inside the queue
*/
class PriorityQueue[T](implicit ord: Ordering[T]) {
private[this] val q = new java.util.PriorityQueue[T](11, ord.reversed())

def dequeueAll: Unit = q.clear()

def dequeue(): T = q.poll()

def size: Int = q.size()

def enqueue(x: T): Unit = q.add(x)

def +=(x: T): PriorityQueue[T] = {
q.add(x)
this
}

def nonEmpty: Boolean = !isEmpty

def isEmpty: Boolean = q.isEmpty

}
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class BestFirstSearch(
stop: Token,
depth: Int = 0,
maxCost: Int = Integer.MAX_VALUE): State = {
val Q = new mutable.PriorityQueue[State]()
val Q = new PriorityQueue[State]()
var result = start
var lastDequeue = start
Q += start
Expand Down