Skip to content

Commit bd71e93

Browse files
committed
Allow considering all SCCs bad
1 parent 601ba5a commit bd71e93

File tree

4 files changed

+37
-18
lines changed

4 files changed

+37
-18
lines changed

bench.nu

+18-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
const jar = "fred.jar"
22
const outExe = "bench.bin"
33

4-
export def run [ file: string, lazyMarkScanOnly: bool ] {
4+
export def run [ file: string, lazyMarkScanOnly: bool, allSccsBad: bool ] {
55
let benchName = $file | path basename
6-
if $lazyMarkScanOnly {
7-
java -jar $jar $file -o $outExe --lazy-mark-scan-only
8-
} else {
9-
java -jar $jar $file -o $outExe
10-
}
11-
print $"Compiled ($file) \(lazy-mark-scan-only: ($lazyMarkScanOnly))"
6+
let opts = [
7+
...(if $lazyMarkScanOnly { [--lazy-mark-scan-only] } else { [] }),
8+
...(if $allSccsBad { [--all-sccs-bad] } else { [] })
9+
]
10+
java -jar $jar $file -o $outExe ...$opts
11+
print $"Compiled ($file) \(lazy-mark-scan-only: ($lazyMarkScanOnly), all-sccs-bad: ($allSccsBad))"
1212
let out = ^$"./($outExe)"
1313
print $out
1414
let res = (
@@ -20,12 +20,19 @@ export def run [ file: string, lazyMarkScanOnly: bool ] {
2020
Name: $benchName,
2121
"Timestamp counter": $res.tsc,
2222
Clock: $res.clock,
23-
"Lazy mark scan only": $lazyMarkScanOnly
23+
"Lazy mark scan only": $lazyMarkScanOnly,
24+
"All SCCs bad": $allSccsBad,
2425
}
2526
}
2627

27-
export def run-all [ ] {
28-
let files = (ls benchmarks/*.fred).name
29-
let results = $files | each { |file| [(run $file false), (run $file true)] }
28+
export def run-all [ files: glob = benchmarks/*.fred ] {
29+
let results = glob $files | each { |file|
30+
[
31+
(run $file false false),
32+
(run $file false true),
33+
(run $file true false),
34+
(run $file true true)
35+
]
36+
}
3037
$results | flatten
3138
}

benchmarks/game.fred

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ data Player
22
= Player { store: Store }
33
// This exists only to make the compiler think that Player can be involved in cycles
44
| PlayerCyclic {
5-
mut player: Player
5+
// With the --all-sccs-bad flag enabled, this would make the compiler think there could be a cycle
6+
player: Player
67
}
78

89
// Represents some shared data that all Player objects have a reference to
@@ -11,8 +12,8 @@ data Store = Store { datums: Data }
1112
data Data
1213
= DataCons {
1314
value: int,
14-
// This is mut only so the compiler thinks there can be a cycle at runtime
15-
mut next: Data
15+
// This would need to be mut for the compiler to think there could be a cycle at runtime
16+
next: Data
1617
}
1718
| DataNil {}
1819

src/main/scala/fred/Compiler.scala

+9-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ package fred
22

33
import scala.sys.process.*
44
import java.io.File
5-
6-
import scopt.OParser
75
import java.nio.file.Files
86
import java.nio.file.Path
97

8+
import scopt.OParser
9+
1010
object Compiler {
1111
private val RuntimeHeader = "runtime/runtime.h"
1212

1313
case class Settings(
1414
rcAlgo: RcAlgo = RcAlgo.Mine,
15+
allSccsBad: Boolean = false,
1516
includeMemcheck: Boolean = false
1617
)
1718

@@ -37,7 +38,12 @@ object Compiler {
3738
.text("Output executable (default: a.out)"),
3839
opt[Unit]("lazy-mark-scan-only").action((_, opts) =>
3940
opts.copy(settings = opts.settings.copy(rcAlgo = RcAlgo.LazyMarkScan))
40-
).text("Use base lazy mark scan algorithm instead of my cool one :(")
41+
).text("Use base lazy mark scan algorithm instead of my cool one :("),
42+
opt[Unit]("all-sccs-bad").action((_, opts) =>
43+
opts.copy(settings = opts.settings.copy(allSccsBad = true))
44+
).text(
45+
"Consider all SCCs to be bad, i.e., act like all fields are mutable and that any type SCC can have cycles at runtime"
46+
)
4147
)
4248
}
4349
OParser.parse(parser, args, Options()) match {

src/main/scala/fred/Translator.scala

+6-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ object Translator {
2929
// whole program, make this an empty set in that case
3030
Set(0)
3131
)
32-
case RcAlgo.Mine => Cycles.fromFile(file)
32+
case RcAlgo.Mine => {
33+
val cycles = Cycles.fromFile(file)
34+
if (settings.allSccsBad) cycles
35+
.copy(badSCCs = cycles.sccs.indices.toSet)
36+
else cycles
37+
}
3338
}
3439
val helper = Helper(typer, cycles)
3540
val (genDecls, genImpls) =

0 commit comments

Comments
 (0)