Skip to content

DRAFT [Feat] Compiler Context to Support Compositions#126

Draft
briankane wants to merge 1 commit intokubevela:mainfrom
briankane:feature/compiler-context
Draft

DRAFT [Feat] Compiler Context to Support Compositions#126
briankane wants to merge 1 commit intokubevela:mainfrom
briankane:feature/compiler-context

Conversation

@briankane
Copy link
Contributor

@briankane briankane commented Nov 19, 2025

Related KubeVela changes: kubevela/kubevela#6989

Summary by cubic

Added a compiler context to share the Cue context and compiler across nested compilations. This enables compositions to reuse state and resolve provider functions reliably.

  • New Features

    • Added context helpers to set/get the compiler and cue.Context.
    • Compiler now uses a shared cue.Context when building instances and stores both in the request context.
  • Migration

    • Use github.com/kubevela/pkg/cue/cuex/interfaces and github.com/kubevela/pkg/cue/cuex/types.
    • CompileStringWithOptions now takes opts ...interfaces.CompileOption.
    • Custom CompileOption implementations must apply to *types.CompileConfig.

Written for commit 2792b6f. Summary will update automatically on new commits.

Signed-off-by: Brian Kane <briankane1@gmail.com>
Copy link
Collaborator

@jguionnet jguionnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ask the gokarna team for review

I included 3 comments that make sense to me from AI review. 1 below and 2 inline

Consider renaming package from context to compilercontext (or similar) to avoid confusion with stdlib.

func (in *Compiler) CompileStringWithOptions(ctx context.Context, src string, opts ...CompileOption) (cue.Value, error) {
func (in *Compiler) CompileStringWithOptions(ctx context.Context, src string, opts ...interfaces.CompileOption) (cue.Value, error) {
var err error
compilercontext.WithCompiler(ctx, in) // set context for nested compilations
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Store compiler in context for nested compilations; capture returned ctx.
ctx = compilercontext.WithCompiler(ctx, in)

cueCtx := compilercontext.GetCueContext(ctx)
if cueCtx == nil {
cueCtx = cuecontext.New()
compilercontext.WithCueContext(ctx, cueCtx) // set the cue context for nested compilations
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

	ctx = compilercontext.WithCueContext(ctx, cueCtx)

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