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

Changes needed for compiler plugin #474

Merged

Conversation

@neeme-praks-sympower
Copy link
Contributor Author

@oshai, can you have a look at these small changes? I want to merge this in before I move compiler plugin to a separate repository.

@oshai
Copy link
Owner

oshai commented Jan 30, 2025

Looking at it now.

The change in LogbackLoggerFactory seems ok, but if possible I would like to avoid the rest. Even on the expense of some duplication on the compiler plugin.

public extension functions can really clutter IDE autocomplete and confuses users. So I suggest to have them in a separate module, either only dependent at runtime, or bundle with the compiler plugin somehow.

@oshai
Copy link
Owner

oshai commented Jan 31, 2025

Another option: Mark methods as deprecated - I think there is an option they will only be visible to compiler.

@neeme-praks-sympower
Copy link
Contributor Author

neeme-praks-sympower commented Feb 3, 2025

The change in LogbackLoggerFactory seems ok, but if possible I would like to avoid the rest. Even on the expense of some duplication on the compiler plugin.

public extension functions can really clutter IDE autocomplete and confuses users. So I suggest to have them in a separate module, either only dependent at runtime, or bundle with the compiler plugin somehow.

These extension functions can be replaced with static non-extension functions. Would that be acceptable? While less elegant to read, at least they will not show up in IDE auto-complete.

I would like to avoid run-time dependency on the compiler plugin project.

@oshai
Copy link
Owner

oshai commented Feb 3, 2025

Non extension functions is also an option. iiuc it will only be seen in bytecode inspection, right?

@neeme-praks-sympower
Copy link
Contributor Author

Non extension functions is also an option. iiuc it will only be seen in bytecode inspection, right?

The functions themselves are visible on the classpath but IDE will not suggest them as they are not defined as (extension) functions on particular type.

@oshai
Copy link
Owner

oshai commented Feb 3, 2025

Non extension functions is also an option. iiuc it will only be seen in bytecode inspection, right?

The functions themselves are visible on the classpath but IDE will not suggest them as they are not defined as (extension) functions on particular type.

yes I understand that. If the package or class name is marked as internal I expect users to understand that they shouldn't use it or rely on it.

Again, it's also possible to use the "HIDDEN" deprecation level as well so users can use it: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-deprecation-level/#412239310%2FClasslikes%2F1895087430

Maybe we can do that (hidden) also to internalCompilerData field.

@neeme-praks-sympower
Copy link
Contributor Author

neeme-praks-sympower commented Feb 3, 2025

yes I understand that. If the package or class name is marked as internal I expect users to understand that they shouldn't use it or rely on it.

Again, it's also possible to use the "HIDDEN" deprecation level as well so users can use it: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-deprecation-level/#412239310%2FClasslikes%2F1895087430

Maybe we can do that (hidden) also to internalCompilerData field.

If we make internalCompilerData field hidden then we can no longer compile kotlin-logging itself -- we need read access to this field.

Here is a trick that works:

  • We can use the deprecation annotation to hide all the functions that are called only by the compiler plugin. Then they can stay as extension functions.
  • However, we cannot hide functions/members that we want to access ourselves from kotlin-logging code. But we can declare such functions/members as internal.

So, for internalCompilerData field, we can declare it as internal so it is accessible only from within kotlin-logging and then we can add a hidden extension function to KLoggingEventBuilder that we use to set the field from within the compiler plugin. This will give us the best of both worlds. Pretty neat.

I now applied this change, have a look.

@neeme-praks-sympower
Copy link
Contributor Author

neeme-praks-sympower commented Feb 3, 2025

I now hid also toStringSafe() and castToThrowable() extension functions, using the same mechanism. Ok, the latter was already hidden, I just moved it to the same file with all the other hidden functions (and renamed the file).

@oshai
Copy link
Owner

oshai commented Feb 3, 2025

lgtm. anything you would like to add before I merge it?

@neeme-praks-sympower
Copy link
Contributor Author

neeme-praks-sympower commented Feb 3, 2025

lgtm. anything you would like to add before I merge it?

Nope, should be complete from my side.

@oshai oshai merged commit 2b2dbc7 into oshai:master Feb 4, 2025
5 checks passed
@oshai
Copy link
Owner

oshai commented Feb 4, 2025

merged, thanks!

@neeme-praks-sympower neeme-praks-sympower deleted the changes-for-compiler-plugin branch February 4, 2025 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants