compiler

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2026 License: MPL-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SeverityError is the default: it fails the build.
	SeverityError = diagnostics.SeverityError
	// SeverityWarning is surfaced to the author but does not fail the build.
	SeverityWarning = diagnostics.SeverityWarning
)

Variables

This section is empty.

Functions

func AssembleProgram added in v0.5.0

func AssembleProgram(config gowdk.Config, sources gwdkanalysis.Sources) (gwdkir.Program, []source.BackendBinding, error)

AssembleProgram builds the canonical compiler IR from parsed sources and runs EnrichProgram on it, returning the enriched program together with its backend bindings. It is the single entrypoint for callers that start from sources rather than an already-assembled program, so they cannot accidentally build on a base program that skipped discovery and binding.

func BackendBindingsFromIR added in v0.2.8

func BackendBindingsFromIR(ir gwdkir.Program) []source.BackendBinding

BackendBindingsFromIR derives the backend binding records already attached to the program's endpoints, without inspecting Go packages on disk. Callers that only need binding metadata for reporting (e.g. build reports) should use this instead of re-running handler discovery.

func BindBackendHandlers added in v0.1.5

func BindBackendHandlers(ir *gwdkir.Program) []source.BackendBinding

BindBackendHandlers discovers same-package Go handlers for act and api blocks, attaches the resulting binding metadata to the program's endpoints and page load bindings, and returns the full binding record list (sorted by source, kind, and block name) for reporting and public manifest JSON. Discovery is intentionally non-fatal: missing packages, missing functions, and unsupported signatures are reported as binding metadata so generated apps can emit clear 501 responses.

func DiscoverGoEndpoints added in v0.2.8

func DiscoverGoEndpoints(config gowdk.Config, ir *gwdkir.Program) error

DiscoverGoEndpoints merges optional //gowdk:act and //gowdk:api comments from selected feature-package Go files into the program as standalone Go endpoints.

func EnrichProgram added in v0.5.0

func EnrichProgram(config gowdk.Config, program *gwdkir.Program) ([]source.BackendBinding, error)

EnrichProgram runs the IR enrichment phases that every codegen orchestrator needs, in the one order they must run: discover standalone Go endpoints, then bind backend handlers. It mutates program in place and returns the backend bindings.

This is the single definition of the discover -> bind phase order. Codegen orchestrators must not re-sequence these phases by hand; doing so is how the source-taking buildgen entrypoints previously produced under-enriched IR (no discovered Go endpoints, empty bindings) by skipping these steps entirely.

Contract linking and validation are deliberately left to the caller: they require a project root and a contract-scan report, and each orchestrator has a different error-handling contract (the CLI fails hard; the LSP/check path collects diagnostics).

func ValidateBackendBindingPolicyIR added in v0.2.8

func ValidateBackendBindingPolicyIR(config gowdk.Config, ir gwdkir.Program) error

ValidateBackendBindingPolicyIR enforces build-mode rules for declared backend endpoints after same-package Go handler binding metadata has been produced. When the program carries no binding metadata but declares backend endpoints (callers that build straight from an unbound program), handlers are re-discovered from disk before the policy check.

func ValidateContractReferences added in v0.1.5

func ValidateContractReferences(refs []gwdkir.ContractReference) error

ValidateContractReferences converts linked contract-reference metadata into compiler diagnostics for CLI validation paths.

func ValidateProgram added in v0.2.8

func ValidateProgram(config gowdk.Config, ir gwdkir.Program) error

ValidateProgram checks render-mode invariants that must hold before codegen. The validators read the compiler IR directly; there is no manifest intermediary on this path. It returns a non-nil error only when at least one error-severity diagnostic is present; warning-only programs return nil.

func ValidateQueryInvalidations added in v0.5.0

func ValidateQueryInvalidations(config gowdk.Config, invalidations []gwdkir.QueryInvalidation) error

ValidateQueryInvalidations converts linked query-invalidation metadata into compiler diagnostics for CLI validation paths.

func ValidateRealtimeSubscriptionBindings added in v0.5.0

func ValidateRealtimeSubscriptionBindings(subscriptions []gwdkir.RealtimeSubscription) error

ValidateRealtimeSubscriptionBindings converts linked realtime subscription metadata into compiler diagnostics for CLI validation paths.

func ValidateSourceProgram added in v0.2.8

func ValidateSourceProgram(config gowdk.Config, ir gwdkir.Program) error

ValidateSourceProgram checks a program built from a single in-memory source buffer. Cross-file checks (use packages and component references resolved against the discovered project) are skipped because sibling files are not present in the program.

Types

type ContractEndpointBinding added in v0.1.5

type ContractEndpointBinding struct {
	Name        string
	Kind        gwdkir.ContractKind
	Status      gwdkir.ContractBindingStatus
	Message     string
	ImportAlias string
	ImportPath  string
	Type        string
	Result      string
	Roles       []string
	Handler     string
	Register    string
}

ContractEndpointBinding describes a command/query contract exposed through a generated backend endpoint.

type EndpointBinding added in v0.1.5

type EndpointBinding struct {
	Kind              EndpointKind
	EndpointSource    string
	Source            string
	SourceSpan        source.SourceSpan
	Package           string
	PackagePath       string
	PackageName       string
	Symbol            string
	Method            string
	Route             string
	Cache             string
	DynamicParams     []string
	RouteParams       []source.RouteParam
	Guards            []string
	CSRF              bool
	PageID            string
	Handler           string
	BindingStatus     source.BackendBindingStatus
	BindingMessage    string
	BindingImportPath string
	BindingPackage    string
	BindingFunction   string
	BindingSignature  source.BackendSignatureKind
	BindingInputType  string
	Contract          ContractEndpointBinding
}

EndpointBinding is backend action/API metadata. Endpoints are not route kinds; they hang off the generated app/runtime backend layer.

type EndpointKind added in v0.1.5

type EndpointKind string

EndpointKind describes backend endpoint behavior separate from page/file routes.

const (
	EndpointAction   EndpointKind = "action"
	EndpointAPI      EndpointKind = "api"
	EndpointFragment EndpointKind = "fragment"
	EndpointCommand  EndpointKind = "command"
	EndpointQuery    EndpointKind = "query"
)

type RouteBinding added in v0.1.5

type RouteBinding struct {
	Kind          RouteKind
	Method        string
	Route         string
	PageID        string
	Package       string
	Render        gowdk.RenderMode
	Cache         string
	DynamicParams []string
	RouteParams   []source.RouteParam
	Layouts       []string
	Guards        []string
	Source        string
	SourceSpan    source.SourceSpan
	Handler       string
}

RouteBinding is route-level metadata. Route kinds are intentionally limited to static files, SPA routes, SSR routes, and hybrid routes.

type RouteInfo added in v0.1.5

type RouteInfo struct {
	Code    string
	PageID  string
	Route   string
	Message string
}

RouteInfo is non-fatal route metadata surfaced by CLI inspection commands.

type RouteKind added in v0.1.5

type RouteKind string

RouteKind describes route behavior in the CLI routes report.

const (
	RouteStatic RouteKind = "static"
	RouteSPA    RouteKind = "spa"
	RouteSSR    RouteKind = "ssr"
	RouteHybrid RouteKind = "hybrid"
)

type RouteMetadata added in v0.1.5

type RouteMetadata struct {
	Routes    []RouteBinding
	Endpoints []EndpointBinding
	Info      []RouteInfo
}

RouteMetadata is route and endpoint metadata used by the CLI routes report.

func BuildRouteMetadataFromIR added in v0.1.5

func BuildRouteMetadataFromIR(config gowdk.Config, ir gwdkir.Program) RouteMetadata

BuildRouteMetadataFromIR converts stable compiler IR into CLI route and endpoint metadata.

type Severity added in v0.3.0

type Severity = diagnostics.Severity

Severity classifies a diagnostic as a hard error or a non-fatal warning.

type ValidationError

type ValidationError struct {
	Code          string
	PageID        string
	ComponentName string
	Source        string
	Span          source.SourceSpan
	// Related carries secondary source locations, such as the first declaration
	// that a conflict diagnostic also points at. It is optional and additive.
	Related  []source.RelatedSpan
	Message  string
	Severity Severity
}

func BackendBindingDiagnostics added in v0.5.0

func BackendBindingDiagnostics(bindings []source.BackendBinding) []ValidationError

BackendBindingDiagnostics returns non-fatal diagnostics that explain why a declared backend handler did not bind to a Go function, so the reason is visible during gowdk check and build instead of only in inspect go-bindings or a strict production build.

It intentionally warns only when there is positive evidence of a problem the author almost certainly cares about:

  • ambiguous_backend_handler: the same handler is declared in both same-package Go and an inline go {} block, so the chosen source is ambiguous.
  • unsupported_backend_signature: a same-named Go function exists but has a signature GOWDK does not support.
  • unexported_backend_handler: a same-named Go function exists but is not exported, so binding cannot see it.

A plainly missing handler (no candidate function at all) is left silent because the default workflow generates 501 stubs for not-yet-implemented handlers, and strict production builds already fail via backend_binding_required.

func ValidatePage

func ValidatePage(config gowdk.Config, page gwdkir.Page) []ValidationError

func (ValidationError) Error

func (err ValidationError) Error() string

type ValidationErrors

type ValidationErrors []ValidationError

func ValidateProgramReport added in v0.3.0

func ValidateProgramReport(config gowdk.Config, ir gwdkir.Program) ValidationErrors

ValidateProgramReport returns every diagnostic, including warnings, so the caller can surface warnings while still gating the build on HasErrors.

func ValidateSourceProgramReport added in v0.3.0

func ValidateSourceProgramReport(config gowdk.Config, ir gwdkir.Program) ValidationErrors

ValidateSourceProgramReport is the single-source counterpart to ValidateProgramReport.

func (ValidationErrors) Error

func (errs ValidationErrors) Error() string

func (ValidationErrors) HasErrors added in v0.3.0

func (errs ValidationErrors) HasErrors() bool

HasErrors reports whether any diagnostic is error severity. Warning-only reports return false so the build proceeds.

func (ValidationErrors) Warnings added in v0.3.0

func (errs ValidationErrors) Warnings() ValidationErrors

Warnings returns only the warning-severity diagnostics.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL