Skip to content

Commit 73695e3

Browse files
authored
Support -Xno-optimized-callable-references Kotlinc flag (#394)
1 parent ae658ea commit 73695e3

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

kotlin/internal/jvm/compile.bzl

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def _adjust_resources_path(path, resource_strip_prefix):
167167
return _adjust_resources_path_by_default_prefixes(path)
168168

169169
def _merge_kt_jvm_info(module_name, providers):
170-
language_versions = {p.language_version: True for p in providers if p.language_verison}
170+
language_versions = {p.language_version: True for p in providers if p.language_version}
171171
if len(language_versions) != 1:
172172
fail("Conflicting kt language versions: %s" % language_versions)
173173
return _KtJvmInfo(
@@ -179,9 +179,13 @@ def _merge_kt_jvm_info(module_name, providers):
179179
]),
180180
)
181181

182-
def _kotlinc_options_provider_to_flags(opts):
182+
def _kotlinc_options_provider_to_flags(opts, language_version):
183183
if not opts:
184184
return ""
185+
186+
# Validate the compiler opts before they are mapped over to flags
187+
_validate_kotlinc_options(opts, language_version)
188+
185189
flags = []
186190
if opts.warn == "off":
187191
flags.append("-nowarn")
@@ -207,11 +211,19 @@ def _kotlinc_options_provider_to_flags(opts):
207211
flags.append("-Xjvm-default=enable")
208212
elif opts.x_jvm_default == "compatibility":
209213
flags.append("-Xjvm-default=compatibility")
214+
if opts.x_no_optimized_callable_references:
215+
flags.append("-Xno-optimized-callable-references")
210216
return flags
211217

218+
def _validate_kotlinc_options(opts, language_version):
219+
if opts.x_allow_jvm_ir_dependencies and language_version < "1.4":
220+
fail("The x_allow_jvm_ir_dependencies flag is only avaliable in Kotlin version 1.4 or greater")
221+
pass
222+
212223
def _javac_options_provider_to_flags(opts):
213224
if not opts:
214225
return ""
226+
215227
flags = []
216228
if opts.warn == "off":
217229
flags.append("-nowarn")
@@ -359,8 +371,7 @@ def _run_kt_builder_action(
359371
# Unwrap kotlinc_options/javac_options options or default to the ones being provided by the toolchain
360372
kotlinc_options = ctx.attr.kotlinc_opts[_KotlincOptions] if ctx.attr.kotlinc_opts else toolchains.kt.kotlinc_options
361373
javac_options = ctx.attr.javac_opts[_JavacOptions] if ctx.attr.javac_opts else toolchains.kt.javac_options
362-
363-
args.add_all("--kotlin_passthrough_flags", _kotlinc_options_provider_to_flags(kotlinc_options))
374+
args.add_all("--kotlin_passthrough_flags", _kotlinc_options_provider_to_flags(kotlinc_options, toolchains.kt.language_version))
364375
args.add_all("--javacopts", _javac_options_provider_to_flags(javac_options))
365376

366377
# TODO: Implement Strict Kotlin deps: (https://github.com/bazelbuild/rules_kotlin/issues/419)

kotlin/internal/opts.bzl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ _KOPTS = {
7979
),
8080
type = attr.string,
8181
),
82+
"x_no_optimized_callable_references": struct(
83+
args = dict(
84+
default = False,
85+
doc = "Do not use optimized callable reference superclasses. Available from 1.4.",
86+
),
87+
type = attr.bool,
88+
),
8289
}
8390

8491
KotlincOptions = provider(

0 commit comments

Comments
 (0)