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

Add Bean instantiation generator infrastructure #28047

Closed
snicoll opened this issue Feb 14, 2022 · 0 comments
Closed

Add Bean instantiation generator infrastructure #28047

snicoll opened this issue Feb 14, 2022 · 0 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement
Milestone

Comments

@snicoll
Copy link
Member

snicoll commented Feb 14, 2022

As part of our AOT effort, we need an infrastructure that lets us generate the code to instantiate a bean.

This includes some low-level code generation infrastructure to write method calls, parameters, etc, as well as an API that can be used to contribute to the bean instance.

Such contributors should namely be based on the existing BeanPostProcessor infrastructure as they augment a bean instance with some logic that can be translated into code during the AOT phase. As BPP are ordered, so can their contributions so that the order in which they are applied by executing generated code matches.

To ease code generation, we need an infrastructure that focuses on something quite basic for a first version, something like:

BeanDefinitionRegistrar.of("restTemplateClientService", RestTemplateClientService.class)
	  .withConstructor(RestTemplateBuilder.class)
	  .instanceSupplier((instanceContext) -> instanceContext.create(beanFactory, (attributes) ->
			  new RestTemplateClientService(attributes.get(0))))
	  .register(beanFactory);

This registeres a restTemplateClientService bean that requires a RestTemplateBuilder. Rather than doing all the dependency resolution at build-time, we leverage framework's dependency resolution algorithm, via the instanceContext who can provide us resolved attributes according to Executable to use to instantiate the bean (here a constructor that takes a RestTemplateBuilder).

@snicoll snicoll added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement theme: aot An issue related to Ahead-of-time processing labels Feb 14, 2022
@snicoll snicoll added this to the 6.0.0-M3 milestone Feb 14, 2022
@snicoll snicoll self-assigned this Feb 14, 2022
@snicoll snicoll changed the title Add Bean instance generator infrastructure Add Bean instantiation generator infrastructure Mar 9, 2022
snicoll added a commit that referenced this issue Mar 9, 2022
snicoll added a commit that referenced this issue Mar 9, 2022
This commit polishes the contribution model where an AOT contributing
bean post processor can return a contribution, rather than a
contributor. This makes it easier to return `null` if no contribution
can be produced now that it is named this way.

See gh-28047
snicoll added a commit that referenced this issue Mar 9, 2022
This commit updates AotContributingBeanPostProcessor so that it
explicitly extends from PriorityOrdered. This makes it more apparent
that AOT contributing bean post processors are meant to be invoked
early with the regular runtime, and shouldn't be post-processed
themselves.

See gh-28047
snicoll added a commit that referenced this issue Mar 9, 2022
This commit harmonizes the use of the "generate" keyword for anything
related to code generation. Previously, there was a mix of "generate"
and "write."

See gh-28047
snicoll added a commit that referenced this issue Mar 9, 2022
This commit updates the generator to stop specifying a field type when
reflection is necessary, or when a reference to a field should be
retrieved as its name alone suffices.

This could trigger package protected issues if the field type is not
public.

See gh-28047
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant