Skip to content

Remove unnecessary reification from Kotlin R2DBC extensions #1496

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

Closed
wants to merge 1 commit into from

Conversation

astiob
Copy link
Contributor

@astiob astiob commented Apr 15, 2023

This allows calling the extensions from generic code that has erased types, for example:

class CustomRepository<T>(val type: Class<T>) {
    @Autowired
    lateinit var db: R2dbcEntityTemplate

    // Fails to compile currently because usingAndAwait requires a reified T
    suspend fun create(obj: T) = db.insert(type).usingAndAwait(obj)
}

I’m not sure what to do about tests. I could add new tests with erased types, but they would necessarily duplicate the existing tests that have reified types—and especially in ReactiveSelectOperationExtensionsUnitTests, that’s quite a lot of code; and the new tests would be verifying the same runtime behaviour as the old tests (as this change only affects compilability), so they’d become redundant. Alternatively, the existing tests could be tweaked to ensure the types are erased; or the ability to use erased types could go completely untested.

I’m also not sure whether this is an ABI-compatible change. If not, I assume it will have to wait until a major-enough release where ABI breaks are allowed.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 15, 2023
@astiob
Copy link
Contributor Author

astiob commented Apr 15, 2023

Er, to clarify about ABI: the reified versions are inline, so any code compiled against the old version is inevitably compatible with the new version, too. But I’m guessing that code compiled against the new version will be incompatible with older Spring binaries at runtime because it will try to call methods that don’t exist, so this likely has to wait until a release like 3.1.

Alternatively, the non-reified versions could continue to be marked inline, which would avoid all ABI issues entirely; but as far as I see, Spring’s existing non-reified Kotlin coroutine extensions appear to be never marked inline.

@schauder schauder added in: kotlin Kotlin support in: r2dbc Spring Data R2DBC labels Apr 17, 2023
@mp911de mp911de added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 24, 2023
schauder added a commit that referenced this pull request Apr 25, 2023
This allows calling the extensions from generic code that has erased types.

Original pull request #1496
schauder pushed a commit that referenced this pull request Apr 25, 2023
This allows calling the extensions from generic code that has erased types.

Original pull request #1496
schauder added a commit that referenced this pull request Apr 25, 2023
This allows calling the extensions from generic code that has erased types.

Original pull request #1496
schauder pushed a commit that referenced this pull request Apr 25, 2023
This allows calling the extensions from generic code that has erased types.

Original pull request #1496
schauder pushed a commit that referenced this pull request Apr 25, 2023
This allows calling the extensions from generic code that has erased types.

Original pull request #1496
@schauder
Copy link
Contributor

schauder commented Apr 25, 2023

Thanks, that's merged and ported back to 3.0

@schauder schauder closed this Apr 25, 2023
@schauder schauder added this to the 3.0.6 (2022.0.6) milestone Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: kotlin Kotlin support in: r2dbc Spring Data R2DBC type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants