Skip to content

Commit

Permalink
optimization: ignore unused pure calls
Browse files Browse the repository at this point in the history
  • Loading branch information
SrGaabriel committed Sep 9, 2024
1 parent c658d40 commit 692f432
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ class SeleneDragonCompilingSession(
return intrinsics.onCall(context)
}
val pure = !signature.modifiers.contains(Modifiers.IMPURE)
val ignoreResult = statement || signature.returnType == SeleneType.Void
if (pure && ignoreResult) {
return NullMemory
}

val call =
if (signature.module != compilerModule.name) {
Expand All @@ -132,7 +136,7 @@ class SeleneDragonCompilingSession(
pure = pure
)
}
if (statement || signature.returnType == SeleneType.Void) {
if (ignoreResult) {
call.ignore()
return NullMemory
}
Expand Down
2 changes: 1 addition & 1 deletion bard/output/ll/signatures.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"functions":[{"module":"stdlib","name":"printf","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Void"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Any"}],"modifiers":["IMPURE","INTRINSIC"]},{"module":"stdlib","name":"println","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Void"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Any"}],"modifiers":["IMPURE","INTRINSIC"]},{"module":"stdlib","name":"readln","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.String"},"parameters":[],"modifiers":["IMPURE","INTRINSIC"]},{"module":"stdlib","name":"arraylen","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Any"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"sin","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"cos","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"tan","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"asin","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"acos","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"atan","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"atan2","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"socket","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"bind","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int8"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"listen","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"accept","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int8"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"receive","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int8"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"send","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int8"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"close","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"bard","name":"test","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[],"modifiers":[]},{"module":"bard","name":"main","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[],"modifiers":["IMPURE"]}]}
{"functions":[{"module":"stdlib","name":"arraylen","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Any"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"printf","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Void"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Any"}],"modifiers":["IMPURE","INTRINSIC"]},{"module":"stdlib","name":"println","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Void"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Any"}],"modifiers":["IMPURE","INTRINSIC"]},{"module":"stdlib","name":"readln","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.String"},"parameters":[],"modifiers":["IMPURE","INTRINSIC"]},{"module":"stdlib","name":"sin","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"cos","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"tan","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"asin","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"acos","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"atan","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"atan2","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"socket","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"bind","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int8"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"listen","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"accept","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int8"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"receive","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int8"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"send","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int8"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"close","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"bard","name":"test","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[],"modifiers":[]},{"module":"bard","name":"main","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[],"modifiers":["IMPURE"]}]}
Binary file modified bard/output/output.exe
Binary file not shown.
8 changes: 0 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.gradle.kotlin.dsl.support.kotlinCompilerOptions

plugins {
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.kotlinx.serialization) apply false
Expand All @@ -18,10 +16,4 @@ dependencies {

allprojects {
apply(plugin = "org.jetbrains.kotlin.plugin.serialization")

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class.java).configureEach {
compilerOptions {
freeCompilerArgs.add("-Xcontext-receivers")
}
}
}
4 changes: 3 additions & 1 deletion stdlib/src/collections.sn
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@
// self.array[self.size] = value;
// self.size = self.size + 1;
// }
//}
//}

intrinsic func arraylen (arr: any) :: int32 {}
4 changes: 1 addition & 3 deletions stdlib/src/io.sn
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ impure intrinsic func printf (message: any) {}

impure intrinsic func println (message: any) {}

impure intrinsic func readln () :: string {}

intrinsic func arraylen (arr: any) :: int32 {}
impure intrinsic func readln () :: string {}

0 comments on commit 692f432

Please sign in to comment.